2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
22 #include <test-native-image.h>
24 // Internal headers are allowed here
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/update/resources/bitmap-metadata.h>
28 #include <dali/internal/update/resources/resource-manager.h>
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/internal/event/resources/resource-client.h>
31 #include <dali/internal/event/resources/resource-ticket.h>
32 #include <dali/internal/event/resources/image-ticket.h>
33 #include <dali/internal/event/resources/resource-ticket-observer.h>
34 #include <dali/internal/event/images/image-impl.h>
35 #include <dali/internal/event/modeling/model-data-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::ImagePtr image = Internal::Image::New(name);
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, false );
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, false );
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 Internal::ResourceTicketPtr CheckLoadModel(TestApplication& application, const char* name)
162 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
163 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), name );
164 ticket->AddObserver(testTicketObserver);
166 application.SendNotification(); // Flush update messages
167 application.Render(); // Process resource request
168 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
169 Dali::ModelData modelData = BuildTreeModel();
170 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
171 Integration::ResourcePointer resourcePtr(&modelDataImpl);
172 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
173 application.Render(); // Process LoadComplete
174 application.SendNotification(); // Process event messages
175 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
176 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
178 application.GetPlatform().ResetTrace();
183 } //anonymous namespace
186 void utc_dali_internal_resource_client_startup()
188 test_return_value = TET_UNDEF;
191 void utc_dali_internal_resource_client_cleanup()
193 test_return_value = TET_PASS;
196 // Load a bitmap resource successfully, then discard it's ticket
197 int UtcDaliInternalRequestResourceBitmapRequests01(void)
199 TestApplication application; // Reset all test adapter return codes
201 tet_infoline("Testing bitmap requests");
203 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
204 ImageAttributes attr;
205 Integration::BitmapResourceType bitmapRequest (attr);
206 Internal::ResourceId id(0);
208 testTicketObserver.Reset();
211 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
212 /************************************************************
213 * FUNCTION UNDER TEST
214 ***********************************************************/
215 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
216 ticket->AddObserver(testTicketObserver);
218 // Update thread will request the bitmap resource:
219 // Sets application.GetPlatform().mRequest
220 application.SendNotification(); // Run flush update queue
221 application.Render(1); // Process update messages
222 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
224 application.SendNotification(); // Send any event messages
225 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
226 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
227 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
229 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
230 DALI_TEST_CHECK( imageTicket );
231 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
232 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
235 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
236 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
237 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
238 Integration::ResourcePointer resourcePtr(bitmap); // reference it
240 // Set up platform abstraction to load it
242 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
244 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
246 // load the cache, which will immediately have the loaded resource
247 application.Render(0);
249 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
251 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
252 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
253 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
254 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
256 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
257 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
259 // Trigger the event thread to process notify messages. Should then trigger the signals
260 // in the ticket observer
261 application.SendNotification();
263 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
264 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
266 // Check that the image ticket was updated with the image attributes
267 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
268 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
271 application.SendNotification(); // Flush update queue (with ticket discarded message
272 application.Render(1); // Process update messages
273 application.SendNotification(); // Send event notifications
274 application.Render(1); // Process update messages
276 // Resource should have been discarded.
277 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
278 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
280 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
281 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
285 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
286 int UtcDaliInternalRequestResourceBitmapRequests02(void)
288 TestApplication application; // Reset all test adapter return codes
290 tet_infoline("Testing bitmap request ticket discard before load complete");
292 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
293 ImageAttributes attr;
294 Integration::BitmapResourceType bitmapRequest (attr);
295 Internal::ResourceId id(0);
297 testTicketObserver.Reset();
300 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
301 /************************************************************
302 * FUNCTION UNDER TEST
303 ***********************************************************/
304 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
305 ticket->AddObserver(testTicketObserver);
306 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
307 DALI_TEST_CHECK( imageTicket );
308 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
309 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
311 // Update thread will request the bitmap resource:
312 // Sets application.GetPlatform().mRequest
313 application.SendNotification(); // Run flush update queue
314 application.Render(1);
315 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
316 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
319 application.SendNotification(); // Should produce no messages
320 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
321 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
323 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
325 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
326 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
327 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
331 // Ensure ticket discarded message is sent to update thread
332 application.SendNotification(); // Flush update queue
333 application.Render(0); // Process update messages
335 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
336 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
338 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
340 // Trigger the event thread to process notify messages. Should then trigger the signals
341 // in the ticket observer
342 application.SendNotification();
344 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
345 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
349 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
350 int UtcDaliInternalRequestResourceBitmapRequests03(void)
352 TestApplication application; // Reset all test adapter return codes
354 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
356 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
357 ImageAttributes attr;
358 Integration::BitmapResourceType bitmapRequest (attr);
359 Internal::ResourceId id(0);
361 testTicketObserver.Reset();
362 { // Scope lifetime of ticket
363 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
365 /************************************************************
366 * FUNCTION UNDER TEST
367 ***********************************************************/
368 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
369 ticket->AddObserver(testTicketObserver);
370 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
371 DALI_TEST_CHECK( imageTicket );
372 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
373 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
375 // Update thread will request the bitmap resource:
376 // Sets application.GetPlatform().mRequest
377 application.SendNotification(); // Run flush update queue
378 application.Render(1); // process update messages
379 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
380 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
382 application.SendNotification(); // Should produce no messages
383 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
384 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
386 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
388 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
390 application.Render(0); // Get failed result
391 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
392 application.SendNotification(); // send failed
393 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
394 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
396 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
397 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
398 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
400 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
403 application.Render(0); // Send DiscardTicket
404 application.SendNotification();
406 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
412 // Load a bitmap resource successfully, then reload it
413 int UtcDaliInternalRequestReloadBitmapRequests01(void)
415 TestApplication application; // Reset all test adapter return codes
417 tet_infoline("Testing bitmap reload after successful load");
419 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
420 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
422 Internal::ResourceId id(0);
423 testTicketObserver.Reset();
426 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
427 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
428 id = ticket->GetId();
430 // Reset call statistics - test that resource is reloaded
431 application.GetPlatform().ResetTrace();
433 /************************************************************
434 * FUNCTION UNDER TEST
435 ***********************************************************/
436 resourceClient.ReloadResource( ticket->GetId() );
438 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
439 application.SendNotification(); // Flush update messages
440 application.Render(0); // Process update messages
441 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
442 application.SendNotification(); // Process event messages
444 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
445 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
446 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
447 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
449 // Create a new resource - the image size could have changed in the meantime
450 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
451 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
452 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
453 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
454 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
455 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
457 application.Render(0); // Process update messages / UpdateCache
458 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
460 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
461 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
462 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
463 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
465 // Ticket can't have been updated yet - it should still have old values
466 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
467 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
469 application.SendNotification(); // Process event messages
470 application.Render(0); // Process update messages / UpdateCache
471 application.SendNotification(); // Process event messages
473 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
474 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
475 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
476 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
477 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
481 application.SendNotification(); // Flush update queue (with ticket discarded message
482 application.Render(1); // Process update messages
483 application.SendNotification(); // Send event notifications
484 application.Render(1); // Process update messages
486 // Resource should have been discarded.
487 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
488 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
490 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
491 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
492 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
497 int UtcDaliInternalRequestReloadBitmapRequests02(void)
499 TestApplication application; // Reset all test adapter return codes
501 tet_infoline("Testing bitmap reload during first load");
503 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
504 ImageAttributes attr;
505 Integration::BitmapResourceType bitmapRequest (attr);
506 Internal::ResourceId id(0);
508 testTicketObserver.Reset();
511 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
512 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
513 ticket->AddObserver(testTicketObserver);
515 // Update thread will request the bitmap resource:
516 // Sets application.GetPlatform().mRequest
517 application.SendNotification(); // Run flush update queue
518 application.Render(1); // Process update messages
519 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
521 application.SendNotification(); // Send any event messages
522 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
523 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
525 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
526 DALI_TEST_CHECK( imageTicket );
527 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
528 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
531 /************************************************************
532 * FUNCTION UNDER TEST
533 ***********************************************************/
534 resourceClient.ReloadResource( ticket->GetId() );
535 /************************************************************
536 * Expected result - current load completes as usual, no reload requested
537 ************************************************************/
539 application.SendNotification(); // Flush update methods
541 // Reset call statistics - test that resource is not reloaded
542 application.GetPlatform().ResetTrace();
544 application.Render(0); // Process reload message (nothing for UpdateCache yet)
546 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
547 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
549 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
550 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
551 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
552 Integration::ResourcePointer resourcePtr(bitmap); // reference it
554 // Set up platform abstraction to load it
557 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
559 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
561 application.GetPlatform().ResetTrace();
562 // load the cache, which will immediately have the loaded resource
563 application.Render(0);
564 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
565 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
566 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
567 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
568 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
570 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
571 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
573 // Trigger the event thread to process notify messages. Should then trigger the signals
574 // in the ticket observer
575 application.SendNotification();
577 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
578 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
579 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
581 // Check that the image ticket was updated with the image attributes
582 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
583 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
585 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
587 application.SendNotification(); // Flush update messages
588 application.Render(0); // Process update messages
590 // There should be no reload
591 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
592 application.SendNotification(); // Process event messages
594 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
595 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
596 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
597 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
599 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
600 bitmapData = resourceManager.GetBitmapMetadata(id);
601 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
602 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
603 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
604 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
611 int UtcDaliInternalRequestReloadBitmapRequests03(void)
613 TestApplication application; // Reset all test adapter return codes
615 tet_infoline("Testing bitmap reload at end of first load");
617 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
618 ImageAttributes attr;
619 Integration::BitmapResourceType bitmapRequest (attr);
620 Internal::ResourceId id(0);
622 testTicketObserver.Reset();
625 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
626 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
627 ticket->AddObserver(testTicketObserver);
629 // Update thread will request the bitmap resource:
630 // Sets application.GetPlatform().mRequest
631 application.SendNotification(); // Run flush update queue
632 application.Render(1); // Process update messages
633 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
635 application.SendNotification(); // Send any event messages
636 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
637 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
639 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
640 DALI_TEST_CHECK( imageTicket );
641 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
642 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
645 /************************************************************
646 * FUNCTION UNDER TEST
647 ***********************************************************/
648 resourceClient.ReloadResource( ticket->GetId() );
649 /************************************************************
650 * Expected result - current load completes as usual, no reload requested
651 ************************************************************/
653 application.SendNotification(); // Flush update methods
655 // Reset call statistics - test that resource is not reloaded
656 application.GetPlatform().ResetTrace();
659 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
660 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
661 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
662 Integration::ResourcePointer resourcePtr(bitmap); // reference it
664 // Set up platform abstraction to load it
667 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
669 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
671 application.GetPlatform().ResetTrace();
672 // load the cache, which will immediately have the loaded resource
673 application.Render(0);
675 // UpdateCache runs before ProcessMessages, so the loading resource completes before
676 // the reload request is handled.
677 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
678 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
680 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
681 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
682 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
683 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
685 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
686 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
688 // Trigger the event thread to process notify messages. Should then trigger the signals
689 // in the ticket observer
690 application.SendNotification();
692 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
693 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
694 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
696 // Check that the image ticket was updated with the image attributes
697 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
698 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
700 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
702 // Create a new resource - the image size could have changed in the meantime
703 req = application.GetPlatform().GetRequest();
704 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
705 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
706 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
707 DALI_TEST_CHECK( req->GetId() == id );
708 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
710 application.Render(0); // Process update messages / UpdateCache
712 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
713 bitmapData = resourceManager.GetBitmapMetadata(id);
714 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
715 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
716 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
717 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
719 application.SendNotification(); // Process event messages
721 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
723 // Not staged - no GL upload
724 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
726 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
727 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
728 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
729 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
735 int UtcDaliInternalSaveResource01(void)
737 TestApplication application;
738 tet_infoline("Testing SaveResource() with valid id, and valid filename");
740 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
742 Dali::ModelData modelData = BuildTreeModel();
743 testTicketObserver.Reset();
745 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
746 ticket->AddObserver(testTicketObserver);
748 // First, load a model resource
749 application.SendNotification(); // Flush update messages
750 application.Render(); // Process resource request
751 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
752 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
753 Integration::ResourcePointer resourcePtr(&modelDataImpl);
755 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
756 application.Render(); // Process LoadComplete
757 application.SendNotification(); // Process event messages
758 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
761 resourceClient.SaveResource( ticket, "model.dali-bin" );
762 application.SendNotification(); // Flush update messages
763 application.Render(); // Process save resource request
765 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
766 req = application.GetPlatform().GetRequest();
767 DALI_TEST_CHECK( req->GetType()->id == Integration::ResourceModel );
768 DALI_TEST_CHECK( req->GetPath().compare("model.dali-bin") == 0 );
770 // Set up success response
771 application.GetPlatform().SetResourceSaved(req->GetId(), req->GetType()->id);
772 application.Render(); // GetResources --> SaveComplete
773 application.SendNotification(); // Send event messages
775 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 1 );
776 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
782 int UtcDaliInternalSaveResource02(void)
784 TestApplication application;
785 tet_infoline("Testing SaveResource() with invalid id");
786 testTicketObserver.Reset();
788 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
790 Dali::ModelData modelData = BuildTreeModel();
792 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
793 ticket->AddObserver(testTicketObserver);
795 // First, load a model resource
796 application.SendNotification(); // Flush update messages
797 application.Render(); // Process resource request
798 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
799 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
800 Integration::ResourcePointer resourcePtr(&modelDataImpl);
801 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
802 application.Render(); // Process LoadComplete
803 application.SendNotification(); // Process event messages
804 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
805 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
807 Internal::ResourceTypePath typePath(Integration::ModelResourceType(), "");
808 Internal::ResourceTicketPtr aTicket = new Internal::ResourceTicket( testTicketLifetimeObserver, 2000, typePath );
811 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
812 } catch (DaliException& e)
814 // Tests that a negative test of an assertion succeeds
815 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
817 DALI_TEST_ASSERT(e, "mImpl->mTickets.find(ticket->GetId()) != mImpl->mTickets.end()", TEST_LOCATION );
820 application.SendNotification(); // Flush update messages
821 application.Render(); // Process save resource request
823 // Ensure no request sent to platform abstraction
824 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
825 req = application.GetPlatform().GetRequest();
826 DALI_TEST_CHECK ( req == NULL );
830 int UtcDaliInternalSaveResource03(void)
832 TestApplication application;
833 tet_infoline("Testing SaveResource() with invalid id");
834 testTicketObserver.Reset();
836 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
838 Dali::ModelData modelData = BuildTreeModel();
840 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
841 ticket->AddObserver(testTicketObserver);
843 // First, load a model resource
844 application.SendNotification(); // Flush update messages
845 application.Render(); // Process resource request
846 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
847 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
848 Integration::ResourcePointer resourcePtr(&modelDataImpl);
849 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
850 application.Render(); // Process LoadComplete
851 application.SendNotification(); // Process event messages
852 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
853 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
855 Internal::ResourceTicketPtr aTicket;
858 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
859 } catch (DaliException& e)
861 // Tests that a negative test of an assertion succeeds
862 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
864 DALI_TEST_EQUALS(e.mCondition, "ticket", TEST_LOCATION);
867 application.SendNotification(); // Flush update messages
868 application.Render(); // Process save resource request
870 // Ensure no request sent to platform abstraction
871 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
872 req = application.GetPlatform().GetRequest();
873 DALI_TEST_CHECK ( req == NULL );
878 int UtcDaliInternalSaveResource04(void)
880 TestApplication application;
881 tet_infoline("Testing SaveResource() with valid id, but invalid filename");
882 testTicketObserver.Reset();
884 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
886 // First, load a model resource
887 Internal::ResourceTicketPtr ticket = CheckLoadModel(application, "model.dae");
889 resourceClient.SaveResource( ticket, "model.dali-bin" );
890 application.SendNotification(); // Flush update messages
891 application.Render(); // Process save resource request
893 // Set up fail response
894 application.GetPlatform().SetResourceSaveFailed(ticket->GetId(), Integration::FailureInvalidPath );
895 application.Render(); // GetResources --> SaveFailed
896 application.SendNotification(); // Send event messages
898 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 0 );
899 DALI_TEST_CHECK( testTicketObserver.SaveFailedCalled() == 1 );
900 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
905 int UtcDaliInternalSaveResource05(void)
907 TestApplication application;
908 tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
909 testTicketObserver.Reset();
911 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
913 // First, load a bitmap resource
914 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
917 resourceClient.SaveResource( ticket, "bitmap.png" );
918 application.SendNotification(); // Flush update messages
919 application.Render(); // Process save resource request
921 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
925 int UtcDaliInternalRequestResourceTicket01(void)
927 TestApplication application;
928 tet_infoline("Testing RequestResourceTicket() with valid id");
930 testTicketObserver.Reset();
932 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
934 // First, load a bitmap resource
935 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
937 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
938 DALI_TEST_CHECK( newTicket );
939 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
940 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
944 int UtcDaliInternalRequestResourceTicket02(void)
946 TestApplication application;
947 tet_infoline("Testing RequestResourceTicket() with invalid id");
949 testTicketObserver.Reset();
951 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
953 // First, load a bitmap resource
954 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
956 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
957 DALI_TEST_CHECK( ! newTicket );
961 int UtcDaliInternalLoadShaderRequest01(void)
963 TestApplication application;
964 tet_infoline("Testing LoadShader() success");
965 testTicketObserver.Reset();
967 // Clear through all of the outstanding shader load requests from the default shader effect
968 std::vector< unsigned char > buffer;
969 for( int i=0; i<10; i++ )
971 buffer.push_back((unsigned char)i);
973 application.GetPlatform().SetLoadFileResult( true, buffer );
974 application.GetGlAbstraction().SetLinkStatus(1);
975 application.SendNotification(); // Flush update messages
976 application.Render(); // Process load shader request (immediately)
977 application.SendNotification();
978 application.Render();
979 application.SendNotification();
980 application.Render();
981 application.SendNotification();
983 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
985 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
986 std::string shaderBinaryFile("shader.bin");
987 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
988 DALI_TEST_CHECK( ticket );
990 application.GetPlatform().SetLoadFileResult( true, buffer );
991 application.GetGlAbstraction().EnableShaderCallTrace( true );
992 application.GetGlAbstraction().SetLinkStatus(1);
994 application.SendNotification(); // Flush update messages
995 application.Render(); // Process load shader request (immediately)
997 application.SendNotification();
998 application.Render();
1000 application.SendNotification();
1001 application.Render();
1003 // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
1004 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1005 DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
1007 // Ensure no request sent to platform abstraction
1008 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1012 int UtcDaliInternalLoadShaderRequest02(void)
1014 TestApplication application;
1015 tet_infoline("Testing LoadShader() failure");
1016 testTicketObserver.Reset();
1018 // Clear through all of the outstanding shader load requests from the default shader effect
1019 std::vector< unsigned char > buffer;
1020 for( int i=0; i<10; i++ )
1022 buffer.push_back((unsigned char)i);
1024 application.GetPlatform().SetLoadFileResult( true, buffer );
1025 application.GetGlAbstraction().SetLinkStatus(1);
1026 application.SendNotification(); // Flush update messages
1027 application.Render(); // Process load shader request (immediately)
1028 application.SendNotification();
1029 application.Render();
1030 application.SendNotification();
1031 application.Render();
1032 application.SendNotification();
1034 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1035 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
1037 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
1038 std::string shaderBinaryFile("shader.bin");
1039 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
1040 ticket->AddObserver(testTicketObserver);
1042 ShaderEffect::GeometryHints hints = ShaderEffect::HINT_NONE;
1043 Internal::SceneGraph::Shader* sceneObject = new Internal::SceneGraph::Shader( hints );
1044 AddShaderMessage( updateManager, *sceneObject );
1046 size_t shaderHash=0;
1047 SetShaderProgramMessage( updateManager, *sceneObject, GEOMETRY_TYPE_IMAGE, Internal::SHADER_DEFAULT, ticket->GetId(), shaderHash );
1049 DALI_TEST_CHECK( ticket );
1052 DALI_TEST_CHECK(buffer.size() == 0);
1054 application.GetPlatform().SetLoadFileResult( true, buffer );
1055 application.GetGlAbstraction().ResetShaderCallStack();
1056 application.GetGlAbstraction().EnableShaderCallTrace( true );
1057 application.GetGlAbstraction().SetLinkStatus(1);
1058 application.GetGlAbstraction().SetProgramBinaryLength(20);
1059 application.GetPlatform().SetResourceSaved (ticket->GetId(), Integration::ResourceShader );
1061 application.SendNotification(); // Flush update messages
1062 application.Render(); // Process load shader request (immediately), add responses
1063 // to post process q
1064 application.Render(); // this update will process old post-process-q
1065 application.Render(); // this update will process new post-process-q
1066 application.SendNotification(); // Send save request to event thread
1067 application.Render(); // this update will process save request
1068 application.Render(); // this update will get SaveComplete
1069 application.SendNotification(); // Send save request response
1071 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1072 DALI_TEST_CHECK( shaderTrace.FindMethod("CompileShader") );
1074 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1075 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() );
1079 int UtcDaliInternalAllocateBitmapImage01(void)
1081 TestApplication application;
1082 tet_infoline("Testing AllocateBitmapImage()");
1083 testTicketObserver.Reset();
1085 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1086 Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1087 imageTicket->AddObserver( testTicketObserver );
1089 DALI_TEST_CHECK( imageTicket );
1090 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1091 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1092 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1093 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1095 application.SendNotification(); // Flush update queue
1096 application.Render(0); // Process message
1097 application.SendNotification(); // Send message to tickets
1099 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1100 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1101 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1102 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1103 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1105 Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1106 DALI_TEST_CHECK ( bitmap != NULL );
1107 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1108 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1109 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1110 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1111 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1115 int UtcDaliInternalAddBitmapImage01(void)
1117 TestApplication application;
1118 tet_infoline("Testing AddBitmap with reserved buffer()");
1119 testTicketObserver.Reset();
1120 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1121 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1122 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1124 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1125 DALI_TEST_CHECK( imageTicket );
1126 imageTicket->AddObserver( testTicketObserver );
1128 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1129 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1130 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1131 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1133 application.SendNotification(); // Flush update queue
1134 application.Render(0); // Process message
1135 application.SendNotification(); // Send message to tickets
1137 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1138 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1139 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1140 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1141 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1143 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1144 DALI_TEST_CHECK ( theBitmap != NULL );
1145 DALI_TEST_CHECK ( bitmap == theBitmap );
1146 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1147 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1148 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1149 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1150 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1154 int UtcDaliInternalAddBitmapImage02(void)
1156 TestApplication application;
1157 tet_infoline("Testing AddBitmap without reserved buffer()");
1158 testTicketObserver.Reset();
1159 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1160 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1162 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1163 DALI_TEST_CHECK( imageTicket );
1164 imageTicket->AddObserver( testTicketObserver );
1166 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1167 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1168 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1169 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1170 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1172 application.SendNotification(); // Flush update queue
1173 application.Render(0); // Process message
1174 application.SendNotification(); // Send message to tickets
1176 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1177 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1178 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1179 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1180 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1182 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1183 DALI_TEST_CHECK ( theBitmap != NULL );
1184 DALI_TEST_CHECK ( bitmap == theBitmap );
1185 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1186 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1187 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1188 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1189 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1191 // There is no way for the ticket's image attributes to be updated if the bitmap
1192 // reserves a buffer after ticket generation.
1193 // Probably not an issue - there is no public API in BufferImage to change the image size.
1198 int UtcDaliInternalAddBitmapImage03(void)
1200 TestApplication application;
1201 tet_infoline("Testing AddBitmap() with invalid bitmap");
1202 testTicketObserver.Reset();
1204 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1205 Internal::ImageTicketPtr imageTicket;
1206 bool exceptionRaised=false;
1209 imageTicket = resourceClient.AddBitmapImage( NULL );
1211 catch( DaliException& e )
1213 exceptionRaised = true;
1215 DALI_TEST_CHECK( exceptionRaised );
1216 DALI_TEST_CHECK( ! imageTicket );
1220 int UtcDaliInternalGetBitmapImage01(void)
1222 TestApplication application;
1223 tet_infoline("Testing GetBitmap() with valid ticket");
1224 testTicketObserver.Reset();
1226 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1227 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1228 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1229 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1231 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1232 DALI_TEST_CHECK ( theBitmap != NULL );
1233 DALI_TEST_CHECK ( bitmap == theBitmap );
1234 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1235 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1236 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1237 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1238 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1240 imageTicket->AddObserver( testTicketObserver );
1241 application.SendNotification(); // Flush update queue
1242 application.Render(0); // Process message
1243 application.SendNotification(); // Send message to tickets
1245 theBitmap = resourceClient.GetBitmap(imageTicket);
1246 DALI_TEST_CHECK ( theBitmap != NULL );
1247 DALI_TEST_CHECK ( bitmap == theBitmap );
1248 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1249 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1250 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1251 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1252 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1256 int UtcDaliInternalGetBitmapImage02(void)
1258 TestApplication application;
1259 tet_infoline("Testing GetBitmap() with invalid ticket");
1261 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1262 Internal::ImageTicketPtr imageTicket;
1263 Integration::Bitmap* theBitmap = NULL;
1264 bool exceptionRaised = false;
1267 theBitmap = resourceClient.GetBitmap(imageTicket);
1268 } catch (DaliException& e)
1270 exceptionRaised = true;
1272 DALI_TEST_CHECK( exceptionRaised );
1273 DALI_TEST_CHECK( ! theBitmap );
1277 int UtcDaliInternalGetBitmapImage03(void)
1279 TestApplication application;
1280 tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1282 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1283 Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1285 Integration::Bitmap* theBitmap = NULL;
1286 theBitmap = resourceClient.GetBitmap(imageTicket);
1287 DALI_TEST_CHECK( ! theBitmap );
1289 theBitmap = resourceClient.GetBitmap(modelTicket);
1290 DALI_TEST_CHECK( ! theBitmap );
1294 int UtcDaliInternalAllocateTexture01(void)
1296 TestApplication application;
1297 tet_infoline("Testing AllocateTexture()");
1298 testTicketObserver.Reset();
1300 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1301 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1302 resourceTicket->AddObserver( testTicketObserver );
1304 DALI_TEST_CHECK( resourceTicket );
1305 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1306 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1308 application.SendNotification(); // Flush update queue
1309 application.Render(0); // Process message
1310 application.SendNotification(); // Send message to tickets
1312 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1313 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1317 int UtcDaliInternalAddNativeImage(void)
1319 TestApplication application;
1320 tet_infoline("Testing AddNativeImage()");
1322 testTicketObserver.Reset();
1323 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1324 Internal::ResourceTicketPtr ticket;
1325 Internal::ImageTicketPtr imageTicket;
1326 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1327 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1328 ticket = resourceClient.AddNativeImage( *nativeImage );
1329 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1330 DALI_TEST_CHECK( imageTicket );
1331 imageTicket->AddObserver( testTicketObserver );
1334 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1335 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1336 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1337 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1339 application.SendNotification(); // Flush update queue
1340 application.Render(0); // Process message
1341 application.SendNotification(); // Send message to tickets
1343 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1344 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1345 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1346 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1348 Integration::Bitmap* theBitmap = NULL;
1349 theBitmap = resourceClient.GetBitmap(imageTicket);
1351 DALI_TEST_CHECK ( theBitmap == NULL );
1355 int UtcDaliInternalAddFrameBufferImage(void)
1357 TestApplication application;
1358 tet_infoline("Testing AddFrameBufferImage()");
1360 testTicketObserver.Reset();
1361 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1362 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1363 DALI_TEST_CHECK( imageTicket );
1364 imageTicket->AddObserver( testTicketObserver );
1366 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1367 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1368 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1369 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1370 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1372 application.SendNotification(); // Flush update queue
1373 application.Render(0); // Process message
1374 application.SendNotification(); // Send message to tickets
1376 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1377 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1378 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1379 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1380 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1382 Integration::Bitmap* theBitmap = NULL;
1383 theBitmap = resourceClient.GetBitmap(imageTicket);
1384 DALI_TEST_CHECK ( theBitmap == NULL );
1388 int UtcDaliInternalAllocateMesh01(void)
1390 TestApplication application;
1391 tet_infoline("Testing AllocateMesh() with vald mesh data");
1393 MeshData publicMeshData;
1394 MeshData::VertexContainer vertices;
1395 MeshData::FaceIndices faces;
1396 BoneContainer bones;
1397 ConstructVertices(vertices, 60);
1398 ConstructFaces(vertices, faces);
1399 Material customMaterial = ConstructMaterial();
1400 publicMeshData.SetData(vertices, faces, bones, customMaterial);
1401 publicMeshData.SetHasNormals(true);
1402 publicMeshData.SetHasTextureCoords(true);
1404 testTicketObserver.Reset();
1405 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1406 Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, true, true ) );
1407 Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1408 DALI_TEST_CHECK( meshTicket );
1409 meshTicket->AddObserver( testTicketObserver );
1411 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1413 application.SendNotification(); // Flush update queue
1414 application.Render(0); // Process message
1415 application.SendNotification(); // Send message to tickets
1417 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );