2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
25 // Internal headers are allowed here
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/update/resources/bitmap-metadata.h>
29 #include <dali/internal/update/resources/resource-manager.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/event/resources/resource-client.h>
32 #include <dali/internal/event/resources/resource-ticket.h>
33 #include <dali/internal/event/resources/image-ticket.h>
34 #include <dali/internal/event/resources/resource-ticket-observer.h>
35 #include <dali/internal/event/images/resource-image-impl.h>
36 #include <dali/integration-api/resource-cache.h>
37 #include <dali/internal/render/gl-resources/texture-declarations.h>
38 #include <dali/internal/render/shaders/shader.h>
39 #include <dali/internal/common/owner-pointer.h>
40 #include <dali/public-api/shader-effects/shader-effect.h>
44 #include <mesh-builder.h>
49 class TestTicketObserver : public Internal::ResourceTicketObserver
53 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
54 mSavingFailedCalled(0), mSavingSucceededCalled(0),
58 int LoadFailedCalled() {
59 tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
60 return mLoadingFailedCalled;
62 int LoadSucceededCalled() {
63 tet_printf("TicketObserver: LoadingSucceeded() called %d times", mLoadingSucceededCalled);
64 return mLoadingSucceededCalled;
66 int SaveFailedCalled() {
67 tet_printf("TicketObserver: SavingFailed() called %d times", mSavingFailedCalled);
68 return mSavingFailedCalled;
70 int SaveSucceededCalled() {
71 tet_printf("TicketObserver: SavingSucceeded() called %d times", mSavingSucceededCalled);
72 return mSavingSucceededCalled;
75 tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
76 return mUploadedCount;
79 mLoadingFailedCalled = 0;
80 mLoadingSucceededCalled = 0;
81 mSavingFailedCalled = 0;
82 mSavingSucceededCalled = 0;
86 public: // From ResourceTicketObserver
87 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
88 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
89 virtual void ResourceSavingFailed(const Internal::ResourceTicket& ticket) {mSavingFailedCalled++;}
90 virtual void ResourceSavingSucceeded(const Internal::ResourceTicket& ticket) {mSavingSucceededCalled++;}
91 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
94 int mLoadingFailedCalled;
95 int mLoadingSucceededCalled;
96 int mSavingFailedCalled;
97 int mSavingSucceededCalled;
101 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
104 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
106 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
107 { resourceTicketDiscarded = true; }
109 void Reset() { resourceTicketDiscarded = false; }
110 bool resourceTicketDiscarded;
113 static TestTicketObserver testTicketObserver;
114 static TestTicketLifetimeObserver testTicketLifetimeObserver;
117 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
119 Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES );
120 application.SendNotification(); // Flush update messages
121 application.Render(); // Process resource request
122 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
123 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
124 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
125 Integration::ResourcePointer resourcePtr(bitmap); // reference it
126 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
127 application.Render(); // Process LoadComplete
128 application.SendNotification(); // Process event messages
129 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
131 application.GetPlatform().ResetTrace();
136 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
138 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
139 ImageAttributes attr;
140 Integration::BitmapResourceType bitmapRequest(attr);
141 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
142 ticket->AddObserver(testTicketObserver);
143 application.SendNotification(); // Flush update messages
144 application.Render(); // Process resource request
145 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
146 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
147 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
148 Integration::ResourcePointer resourcePtr(bitmap); // reference it
149 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
150 application.Render(); // Process LoadComplete
151 application.SendNotification(); // Process event messages
152 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
153 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
155 application.GetPlatform().ResetTrace();
160 } //anonymous namespace
163 void utc_dali_internal_resource_client_startup()
165 test_return_value = TET_UNDEF;
168 void utc_dali_internal_resource_client_cleanup()
170 test_return_value = TET_PASS;
173 // Load a bitmap resource successfully, then discard it's ticket
174 int UtcDaliInternalRequestResourceBitmapRequests01(void)
176 TestApplication application; // Reset all test adapter return codes
178 tet_infoline("Testing bitmap requests");
180 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
181 ImageAttributes attr;
182 Integration::BitmapResourceType bitmapRequest (attr);
183 Internal::ResourceId id(0);
185 testTicketObserver.Reset();
188 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
189 /************************************************************
190 * FUNCTION UNDER TEST
191 ***********************************************************/
192 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
193 ticket->AddObserver(testTicketObserver);
195 // Update thread will request the bitmap resource:
196 // Sets application.GetPlatform().mRequest
197 application.SendNotification(); // Run flush update queue
198 application.Render(1); // Process update messages
199 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
201 application.SendNotification(); // Send any event messages
202 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
203 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
204 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
206 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
207 DALI_TEST_CHECK( imageTicket );
208 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
209 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
212 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
213 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
214 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
215 Integration::ResourcePointer resourcePtr(bitmap); // reference it
217 // Set up platform abstraction to load it
219 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
221 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
223 // load the cache, which will immediately have the loaded resource
224 application.Render(0);
226 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
228 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
229 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
230 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
231 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
233 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
234 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
236 // Trigger the event thread to process notify messages. Should then trigger the signals
237 // in the ticket observer
238 application.SendNotification();
240 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
241 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
243 // Check that the image ticket was updated with the image attributes
244 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
245 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
248 application.SendNotification(); // Flush update queue (with ticket discarded message
249 application.Render(1); // Process update messages
250 application.SendNotification(); // Send event notifications
251 application.Render(1); // Process update messages
253 // Resource should have been discarded.
254 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
255 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
257 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
258 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
262 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
263 int UtcDaliInternalRequestResourceBitmapRequests02(void)
265 TestApplication application; // Reset all test adapter return codes
267 tet_infoline("Testing bitmap request ticket discard before load complete");
269 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
270 ImageAttributes attr;
271 Integration::BitmapResourceType bitmapRequest (attr);
272 Internal::ResourceId id(0);
274 testTicketObserver.Reset();
277 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
278 /************************************************************
279 * FUNCTION UNDER TEST
280 ***********************************************************/
281 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
282 ticket->AddObserver(testTicketObserver);
283 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
284 DALI_TEST_CHECK( imageTicket );
285 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
286 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
288 // Update thread will request the bitmap resource:
289 // Sets application.GetPlatform().mRequest
290 application.SendNotification(); // Run flush update queue
291 application.Render(1);
292 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
293 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
296 application.SendNotification(); // Should produce no messages
297 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
298 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
300 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
302 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
303 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
304 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
308 // Ensure ticket discarded message is sent to update thread
309 application.SendNotification(); // Flush update queue
310 application.Render(0); // Process update messages
312 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
313 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
315 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
317 // Trigger the event thread to process notify messages. Should then trigger the signals
318 // in the ticket observer
319 application.SendNotification();
321 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
322 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
326 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
327 int UtcDaliInternalRequestResourceBitmapRequests03(void)
329 TestApplication application; // Reset all test adapter return codes
331 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
333 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
334 ImageAttributes attr;
335 Integration::BitmapResourceType bitmapRequest (attr);
336 Internal::ResourceId id(0);
338 testTicketObserver.Reset();
339 { // Scope lifetime of ticket
340 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
342 /************************************************************
343 * FUNCTION UNDER TEST
344 ***********************************************************/
345 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
346 ticket->AddObserver(testTicketObserver);
347 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
348 DALI_TEST_CHECK( imageTicket );
349 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
350 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
352 // Update thread will request the bitmap resource:
353 // Sets application.GetPlatform().mRequest
354 application.SendNotification(); // Run flush update queue
355 application.Render(1); // process update messages
356 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
357 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
359 application.SendNotification(); // Should produce no messages
360 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
361 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
363 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
365 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
367 application.Render(0); // Get failed result
368 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
369 application.SendNotification(); // send failed
370 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
371 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
373 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
374 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
375 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
377 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
380 application.Render(0); // Send DiscardTicket
381 application.SendNotification();
383 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
389 // Load a bitmap resource successfully, then reload it
390 int UtcDaliInternalRequestReloadBitmapRequests01(void)
392 TestApplication application; // Reset all test adapter return codes
394 tet_infoline("Testing bitmap reload after successful load");
396 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
397 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
399 Internal::ResourceId id(0);
400 testTicketObserver.Reset();
403 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
404 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
405 id = ticket->GetId();
407 // Reset call statistics - test that resource is reloaded
408 application.GetPlatform().ResetTrace();
410 /************************************************************
411 * FUNCTION UNDER TEST
412 ***********************************************************/
413 resourceClient.ReloadResource( ticket->GetId() );
415 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
416 application.SendNotification(); // Flush update messages
417 application.Render(0); // Process update messages
418 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
419 application.SendNotification(); // Process event messages
421 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
422 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
423 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
424 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
426 // Create a new resource - the image size could have changed in the meantime
427 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
428 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
429 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
430 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
431 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
432 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
434 application.Render(0); // Process update messages / UpdateCache
435 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
437 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
438 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
439 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
440 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
442 // Ticket can't have been updated yet - it should still have old values
443 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
444 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
446 application.SendNotification(); // Process event messages
447 application.Render(0); // Process update messages / UpdateCache
448 application.SendNotification(); // Process event messages
450 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
451 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
452 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
453 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
454 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
458 application.SendNotification(); // Flush update queue (with ticket discarded message
459 application.Render(1); // Process update messages
460 application.SendNotification(); // Send event notifications
461 application.Render(1); // Process update messages
463 // Resource should have been discarded.
464 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
465 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
467 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
468 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
469 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
474 int UtcDaliInternalRequestReloadBitmapRequests02(void)
476 TestApplication application; // Reset all test adapter return codes
478 tet_infoline("Testing bitmap reload during first load");
480 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
481 ImageAttributes attr;
482 Integration::BitmapResourceType bitmapRequest (attr);
483 Internal::ResourceId id(0);
485 testTicketObserver.Reset();
488 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
489 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
490 ticket->AddObserver(testTicketObserver);
492 // Update thread will request the bitmap resource:
493 // Sets application.GetPlatform().mRequest
494 application.SendNotification(); // Run flush update queue
495 application.Render(1); // Process update messages
496 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
498 application.SendNotification(); // Send any event messages
499 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
500 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
502 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
503 DALI_TEST_CHECK( imageTicket );
504 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
505 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
508 /************************************************************
509 * FUNCTION UNDER TEST
510 ***********************************************************/
511 resourceClient.ReloadResource( ticket->GetId() );
512 /************************************************************
513 * Expected result - current load completes as usual, no reload requested
514 ************************************************************/
516 application.SendNotification(); // Flush update methods
518 // Reset call statistics - test that resource is not reloaded
519 application.GetPlatform().ResetTrace();
521 application.Render(0); // Process reload message (nothing for UpdateCache yet)
523 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
524 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
526 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
527 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
528 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
529 Integration::ResourcePointer resourcePtr(bitmap); // reference it
531 // Set up platform abstraction to load it
534 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
536 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
538 application.GetPlatform().ResetTrace();
539 // load the cache, which will immediately have the loaded resource
540 application.Render(0);
541 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
542 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
543 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
544 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
545 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
547 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
548 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
550 // Trigger the event thread to process notify messages. Should then trigger the signals
551 // in the ticket observer
552 application.SendNotification();
554 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
555 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
556 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
558 // Check that the image ticket was updated with the image attributes
559 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
560 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
562 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
564 application.SendNotification(); // Flush update messages
565 application.Render(0); // Process update messages
567 // There should be no reload
568 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
569 application.SendNotification(); // Process event messages
571 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
572 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
573 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
574 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
576 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
577 bitmapData = resourceManager.GetBitmapMetadata(id);
578 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
579 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
580 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
581 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
588 int UtcDaliInternalRequestReloadBitmapRequests03(void)
590 TestApplication application; // Reset all test adapter return codes
592 tet_infoline("Testing bitmap reload at end of first load");
594 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
595 ImageAttributes attr;
596 Integration::BitmapResourceType bitmapRequest (attr);
597 Internal::ResourceId id(0);
599 testTicketObserver.Reset();
602 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
603 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
604 ticket->AddObserver(testTicketObserver);
606 // Update thread will request the bitmap resource:
607 // Sets application.GetPlatform().mRequest
608 application.SendNotification(); // Run flush update queue
609 application.Render(1); // Process update messages
610 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
612 application.SendNotification(); // Send any event messages
613 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
614 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
616 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
617 DALI_TEST_CHECK( imageTicket );
618 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
619 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
622 /************************************************************
623 * FUNCTION UNDER TEST
624 ***********************************************************/
625 resourceClient.ReloadResource( ticket->GetId() );
626 /************************************************************
627 * Expected result - current load completes as usual, no reload requested
628 ************************************************************/
630 application.SendNotification(); // Flush update methods
632 // Reset call statistics - test that resource is not reloaded
633 application.GetPlatform().ResetTrace();
636 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
637 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
638 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
639 Integration::ResourcePointer resourcePtr(bitmap); // reference it
641 // Set up platform abstraction to load it
644 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
646 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
648 application.GetPlatform().ResetTrace();
649 // load the cache, which will immediately have the loaded resource
650 application.Render(0);
652 // UpdateCache runs before ProcessMessages, so the loading resource completes before
653 // the reload request is handled.
654 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
655 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
657 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
658 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
659 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
660 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
662 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
663 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
665 // Trigger the event thread to process notify messages. Should then trigger the signals
666 // in the ticket observer
667 application.SendNotification();
669 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
670 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
671 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
673 // Check that the image ticket was updated with the image attributes
674 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
675 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
677 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
679 // Create a new resource - the image size could have changed in the meantime
680 req = application.GetPlatform().GetRequest();
681 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
682 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
683 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
684 DALI_TEST_CHECK( req->GetId() == id );
685 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
687 application.Render(0); // Process update messages / UpdateCache
689 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
690 bitmapData = resourceManager.GetBitmapMetadata(id);
691 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
692 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
693 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
694 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
696 application.SendNotification(); // Process event messages
698 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
700 // Not staged - no GL upload
701 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
703 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
704 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
705 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
706 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
712 //int UtcDaliInternalSaveResource01(void)//
714 TestApplication application;
715 tet_infoline("Testing SaveResource() with valid id, and valid filename");
716 testTicketObserver.Reset();
723 //int UtcDaliInternalSaveResource02(void)//
725 TestApplication application;
726 tet_infoline("Testing SaveResource() with invalid id");
727 testTicketObserver.Reset();
733 //int UtcDaliInternalSaveResource03(void)//
735 TestApplication application;
736 tet_infoline("Testing SaveResource() with invalid id");
737 testTicketObserver.Reset();
739 DALI_TEST_CHECK ( 0 );
744 //int UtcDaliInternalSaveResource04(void)//
746 TestApplication application;
747 tet_infoline("Testing SaveResource() with valid id, but invalid filename");
748 testTicketObserver.Reset();
749 DALI_TEST_CHECK( 0 );
754 int UtcDaliInternalSaveResource05(void)
756 TestApplication application;
757 tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
758 testTicketObserver.Reset();
760 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
762 // First, load a bitmap resource
763 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
766 resourceClient.SaveResource( ticket, "bitmap.png" );
767 application.SendNotification(); // Flush update messages
768 application.Render(); // Process save resource request
770 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
774 int UtcDaliInternalRequestResourceTicket01(void)
776 TestApplication application;
777 tet_infoline("Testing RequestResourceTicket() with valid id");
779 testTicketObserver.Reset();
781 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
783 // First, load a bitmap resource
784 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
786 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
787 DALI_TEST_CHECK( newTicket );
788 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
789 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
793 int UtcDaliInternalRequestResourceTicket02(void)
795 TestApplication application;
796 tet_infoline("Testing RequestResourceTicket() with invalid id");
798 testTicketObserver.Reset();
800 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
802 // First, load a bitmap resource
803 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
805 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
806 DALI_TEST_CHECK( ! newTicket );
810 int UtcDaliInternalLoadShaderRequest01(void)
812 TestApplication application;
813 tet_infoline("Testing LoadShader() success");
814 testTicketObserver.Reset();
816 // Clear through all of the outstanding shader load requests from the default shader effect
817 std::vector< unsigned char > buffer;
818 for( int i=0; i<10; i++ )
820 buffer.push_back((unsigned char)i);
822 application.GetPlatform().SetLoadFileResult( true, buffer );
823 application.GetGlAbstraction().SetLinkStatus(1);
824 application.SendNotification(); // Flush update messages
825 application.Render(); // Process load shader request (immediately)
826 application.SendNotification();
827 application.Render();
828 application.SendNotification();
829 application.Render();
830 application.SendNotification();
832 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
834 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
835 std::string shaderBinaryFile("shader.bin");
836 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
837 DALI_TEST_CHECK( ticket );
839 application.GetPlatform().SetLoadFileResult( true, buffer );
840 application.GetGlAbstraction().EnableShaderCallTrace( true );
841 application.GetGlAbstraction().SetLinkStatus(1);
843 application.SendNotification(); // Flush update messages
844 application.Render(); // Process load shader request (immediately)
846 application.SendNotification();
847 application.Render();
849 application.SendNotification();
850 application.Render();
852 // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
853 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
854 DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
856 // Ensure no request sent to platform abstraction
857 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
861 int UtcDaliInternalAllocateBitmapImage01(void)
863 TestApplication application;
864 tet_infoline("Testing AllocateBitmapImage()");
865 testTicketObserver.Reset();
867 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
868 Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
869 imageTicket->AddObserver( testTicketObserver );
871 DALI_TEST_CHECK( imageTicket );
872 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
873 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
874 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
876 application.SendNotification(); // Flush update queue
877 application.Render(0); // Process message
878 application.SendNotification(); // Send message to tickets
880 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
881 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
882 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
883 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
885 Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
886 DALI_TEST_CHECK ( bitmap != NULL );
887 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
888 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
889 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
890 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
891 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
895 int UtcDaliInternalAddBitmapImage01(void)
897 TestApplication application;
898 tet_infoline("Testing AddBitmap with reserved buffer()");
899 testTicketObserver.Reset();
900 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
901 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
902 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
904 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
905 DALI_TEST_CHECK( imageTicket );
906 imageTicket->AddObserver( testTicketObserver );
908 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
909 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
910 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
912 application.SendNotification(); // Flush update queue
913 application.Render(0); // Process message
914 application.SendNotification(); // Send message to tickets
916 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
917 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
918 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
919 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
921 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
922 DALI_TEST_CHECK ( theBitmap != NULL );
923 DALI_TEST_CHECK ( bitmap == theBitmap );
924 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
925 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
926 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
927 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
928 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
932 int UtcDaliInternalAddBitmapImage02(void)
934 TestApplication application;
935 tet_infoline("Testing AddBitmap without reserved buffer()");
936 testTicketObserver.Reset();
937 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
938 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
940 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
941 DALI_TEST_CHECK( imageTicket );
942 imageTicket->AddObserver( testTicketObserver );
944 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
945 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
946 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
947 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
949 application.SendNotification(); // Flush update queue
950 application.Render(0); // Process message
951 application.SendNotification(); // Send message to tickets
953 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
954 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
955 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
956 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
958 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
959 DALI_TEST_CHECK ( theBitmap != NULL );
960 DALI_TEST_CHECK ( bitmap == theBitmap );
961 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
962 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
963 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
964 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
965 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
967 // There is no way for the ticket's image attributes to be updated if the bitmap
968 // reserves a buffer after ticket generation.
969 // Probably not an issue - there is no public API in BufferImage to change the image size.
974 int UtcDaliInternalAddBitmapImage03(void)
976 TestApplication application;
977 tet_infoline("Testing AddBitmap() with invalid bitmap");
978 testTicketObserver.Reset();
980 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
981 Internal::ImageTicketPtr imageTicket;
982 bool exceptionRaised=false;
985 imageTicket = resourceClient.AddBitmapImage( NULL );
987 catch( DaliException& e )
989 exceptionRaised = true;
991 DALI_TEST_CHECK( exceptionRaised );
992 DALI_TEST_CHECK( ! imageTicket );
996 int UtcDaliInternalGetBitmapImage01(void)
998 TestApplication application;
999 tet_infoline("Testing GetBitmap() with valid ticket");
1000 testTicketObserver.Reset();
1002 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1003 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1004 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1005 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1007 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1008 DALI_TEST_CHECK ( theBitmap != NULL );
1009 DALI_TEST_CHECK ( bitmap == theBitmap );
1010 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1011 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1012 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1013 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1014 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1016 imageTicket->AddObserver( testTicketObserver );
1017 application.SendNotification(); // Flush update queue
1018 application.Render(0); // Process message
1019 application.SendNotification(); // Send message to tickets
1021 theBitmap = resourceClient.GetBitmap(imageTicket);
1022 DALI_TEST_CHECK ( theBitmap != NULL );
1023 DALI_TEST_CHECK ( bitmap == theBitmap );
1024 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1025 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1026 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1027 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1028 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1032 int UtcDaliInternalGetBitmapImage02(void)
1034 TestApplication application;
1035 tet_infoline("Testing GetBitmap() with invalid ticket");
1037 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1038 Internal::ImageTicketPtr imageTicket;
1039 Integration::Bitmap* theBitmap = NULL;
1040 bool exceptionRaised = false;
1043 theBitmap = resourceClient.GetBitmap(imageTicket);
1044 } catch (DaliException& e)
1046 exceptionRaised = true;
1048 DALI_TEST_CHECK( exceptionRaised );
1049 DALI_TEST_CHECK( ! theBitmap );
1053 int UtcDaliInternalGetBitmapImage03(void)
1055 TestApplication application;
1056 tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1058 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1060 Integration::Bitmap* theBitmap = NULL;
1061 theBitmap = resourceClient.GetBitmap(imageTicket);
1062 DALI_TEST_CHECK( ! theBitmap );
1067 int UtcDaliInternalAllocateTexture01(void)
1069 TestApplication application;
1070 tet_infoline("Testing AllocateTexture()");
1071 testTicketObserver.Reset();
1073 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1074 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1075 resourceTicket->AddObserver( testTicketObserver );
1077 DALI_TEST_CHECK( resourceTicket );
1078 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1079 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1081 application.SendNotification(); // Flush update queue
1082 application.Render(0); // Process message
1083 application.SendNotification(); // Send message to tickets
1085 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1086 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1090 int UtcDaliInternalAddNativeImage(void)
1092 TestApplication application;
1093 tet_infoline("Testing AddNativeImage()");
1095 testTicketObserver.Reset();
1096 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1097 Internal::ResourceTicketPtr ticket;
1098 Internal::ImageTicketPtr imageTicket;
1099 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1100 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1101 ticket = resourceClient.AddNativeImage( *nativeImage );
1102 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1103 DALI_TEST_CHECK( imageTicket );
1104 imageTicket->AddObserver( testTicketObserver );
1107 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1108 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1109 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1110 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1112 application.SendNotification(); // Flush update queue
1113 application.Render(0); // Process message
1114 application.SendNotification(); // Send message to tickets
1116 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1117 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1118 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1119 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1121 Integration::Bitmap* theBitmap = NULL;
1122 theBitmap = resourceClient.GetBitmap(imageTicket);
1124 DALI_TEST_CHECK ( theBitmap == NULL );
1128 int UtcDaliInternalAddFrameBufferImage(void)
1130 TestApplication application;
1131 tet_infoline("Testing AddFrameBufferImage()");
1133 testTicketObserver.Reset();
1134 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1135 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1136 DALI_TEST_CHECK( imageTicket );
1137 imageTicket->AddObserver( testTicketObserver );
1139 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1140 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1141 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1142 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1144 application.SendNotification(); // Flush update queue
1145 application.Render(0); // Process message
1146 application.SendNotification(); // Send message to tickets
1148 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1149 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1150 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1151 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1153 Integration::Bitmap* theBitmap = NULL;
1154 theBitmap = resourceClient.GetBitmap(imageTicket);
1155 DALI_TEST_CHECK ( theBitmap == NULL );
1159 int UtcDaliInternalAllocateMesh01(void)
1161 TestApplication application;
1162 tet_infoline("Testing AllocateMesh() with vald mesh data");
1164 MeshData publicMeshData;
1165 MeshData::VertexContainer vertices;
1166 MeshData::FaceIndices faces;
1167 BoneContainer bones;
1168 ConstructVertices(vertices, 60);
1169 ConstructFaces(vertices, faces);
1170 Material customMaterial = ConstructMaterial();
1171 publicMeshData.SetData(vertices, faces, bones, customMaterial);
1172 publicMeshData.SetHasNormals(true);
1173 publicMeshData.SetHasTextureCoords(true);
1175 testTicketObserver.Reset();
1176 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1177 Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, ResourcePolicy::DISCARD, true ) );
1178 Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1179 DALI_TEST_CHECK( meshTicket );
1180 meshTicket->AddObserver( testTicketObserver );
1182 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1184 application.SendNotification(); // Flush update queue
1185 application.Render(0); // Process message
1186 application.SendNotification(); // Send message to tickets
1188 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );