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/integration-api/image-data.h>
38 #include <dali/integration-api/resource-types.h>
39 #include <dali/internal/render/gl-resources/texture-declarations.h>
40 #include <dali/internal/render/shaders/shader.h>
41 #include <dali/internal/common/owner-pointer.h>
42 #include <dali/public-api/shader-effects/shader-effect.h>
46 #include <mesh-builder.h>
51 class TestTicketObserver : public Internal::ResourceTicketObserver
55 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
56 mSavingFailedCalled(0), mSavingSucceededCalled(0),
60 int LoadFailedCalled() {
61 tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
62 return mLoadingFailedCalled;
64 int LoadSucceededCalled() {
65 tet_printf("TicketObserver: LoadingSucceeded() called %d times", mLoadingSucceededCalled);
66 return mLoadingSucceededCalled;
68 int SaveFailedCalled() {
69 tet_printf("TicketObserver: SavingFailed() called %d times", mSavingFailedCalled);
70 return mSavingFailedCalled;
72 int SaveSucceededCalled() {
73 tet_printf("TicketObserver: SavingSucceeded() called %d times", mSavingSucceededCalled);
74 return mSavingSucceededCalled;
77 tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
78 return mUploadedCount;
81 mLoadingFailedCalled = 0;
82 mLoadingSucceededCalled = 0;
83 mSavingFailedCalled = 0;
84 mSavingSucceededCalled = 0;
88 public: // From ResourceTicketObserver
89 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
90 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
91 virtual void ResourceSavingFailed(const Internal::ResourceTicket& ticket) {mSavingFailedCalled++;}
92 virtual void ResourceSavingSucceeded(const Internal::ResourceTicket& ticket) {mSavingSucceededCalled++;}
93 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
96 int mLoadingFailedCalled;
97 int mLoadingSucceededCalled;
98 int mSavingFailedCalled;
99 int mSavingSucceededCalled;
103 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
106 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
108 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
109 { resourceTicketDiscarded = true; }
111 void Reset() { resourceTicketDiscarded = false; }
112 bool resourceTicketDiscarded;
115 static TestTicketObserver testTicketObserver;
116 static TestTicketLifetimeObserver testTicketLifetimeObserver;
119 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
121 Internal::ImagePtr image = Internal::Image::New(name);
122 application.SendNotification(); // Flush update messages
123 application.Render(); // Process resource request
124 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
125 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
126 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
127 Integration::ResourcePointer resourcePtr(bitmap); // reference it
128 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
129 application.Render(); // Process LoadComplete
130 application.SendNotification(); // Process event messages
131 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
133 application.GetPlatform().ResetTrace();
138 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
140 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
141 ImageAttributes attr;
142 Integration::ImageResourceType bitmapRequest( Integration::ResourceImageData, attr);
143 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
144 ticket->AddObserver(testTicketObserver);
145 application.SendNotification(); // Flush update messages
146 application.Render(); // Process resource request
147 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
148 Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( w, h, Pixel::RGBA8888 );
149 Integration::ResourcePointer resourcePtr(bitmap); // reference it
150 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
151 application.Render(); // Process LoadComplete
152 application.SendNotification(); // Process event messages
153 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
154 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
156 application.GetPlatform().ResetTrace();
161 Internal::ResourceTicketPtr CheckLoadModel(TestApplication& application, const char* name)
163 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
164 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), name );
165 ticket->AddObserver(testTicketObserver);
167 application.SendNotification(); // Flush update messages
168 application.Render(); // Process resource request
169 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
170 Dali::ModelData modelData = BuildTreeModel();
171 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
172 Integration::ResourcePointer resourcePtr(&modelDataImpl);
173 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
174 application.Render(); // Process LoadComplete
175 application.SendNotification(); // Process event messages
176 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
177 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
179 application.GetPlatform().ResetTrace();
184 } //anonymous namespace
187 void utc_dali_internal_resource_client_startup()
189 test_return_value = TET_UNDEF;
192 void utc_dali_internal_resource_client_cleanup()
194 test_return_value = TET_PASS;
197 // Load a bitmap resource successfully, then discard it's ticket
198 int UtcDaliInternalRequestResourceBitmapRequests01(void)
200 TestApplication application; // Reset all test adapter return codes
202 tet_infoline("Testing bitmap requests");
204 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
205 ImageAttributes attr;
206 Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
207 Internal::ResourceId id(0);
209 testTicketObserver.Reset();
212 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
213 /************************************************************
214 * FUNCTION UNDER TEST
215 ***********************************************************/
216 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
217 ticket->AddObserver(testTicketObserver);
219 // Update thread will request the bitmap resource:
220 // Sets application.GetPlatform().mRequest
221 application.SendNotification(); // Run flush update queue
222 application.Render(1); // Process update messages
223 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
225 application.SendNotification(); // Send any event messages
226 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
227 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
228 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
230 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
231 DALI_TEST_CHECK( imageTicket );
232 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
233 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
236 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
237 Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
238 Integration::ResourcePointer resourcePtr(bitmap); // reference it
240 // Set up platform abstraction to load it
242 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceImageData, 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::ImageResourceType bitmapRequest (Integration::ResourceImageData, 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::ImageResourceType bitmapRequest (Integration::ResourceImageData, 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::ImageDataPtr bitmap2 = Integration::NewBitmapImageData( 120, 120, Pixel::RGBA8888 );
452 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
453 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
454 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr2);
456 application.Render(0); // Process update messages / UpdateCache
457 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
459 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
460 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
461 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
462 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
464 // Ticket can't have been updated yet - it should still have old values
465 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
466 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
468 application.SendNotification(); // Process event messages
469 application.Render(0); // Process update messages / UpdateCache
470 application.SendNotification(); // Process event messages
472 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
473 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
474 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
475 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
476 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
480 application.SendNotification(); // Flush update queue (with ticket discarded message
481 application.Render(1); // Process update messages
482 application.SendNotification(); // Send event notifications
483 application.Render(1); // Process update messages
485 // Resource should have been discarded.
486 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
487 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
489 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
490 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
491 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
496 int UtcDaliInternalRequestReloadBitmapRequests02(void)
498 TestApplication application; // Reset all test adapter return codes
500 tet_infoline("Testing bitmap reload during first load");
502 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
503 ImageAttributes attr;
504 Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
505 Internal::ResourceId id(0);
507 testTicketObserver.Reset();
510 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
511 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
512 ticket->AddObserver(testTicketObserver);
514 // Update thread will request the bitmap resource:
515 // Sets application.GetPlatform().mRequest
516 application.SendNotification(); // Run flush update queue
517 application.Render(1); // Process update messages
518 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
520 application.SendNotification(); // Send any event messages
521 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
522 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
524 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
525 DALI_TEST_CHECK( imageTicket );
526 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
527 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
530 /************************************************************
531 * FUNCTION UNDER TEST
532 ***********************************************************/
533 resourceClient.ReloadResource( ticket->GetId() );
534 /************************************************************
535 * Expected result - current load completes as usual, no reload requested
536 ************************************************************/
538 application.SendNotification(); // Flush update methods
540 // Reset call statistics - test that resource is not reloaded
541 application.GetPlatform().ResetTrace();
543 application.Render(0); // Process reload message (nothing for UpdateCache yet)
545 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
546 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
548 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
549 Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
550 Integration::ResourcePointer resourcePtr(bitmap); // reference it
552 // Set up platform abstraction to load it
555 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr);
557 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
559 application.GetPlatform().ResetTrace();
560 // load the cache, which will immediately have the loaded resource
561 application.Render(0);
562 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
563 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
564 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
565 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
566 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
568 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
569 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
571 // Trigger the event thread to process notify messages. Should then trigger the signals
572 // in the ticket observer
573 application.SendNotification();
575 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
576 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
577 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
579 // Check that the image ticket was updated with the image attributes
580 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
581 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
583 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
585 application.SendNotification(); // Flush update messages
586 application.Render(0); // Process update messages
588 // There should be no reload
589 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
590 application.SendNotification(); // Process event messages
592 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
593 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
594 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
595 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
597 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
598 bitmapData = resourceManager.GetBitmapMetadata(id);
599 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
600 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
601 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
602 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
609 int UtcDaliInternalRequestReloadBitmapRequests03(void)
611 TestApplication application; // Reset all test adapter return codes
613 tet_infoline("Testing bitmap reload at end of first load");
615 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
616 ImageAttributes attr;
617 Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
618 Internal::ResourceId id(0);
620 testTicketObserver.Reset();
623 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
624 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
625 ticket->AddObserver(testTicketObserver);
627 // Update thread will request the bitmap resource:
628 // Sets application.GetPlatform().mRequest
629 application.SendNotification(); // Run flush update queue
630 application.Render(1); // Process update messages
631 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
633 application.SendNotification(); // Send any event messages
634 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
635 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
637 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
638 DALI_TEST_CHECK( imageTicket );
639 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
640 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
643 /************************************************************
644 * FUNCTION UNDER TEST
645 ***********************************************************/
646 resourceClient.ReloadResource( ticket->GetId() );
647 /************************************************************
648 * Expected result - current load completes as usual, no reload requested
649 ************************************************************/
651 application.SendNotification(); // Flush update methods
653 // Reset call statistics - test that resource is not reloaded
654 application.GetPlatform().ResetTrace();
657 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
658 Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
659 Integration::ResourcePointer resourcePtr(bitmap); // reference it
661 // Set up platform abstraction to load it
664 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr);
666 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
668 application.GetPlatform().ResetTrace();
669 // load the cache, which will immediately have the loaded resource
670 application.Render(0);
672 // UpdateCache runs before ProcessMessages, so the loading resource completes before
673 // the reload request is handled.
674 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
675 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
677 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
678 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
679 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
680 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
682 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
683 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
685 // Trigger the event thread to process notify messages. Should then trigger the signals
686 // in the ticket observer
687 application.SendNotification();
689 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
690 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
691 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
693 // Check that the image ticket was updated with the image attributes
694 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
695 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
697 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
699 // Create a new resource - the image size could have changed in the meantime
700 req = application.GetPlatform().GetRequest();
701 Integration::ImageDataPtr bitmap2 = Integration::NewBitmapImageData( 120, 120, Pixel::RGBA8888 );
702 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
703 DALI_TEST_CHECK( req->GetId() == id );
704 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr2);
706 application.Render(0); // Process update messages / UpdateCache
708 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
709 bitmapData = resourceManager.GetBitmapMetadata(id);
710 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
711 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
712 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
713 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
715 application.SendNotification(); // Process event messages
717 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
719 // Not staged - no GL upload
720 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
722 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
723 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
724 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
725 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
731 int UtcDaliInternalSaveResource01(void)
733 TestApplication application;
734 tet_infoline("Testing SaveResource() with valid id, and valid filename");
736 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
738 Dali::ModelData modelData = BuildTreeModel();
739 testTicketObserver.Reset();
741 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
742 ticket->AddObserver(testTicketObserver);
744 // First, load a model resource
745 application.SendNotification(); // Flush update messages
746 application.Render(); // Process resource request
747 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
748 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
749 Integration::ResourcePointer resourcePtr(&modelDataImpl);
751 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
752 application.Render(); // Process LoadComplete
753 application.SendNotification(); // Process event messages
754 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
757 resourceClient.SaveResource( ticket, "model.dali-bin" );
758 application.SendNotification(); // Flush update messages
759 application.Render(); // Process save resource request
761 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
762 req = application.GetPlatform().GetRequest();
763 DALI_TEST_CHECK( req->GetType()->id == Integration::ResourceModel );
764 DALI_TEST_CHECK( req->GetPath().compare("model.dali-bin") == 0 );
766 // Set up success response
767 application.GetPlatform().SetResourceSaved(req->GetId(), req->GetType()->id);
768 application.Render(); // GetResources --> SaveComplete
769 application.SendNotification(); // Send event messages
771 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 1 );
772 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
778 int UtcDaliInternalSaveResource02(void)
780 TestApplication application;
781 tet_infoline("Testing SaveResource() with invalid id");
782 testTicketObserver.Reset();
784 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
786 Dali::ModelData modelData = BuildTreeModel();
788 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
789 ticket->AddObserver(testTicketObserver);
791 // First, load a model resource
792 application.SendNotification(); // Flush update messages
793 application.Render(); // Process resource request
794 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
795 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
796 Integration::ResourcePointer resourcePtr(&modelDataImpl);
797 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
798 application.Render(); // Process LoadComplete
799 application.SendNotification(); // Process event messages
800 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
801 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
803 Internal::ResourceTypePath typePath(Integration::ModelResourceType(), "");
804 Internal::ResourceTicketPtr aTicket = new Internal::ResourceTicket( testTicketLifetimeObserver, 2000, typePath );
807 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
808 } catch (DaliException& e)
810 // Tests that a negative test of an assertion succeeds
811 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
813 DALI_TEST_ASSERT(e, "mImpl->mTickets.find(ticket->GetId()) != mImpl->mTickets.end()", TEST_LOCATION );
816 application.SendNotification(); // Flush update messages
817 application.Render(); // Process save resource request
819 // Ensure no request sent to platform abstraction
820 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
821 req = application.GetPlatform().GetRequest();
822 DALI_TEST_CHECK ( req == NULL );
826 int UtcDaliInternalSaveResource03(void)
828 TestApplication application;
829 tet_infoline("Testing SaveResource() with invalid id");
830 testTicketObserver.Reset();
832 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
834 Dali::ModelData modelData = BuildTreeModel();
836 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
837 ticket->AddObserver(testTicketObserver);
839 // First, load a model resource
840 application.SendNotification(); // Flush update messages
841 application.Render(); // Process resource request
842 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
843 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
844 Integration::ResourcePointer resourcePtr(&modelDataImpl);
845 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
846 application.Render(); // Process LoadComplete
847 application.SendNotification(); // Process event messages
848 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
849 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
851 Internal::ResourceTicketPtr aTicket;
854 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
855 } catch (DaliException& e)
857 // Tests that a negative test of an assertion succeeds
858 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
860 DALI_TEST_EQUALS(e.mCondition, "ticket", TEST_LOCATION);
863 application.SendNotification(); // Flush update messages
864 application.Render(); // Process save resource request
866 // Ensure no request sent to platform abstraction
867 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
868 req = application.GetPlatform().GetRequest();
869 DALI_TEST_CHECK ( req == NULL );
874 int UtcDaliInternalSaveResource04(void)
876 TestApplication application;
877 tet_infoline("Testing SaveResource() with valid id, but invalid filename");
878 testTicketObserver.Reset();
880 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
882 // First, load a model resource
883 Internal::ResourceTicketPtr ticket = CheckLoadModel(application, "model.dae");
885 resourceClient.SaveResource( ticket, "model.dali-bin" );
886 application.SendNotification(); // Flush update messages
887 application.Render(); // Process save resource request
889 // Set up fail response
890 application.GetPlatform().SetResourceSaveFailed(ticket->GetId(), Integration::FailureInvalidPath );
891 application.Render(); // GetResources --> SaveFailed
892 application.SendNotification(); // Send event messages
894 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 0 );
895 DALI_TEST_CHECK( testTicketObserver.SaveFailedCalled() == 1 );
896 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
901 int UtcDaliInternalSaveResource05(void)
903 TestApplication application;
904 tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
905 testTicketObserver.Reset();
907 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
909 // First, load a bitmap resource
910 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
913 resourceClient.SaveResource( ticket, "bitmap.png" );
914 application.SendNotification(); // Flush update messages
915 application.Render(); // Process save resource request
917 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
921 int UtcDaliInternalRequestResourceTicket01(void)
923 TestApplication application;
924 tet_infoline("Testing RequestResourceTicket() with valid id");
926 testTicketObserver.Reset();
928 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
930 // First, load a bitmap resource
931 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
933 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
934 DALI_TEST_CHECK( newTicket );
935 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
936 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
940 int UtcDaliInternalRequestResourceTicket02(void)
942 TestApplication application;
943 tet_infoline("Testing RequestResourceTicket() with invalid id");
945 testTicketObserver.Reset();
947 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
949 // First, load a bitmap resource
950 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
952 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
953 DALI_TEST_CHECK( ! newTicket );
957 int UtcDaliInternalLoadShaderRequest01(void)
959 TestApplication application;
960 tet_infoline("Testing LoadShader() success");
961 testTicketObserver.Reset();
963 // Clear through all of the outstanding shader load requests from the default shader effect
964 std::vector< unsigned char > buffer;
965 for( int i=0; i<10; i++ )
967 buffer.push_back((unsigned char)i);
969 application.GetPlatform().SetLoadFileResult( true, buffer );
970 application.GetGlAbstraction().SetLinkStatus(1);
971 application.SendNotification(); // Flush update messages
972 application.Render(); // Process load shader request (immediately)
973 application.SendNotification();
974 application.Render();
975 application.SendNotification();
976 application.Render();
977 application.SendNotification();
979 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
981 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
982 std::string shaderBinaryFile("shader.bin");
983 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
984 DALI_TEST_CHECK( ticket );
986 application.GetPlatform().SetLoadFileResult( true, buffer );
987 application.GetGlAbstraction().EnableShaderCallTrace( true );
988 application.GetGlAbstraction().SetLinkStatus(1);
990 application.SendNotification(); // Flush update messages
991 application.Render(); // Process load shader request (immediately)
993 application.SendNotification();
994 application.Render();
996 application.SendNotification();
997 application.Render();
999 // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
1000 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1001 DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
1003 // Ensure no request sent to platform abstraction
1004 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1008 int UtcDaliInternalLoadShaderRequest02(void)
1010 TestApplication application;
1011 tet_infoline("Testing LoadShader() failure");
1012 testTicketObserver.Reset();
1014 // Clear through all of the outstanding shader load requests from the default shader effect
1015 std::vector< unsigned char > buffer;
1016 for( int i=0; i<10; i++ )
1018 buffer.push_back((unsigned char)i);
1020 application.GetPlatform().SetLoadFileResult( true, buffer );
1021 application.GetGlAbstraction().SetLinkStatus(1);
1022 application.SendNotification(); // Flush update messages
1023 application.Render(); // Process load shader request (immediately)
1024 application.SendNotification();
1025 application.Render();
1026 application.SendNotification();
1027 application.Render();
1028 application.SendNotification();
1030 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1031 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
1033 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
1034 std::string shaderBinaryFile("shader.bin");
1035 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
1036 ticket->AddObserver(testTicketObserver);
1038 ShaderEffect::GeometryHints hints = ShaderEffect::HINT_NONE;
1039 Internal::SceneGraph::Shader* sceneObject = new Internal::SceneGraph::Shader( hints );
1040 AddShaderMessage( updateManager, *sceneObject );
1042 size_t shaderHash=0;
1043 SetShaderProgramMessage( updateManager, *sceneObject, GEOMETRY_TYPE_IMAGE, Internal::SHADER_DEFAULT, ticket->GetId(), shaderHash );
1045 DALI_TEST_CHECK( ticket );
1048 DALI_TEST_CHECK(buffer.size() == 0);
1050 application.GetPlatform().SetLoadFileResult( true, buffer );
1051 application.GetGlAbstraction().ResetShaderCallStack();
1052 application.GetGlAbstraction().EnableShaderCallTrace( true );
1053 application.GetGlAbstraction().SetLinkStatus(1);
1054 application.GetGlAbstraction().SetProgramBinaryLength(20);
1055 application.GetPlatform().SetResourceSaved (ticket->GetId(), Integration::ResourceShader );
1057 application.SendNotification(); // Flush update messages
1058 application.Render(); // Process load shader request (immediately), add responses
1059 // to post process q
1060 application.Render(); // this update will process old post-process-q
1061 application.Render(); // this update will process new post-process-q
1062 application.SendNotification(); // Send save request to event thread
1063 application.Render(); // this update will process save request
1064 application.Render(); // this update will get SaveComplete
1065 application.SendNotification(); // Send save request response
1067 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1068 DALI_TEST_CHECK( shaderTrace.FindMethod("CompileShader") );
1070 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1071 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() );
1075 int UtcDaliInternalAllocateBitmapImage01(void)
1077 TestApplication application;
1078 tet_infoline("Testing AllocateBitmapImage()");
1079 testTicketObserver.Reset();
1081 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1082 Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1083 imageTicket->AddObserver( testTicketObserver );
1085 DALI_TEST_CHECK( imageTicket );
1086 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1087 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1088 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1089 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1091 application.SendNotification(); // Flush update queue
1092 application.Render(0); // Process message
1093 application.SendNotification(); // Send message to tickets
1095 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1096 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1097 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1098 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1099 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1101 Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1102 DALI_TEST_CHECK ( bitmap != NULL );
1103 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1104 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1105 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1106 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1107 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1111 int UtcDaliInternalAddBitmapImage01(void)
1113 TestApplication application;
1114 tet_infoline("Testing AddBitmap with reserved buffer()");
1115 testTicketObserver.Reset();
1116 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1117 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1118 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1120 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1121 DALI_TEST_CHECK( imageTicket );
1122 imageTicket->AddObserver( testTicketObserver );
1124 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1125 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1126 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1127 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1129 application.SendNotification(); // Flush update queue
1130 application.Render(0); // Process message
1131 application.SendNotification(); // Send message to tickets
1133 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1134 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1135 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1136 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1137 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1139 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1140 DALI_TEST_CHECK ( theBitmap != NULL );
1141 DALI_TEST_CHECK ( bitmap == theBitmap );
1142 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1143 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1144 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1145 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1146 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1150 int UtcDaliInternalAddBitmapImage02(void)
1152 TestApplication application;
1153 tet_infoline("Testing AddBitmap without reserved buffer()");
1154 testTicketObserver.Reset();
1155 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1156 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1158 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1159 DALI_TEST_CHECK( imageTicket );
1160 imageTicket->AddObserver( testTicketObserver );
1162 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1163 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1164 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1165 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1166 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1168 application.SendNotification(); // Flush update queue
1169 application.Render(0); // Process message
1170 application.SendNotification(); // Send message to tickets
1172 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1173 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1174 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1175 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1176 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1178 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1179 DALI_TEST_CHECK ( theBitmap != NULL );
1180 DALI_TEST_CHECK ( bitmap == theBitmap );
1181 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1182 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1183 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1184 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1185 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1187 // There is no way for the ticket's image attributes to be updated if the bitmap
1188 // reserves a buffer after ticket generation.
1189 // Probably not an issue - there is no public API in BufferImage to change the image size.
1194 int UtcDaliInternalAddBitmapImage03(void)
1196 TestApplication application;
1197 tet_infoline("Testing AddBitmap() with invalid bitmap");
1198 testTicketObserver.Reset();
1200 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1201 Internal::ImageTicketPtr imageTicket;
1202 bool exceptionRaised=false;
1205 imageTicket = resourceClient.AddBitmapImage( NULL );
1207 catch( DaliException& e )
1209 exceptionRaised = true;
1211 DALI_TEST_CHECK( exceptionRaised );
1212 DALI_TEST_CHECK( ! imageTicket );
1216 int UtcDaliInternalGetBitmapImage01(void)
1218 TestApplication application;
1219 tet_infoline("Testing GetBitmap() with valid ticket");
1220 testTicketObserver.Reset();
1222 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1223 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1224 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1225 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1227 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1228 DALI_TEST_CHECK ( theBitmap != NULL );
1229 DALI_TEST_CHECK ( bitmap == theBitmap );
1230 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1231 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1232 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1233 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1234 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1236 imageTicket->AddObserver( testTicketObserver );
1237 application.SendNotification(); // Flush update queue
1238 application.Render(0); // Process message
1239 application.SendNotification(); // Send message to tickets
1241 theBitmap = resourceClient.GetBitmap(imageTicket);
1242 DALI_TEST_CHECK ( theBitmap != NULL );
1243 DALI_TEST_CHECK ( bitmap == theBitmap );
1244 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1245 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1246 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1247 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1248 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1252 int UtcDaliInternalGetBitmapImage02(void)
1254 TestApplication application;
1255 tet_infoline("Testing GetBitmap() with invalid ticket");
1257 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1258 Internal::ImageTicketPtr imageTicket;
1259 Integration::Bitmap* theBitmap = NULL;
1260 bool exceptionRaised = false;
1263 theBitmap = resourceClient.GetBitmap(imageTicket);
1264 } catch (DaliException& e)
1266 exceptionRaised = true;
1268 DALI_TEST_CHECK( exceptionRaised );
1269 DALI_TEST_CHECK( ! theBitmap );
1273 int UtcDaliInternalGetBitmapImage03(void)
1275 TestApplication application;
1276 tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1278 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1279 Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1281 Integration::Bitmap* theBitmap = NULL;
1282 theBitmap = resourceClient.GetBitmap(imageTicket);
1283 DALI_TEST_CHECK( ! theBitmap );
1285 theBitmap = resourceClient.GetBitmap(modelTicket);
1286 DALI_TEST_CHECK( ! theBitmap );
1290 int UtcDaliInternalAllocateTexture01(void)
1292 TestApplication application;
1293 tet_infoline("Testing AllocateTexture()");
1294 testTicketObserver.Reset();
1296 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1297 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1298 resourceTicket->AddObserver( testTicketObserver );
1300 DALI_TEST_CHECK( resourceTicket );
1301 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1302 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1304 application.SendNotification(); // Flush update queue
1305 application.Render(0); // Process message
1306 application.SendNotification(); // Send message to tickets
1308 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1309 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1313 int UtcDaliInternalAddNativeImage(void)
1315 TestApplication application;
1316 tet_infoline("Testing AddNativeImage()");
1318 testTicketObserver.Reset();
1319 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1320 Internal::ResourceTicketPtr ticket;
1321 Internal::ImageTicketPtr imageTicket;
1322 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1323 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1324 ticket = resourceClient.AddNativeImage( *nativeImage );
1325 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1326 DALI_TEST_CHECK( imageTicket );
1327 imageTicket->AddObserver( testTicketObserver );
1330 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1331 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1332 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1333 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1335 application.SendNotification(); // Flush update queue
1336 application.Render(0); // Process message
1337 application.SendNotification(); // Send message to tickets
1339 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1340 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1341 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1342 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1344 Integration::Bitmap* theBitmap = NULL;
1345 theBitmap = resourceClient.GetBitmap(imageTicket);
1347 DALI_TEST_CHECK ( theBitmap == NULL );
1351 int UtcDaliInternalAddFrameBufferImage(void)
1353 TestApplication application;
1354 tet_infoline("Testing AddFrameBufferImage()");
1356 testTicketObserver.Reset();
1357 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1358 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1359 DALI_TEST_CHECK( imageTicket );
1360 imageTicket->AddObserver( testTicketObserver );
1362 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1363 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1364 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1365 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1366 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1368 application.SendNotification(); // Flush update queue
1369 application.Render(0); // Process message
1370 application.SendNotification(); // Send message to tickets
1372 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1373 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1374 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1375 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1376 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1378 Integration::Bitmap* theBitmap = NULL;
1379 theBitmap = resourceClient.GetBitmap(imageTicket);
1380 DALI_TEST_CHECK ( theBitmap == NULL );
1384 int UtcDaliInternalAllocateMesh01(void)
1386 TestApplication application;
1387 tet_infoline("Testing AllocateMesh() with vald mesh data");
1389 MeshData publicMeshData;
1390 MeshData::VertexContainer vertices;
1391 MeshData::FaceIndices faces;
1392 BoneContainer bones;
1393 ConstructVertices(vertices, 60);
1394 ConstructFaces(vertices, faces);
1395 Material customMaterial = ConstructMaterial();
1396 publicMeshData.SetData(vertices, faces, bones, customMaterial);
1397 publicMeshData.SetHasNormals(true);
1398 publicMeshData.SetHasTextureCoords(true);
1400 testTicketObserver.Reset();
1401 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1402 Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, true, true ) );
1403 Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1404 DALI_TEST_CHECK( meshTicket );
1405 meshTicket->AddObserver( testTicketObserver );
1407 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1409 application.SendNotification(); // Flush update queue
1410 application.Render(0); // Process message
1411 application.SendNotification(); // Send message to tickets
1413 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );