2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
25 // Internal headers are allowed here
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/update/resources/bitmap-metadata.h>
29 #include <dali/internal/update/resources/resource-manager.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/event/resources/resource-client.h>
32 #include <dali/internal/event/resources/resource-ticket.h>
33 #include <dali/internal/event/resources/image-ticket.h>
34 #include <dali/internal/event/resources/resource-ticket-observer.h>
35 #include <dali/internal/event/images/image-impl.h>
36 #include <dali/internal/event/modeling/model-data-impl.h>
37 #include <dali/integration-api/resource-cache.h>
38 #include <dali/internal/render/gl-resources/texture-declarations.h>
39 #include <dali/internal/render/shaders/shader.h>
40 #include <dali/internal/common/owner-pointer.h>
41 #include <dali/public-api/shader-effects/shader-effect.h>
45 #include <mesh-builder.h>
50 class TestTicketObserver : public Internal::ResourceTicketObserver
54 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
55 mSavingFailedCalled(0), mSavingSucceededCalled(0),
59 int LoadFailedCalled() {
60 tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
61 return mLoadingFailedCalled;
63 int LoadSucceededCalled() {
64 tet_printf("TicketObserver: LoadingSucceeded() called %d times", mLoadingSucceededCalled);
65 return mLoadingSucceededCalled;
67 int SaveFailedCalled() {
68 tet_printf("TicketObserver: SavingFailed() called %d times", mSavingFailedCalled);
69 return mSavingFailedCalled;
71 int SaveSucceededCalled() {
72 tet_printf("TicketObserver: SavingSucceeded() called %d times", mSavingSucceededCalled);
73 return mSavingSucceededCalled;
76 tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
77 return mUploadedCount;
80 mLoadingFailedCalled = 0;
81 mLoadingSucceededCalled = 0;
82 mSavingFailedCalled = 0;
83 mSavingSucceededCalled = 0;
87 public: // From ResourceTicketObserver
88 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
89 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
90 virtual void ResourceSavingFailed(const Internal::ResourceTicket& ticket) {mSavingFailedCalled++;}
91 virtual void ResourceSavingSucceeded(const Internal::ResourceTicket& ticket) {mSavingSucceededCalled++;}
92 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
95 int mLoadingFailedCalled;
96 int mLoadingSucceededCalled;
97 int mSavingFailedCalled;
98 int mSavingSucceededCalled;
102 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
105 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
107 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
108 { resourceTicketDiscarded = true; }
110 void Reset() { resourceTicketDiscarded = false; }
111 bool resourceTicketDiscarded;
114 static TestTicketObserver testTicketObserver;
115 static TestTicketLifetimeObserver testTicketLifetimeObserver;
118 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
120 Internal::ImagePtr image = Internal::Image::New(name, Dali::ImageAttributes::DEFAULT_ATTRIBUTES );
121 application.SendNotification(); // Flush update messages
122 application.Render(); // Process resource request
123 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
124 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
125 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
126 Integration::ResourcePointer resourcePtr(bitmap); // reference it
127 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
128 application.Render(); // Process LoadComplete
129 application.SendNotification(); // Process event messages
130 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
132 application.GetPlatform().ResetTrace();
137 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
139 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
140 ImageAttributes attr;
141 Integration::BitmapResourceType bitmapRequest(attr);
142 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
143 ticket->AddObserver(testTicketObserver);
144 application.SendNotification(); // Flush update messages
145 application.Render(); // Process resource request
146 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
147 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
148 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
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::BitmapResourceType bitmapRequest (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::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
238 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
239 Integration::ResourcePointer resourcePtr(bitmap); // reference it
241 // Set up platform abstraction to load it
243 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
245 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
247 // load the cache, which will immediately have the loaded resource
248 application.Render(0);
250 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
252 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
253 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
254 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
255 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
257 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
258 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
260 // Trigger the event thread to process notify messages. Should then trigger the signals
261 // in the ticket observer
262 application.SendNotification();
264 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
265 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
267 // Check that the image ticket was updated with the image attributes
268 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
269 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
272 application.SendNotification(); // Flush update queue (with ticket discarded message
273 application.Render(1); // Process update messages
274 application.SendNotification(); // Send event notifications
275 application.Render(1); // Process update messages
277 // Resource should have been discarded.
278 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
279 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
281 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
282 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
286 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
287 int UtcDaliInternalRequestResourceBitmapRequests02(void)
289 TestApplication application; // Reset all test adapter return codes
291 tet_infoline("Testing bitmap request ticket discard before load complete");
293 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
294 ImageAttributes attr;
295 Integration::BitmapResourceType bitmapRequest (attr);
296 Internal::ResourceId id(0);
298 testTicketObserver.Reset();
301 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
302 /************************************************************
303 * FUNCTION UNDER TEST
304 ***********************************************************/
305 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
306 ticket->AddObserver(testTicketObserver);
307 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
308 DALI_TEST_CHECK( imageTicket );
309 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
310 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
312 // Update thread will request the bitmap resource:
313 // Sets application.GetPlatform().mRequest
314 application.SendNotification(); // Run flush update queue
315 application.Render(1);
316 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
317 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
320 application.SendNotification(); // Should produce no messages
321 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
322 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
324 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
326 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
327 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
328 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
332 // Ensure ticket discarded message is sent to update thread
333 application.SendNotification(); // Flush update queue
334 application.Render(0); // Process update messages
336 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
337 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
339 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
341 // Trigger the event thread to process notify messages. Should then trigger the signals
342 // in the ticket observer
343 application.SendNotification();
345 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
346 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
350 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
351 int UtcDaliInternalRequestResourceBitmapRequests03(void)
353 TestApplication application; // Reset all test adapter return codes
355 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
357 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
358 ImageAttributes attr;
359 Integration::BitmapResourceType bitmapRequest (attr);
360 Internal::ResourceId id(0);
362 testTicketObserver.Reset();
363 { // Scope lifetime of ticket
364 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
366 /************************************************************
367 * FUNCTION UNDER TEST
368 ***********************************************************/
369 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
370 ticket->AddObserver(testTicketObserver);
371 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
372 DALI_TEST_CHECK( imageTicket );
373 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
374 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
376 // Update thread will request the bitmap resource:
377 // Sets application.GetPlatform().mRequest
378 application.SendNotification(); // Run flush update queue
379 application.Render(1); // process update messages
380 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
381 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
383 application.SendNotification(); // Should produce no messages
384 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
385 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
387 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
389 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
391 application.Render(0); // Get failed result
392 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
393 application.SendNotification(); // send failed
394 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
395 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
397 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
398 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
399 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
401 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
404 application.Render(0); // Send DiscardTicket
405 application.SendNotification();
407 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
413 // Load a bitmap resource successfully, then reload it
414 int UtcDaliInternalRequestReloadBitmapRequests01(void)
416 TestApplication application; // Reset all test adapter return codes
418 tet_infoline("Testing bitmap reload after successful load");
420 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
421 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
423 Internal::ResourceId id(0);
424 testTicketObserver.Reset();
427 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
428 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
429 id = ticket->GetId();
431 // Reset call statistics - test that resource is reloaded
432 application.GetPlatform().ResetTrace();
434 /************************************************************
435 * FUNCTION UNDER TEST
436 ***********************************************************/
437 resourceClient.ReloadResource( ticket->GetId() );
439 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
440 application.SendNotification(); // Flush update messages
441 application.Render(0); // Process update messages
442 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
443 application.SendNotification(); // Process event messages
445 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
446 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
447 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
448 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
450 // Create a new resource - the image size could have changed in the meantime
451 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
452 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
453 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
454 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
455 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
456 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
458 application.Render(0); // Process update messages / UpdateCache
459 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
461 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
462 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
463 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
464 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
466 // Ticket can't have been updated yet - it should still have old values
467 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
468 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
470 application.SendNotification(); // Process event messages
471 application.Render(0); // Process update messages / UpdateCache
472 application.SendNotification(); // Process event messages
474 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
475 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
476 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
477 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
478 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
482 application.SendNotification(); // Flush update queue (with ticket discarded message
483 application.Render(1); // Process update messages
484 application.SendNotification(); // Send event notifications
485 application.Render(1); // Process update messages
487 // Resource should have been discarded.
488 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
489 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
491 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
492 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
493 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
498 int UtcDaliInternalRequestReloadBitmapRequests02(void)
500 TestApplication application; // Reset all test adapter return codes
502 tet_infoline("Testing bitmap reload during first load");
504 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
505 ImageAttributes attr;
506 Integration::BitmapResourceType bitmapRequest (attr);
507 Internal::ResourceId id(0);
509 testTicketObserver.Reset();
512 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
513 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
514 ticket->AddObserver(testTicketObserver);
516 // Update thread will request the bitmap resource:
517 // Sets application.GetPlatform().mRequest
518 application.SendNotification(); // Run flush update queue
519 application.Render(1); // Process update messages
520 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
522 application.SendNotification(); // Send any event messages
523 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
524 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
526 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
527 DALI_TEST_CHECK( imageTicket );
528 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
529 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
532 /************************************************************
533 * FUNCTION UNDER TEST
534 ***********************************************************/
535 resourceClient.ReloadResource( ticket->GetId() );
536 /************************************************************
537 * Expected result - current load completes as usual, no reload requested
538 ************************************************************/
540 application.SendNotification(); // Flush update methods
542 // Reset call statistics - test that resource is not reloaded
543 application.GetPlatform().ResetTrace();
545 application.Render(0); // Process reload message (nothing for UpdateCache yet)
547 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
548 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
550 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
551 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
552 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
553 Integration::ResourcePointer resourcePtr(bitmap); // reference it
555 // Set up platform abstraction to load it
558 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
560 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
562 application.GetPlatform().ResetTrace();
563 // load the cache, which will immediately have the loaded resource
564 application.Render(0);
565 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
566 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
567 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
568 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
569 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
571 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
572 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
574 // Trigger the event thread to process notify messages. Should then trigger the signals
575 // in the ticket observer
576 application.SendNotification();
578 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
579 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
580 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
582 // Check that the image ticket was updated with the image attributes
583 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
584 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
586 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
588 application.SendNotification(); // Flush update messages
589 application.Render(0); // Process update messages
591 // There should be no reload
592 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
593 application.SendNotification(); // Process event messages
595 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
596 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
597 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
598 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
600 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
601 bitmapData = resourceManager.GetBitmapMetadata(id);
602 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
603 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
604 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
605 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
612 int UtcDaliInternalRequestReloadBitmapRequests03(void)
614 TestApplication application; // Reset all test adapter return codes
616 tet_infoline("Testing bitmap reload at end of first load");
618 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
619 ImageAttributes attr;
620 Integration::BitmapResourceType bitmapRequest (attr);
621 Internal::ResourceId id(0);
623 testTicketObserver.Reset();
626 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
627 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
628 ticket->AddObserver(testTicketObserver);
630 // Update thread will request the bitmap resource:
631 // Sets application.GetPlatform().mRequest
632 application.SendNotification(); // Run flush update queue
633 application.Render(1); // Process update messages
634 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
636 application.SendNotification(); // Send any event messages
637 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
638 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
640 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
641 DALI_TEST_CHECK( imageTicket );
642 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
643 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
646 /************************************************************
647 * FUNCTION UNDER TEST
648 ***********************************************************/
649 resourceClient.ReloadResource( ticket->GetId() );
650 /************************************************************
651 * Expected result - current load completes as usual, no reload requested
652 ************************************************************/
654 application.SendNotification(); // Flush update methods
656 // Reset call statistics - test that resource is not reloaded
657 application.GetPlatform().ResetTrace();
660 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
661 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
662 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
663 Integration::ResourcePointer resourcePtr(bitmap); // reference it
665 // Set up platform abstraction to load it
668 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
670 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
672 application.GetPlatform().ResetTrace();
673 // load the cache, which will immediately have the loaded resource
674 application.Render(0);
676 // UpdateCache runs before ProcessMessages, so the loading resource completes before
677 // the reload request is handled.
678 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
679 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
681 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
682 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
683 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
684 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
686 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
687 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
689 // Trigger the event thread to process notify messages. Should then trigger the signals
690 // in the ticket observer
691 application.SendNotification();
693 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
694 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
695 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
697 // Check that the image ticket was updated with the image attributes
698 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
699 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
701 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
703 // Create a new resource - the image size could have changed in the meantime
704 req = application.GetPlatform().GetRequest();
705 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
706 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
707 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
708 DALI_TEST_CHECK( req->GetId() == id );
709 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
711 application.Render(0); // Process update messages / UpdateCache
713 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
714 bitmapData = resourceManager.GetBitmapMetadata(id);
715 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
716 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
717 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
718 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
720 application.SendNotification(); // Process event messages
722 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
724 // Not staged - no GL upload
725 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
727 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
728 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
729 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
730 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
736 int UtcDaliInternalSaveResource01(void)
738 TestApplication application;
739 tet_infoline("Testing SaveResource() with valid id, and valid filename");
741 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
743 Dali::ModelData modelData = BuildTreeModel();
744 testTicketObserver.Reset();
746 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
747 ticket->AddObserver(testTicketObserver);
749 // First, load a model resource
750 application.SendNotification(); // Flush update messages
751 application.Render(); // Process resource request
752 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
753 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
754 Integration::ResourcePointer resourcePtr(&modelDataImpl);
756 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
757 application.Render(); // Process LoadComplete
758 application.SendNotification(); // Process event messages
759 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
762 resourceClient.SaveResource( ticket, "model.dali-bin" );
763 application.SendNotification(); // Flush update messages
764 application.Render(); // Process save resource request
766 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
767 req = application.GetPlatform().GetRequest();
768 DALI_TEST_CHECK( req->GetType()->id == Integration::ResourceModel );
769 DALI_TEST_CHECK( req->GetPath().compare("model.dali-bin") == 0 );
771 // Set up success response
772 application.GetPlatform().SetResourceSaved(req->GetId(), req->GetType()->id);
773 application.Render(); // GetResources --> SaveComplete
774 application.SendNotification(); // Send event messages
776 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 1 );
777 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
783 int UtcDaliInternalSaveResource02(void)
785 TestApplication application;
786 tet_infoline("Testing SaveResource() with invalid id");
787 testTicketObserver.Reset();
789 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
791 Dali::ModelData modelData = BuildTreeModel();
793 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
794 ticket->AddObserver(testTicketObserver);
796 // First, load a model resource
797 application.SendNotification(); // Flush update messages
798 application.Render(); // Process resource request
799 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
800 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
801 Integration::ResourcePointer resourcePtr(&modelDataImpl);
802 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
803 application.Render(); // Process LoadComplete
804 application.SendNotification(); // Process event messages
805 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
806 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
808 Internal::ResourceTypePath typePath(Integration::ModelResourceType(), "");
809 Internal::ResourceTicketPtr aTicket = new Internal::ResourceTicket( testTicketLifetimeObserver, 2000, typePath );
812 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
814 catch (DaliException& e)
816 // Tests that a negative test of an assertion succeeds
817 DALI_TEST_PRINT_ASSERT( e );
818 DALI_TEST_ASSERT(e, "mImpl->mTickets.find(ticket->GetId()) != mImpl->mTickets.end()", TEST_LOCATION );
821 application.SendNotification(); // Flush update messages
822 application.Render(); // Process save resource request
824 // Ensure no request sent to platform abstraction
825 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
826 req = application.GetPlatform().GetRequest();
827 DALI_TEST_CHECK ( req == NULL );
831 int UtcDaliInternalSaveResource03(void)
833 TestApplication application;
834 tet_infoline("Testing SaveResource() with invalid id");
835 testTicketObserver.Reset();
837 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
839 Dali::ModelData modelData = BuildTreeModel();
841 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
842 ticket->AddObserver(testTicketObserver);
844 // First, load a model resource
845 application.SendNotification(); // Flush update messages
846 application.Render(); // Process resource request
847 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
848 Internal::ModelData& modelDataImpl = GetImplementation(modelData);
849 Integration::ResourcePointer resourcePtr(&modelDataImpl);
850 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
851 application.Render(); // Process LoadComplete
852 application.SendNotification(); // Process event messages
853 DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
854 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
856 Internal::ResourceTicketPtr aTicket;
859 resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
861 catch (DaliException& e)
863 // Tests that a negative test of an assertion succeeds
864 DALI_TEST_PRINT_ASSERT( e );
865 DALI_TEST_EQUALS(e.condition, "ticket", TEST_LOCATION);
868 application.SendNotification(); // Flush update messages
869 application.Render(); // Process save resource request
871 // Ensure no request sent to platform abstraction
872 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
873 req = application.GetPlatform().GetRequest();
874 DALI_TEST_CHECK ( req == NULL );
879 int UtcDaliInternalSaveResource04(void)
881 TestApplication application;
882 tet_infoline("Testing SaveResource() with valid id, but invalid filename");
883 testTicketObserver.Reset();
885 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
887 // First, load a model resource
888 Internal::ResourceTicketPtr ticket = CheckLoadModel(application, "model.dae");
890 resourceClient.SaveResource( ticket, "model.dali-bin" );
891 application.SendNotification(); // Flush update messages
892 application.Render(); // Process save resource request
894 // Set up fail response
895 application.GetPlatform().SetResourceSaveFailed(ticket->GetId(), Integration::FailureInvalidPath );
896 application.Render(); // GetResources --> SaveFailed
897 application.SendNotification(); // Send event messages
899 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 0 );
900 DALI_TEST_CHECK( testTicketObserver.SaveFailedCalled() == 1 );
901 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
906 int UtcDaliInternalSaveResource05(void)
908 TestApplication application;
909 tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
910 testTicketObserver.Reset();
912 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
914 // First, load a bitmap resource
915 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
918 resourceClient.SaveResource( ticket, "bitmap.png" );
919 application.SendNotification(); // Flush update messages
920 application.Render(); // Process save resource request
922 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
926 int UtcDaliInternalRequestResourceTicket01(void)
928 TestApplication application;
929 tet_infoline("Testing RequestResourceTicket() with valid id");
931 testTicketObserver.Reset();
933 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
935 // First, load a bitmap resource
936 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
938 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
939 DALI_TEST_CHECK( newTicket );
940 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
941 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
945 int UtcDaliInternalRequestResourceTicket02(void)
947 TestApplication application;
948 tet_infoline("Testing RequestResourceTicket() with invalid id");
950 testTicketObserver.Reset();
952 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
954 // First, load a bitmap resource
955 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
957 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
958 DALI_TEST_CHECK( ! newTicket );
962 int UtcDaliInternalLoadShaderRequest01(void)
964 TestApplication application;
965 tet_infoline("Testing LoadShader() success");
966 testTicketObserver.Reset();
968 // Clear through all of the outstanding shader load requests from the default shader effect
969 std::vector< unsigned char > buffer;
970 for( int i=0; i<10; i++ )
972 buffer.push_back((unsigned char)i);
974 application.GetPlatform().SetLoadFileResult( true, buffer );
975 application.GetGlAbstraction().SetLinkStatus(1);
976 application.SendNotification(); // Flush update messages
977 application.Render(); // Process load shader request (immediately)
978 application.SendNotification();
979 application.Render();
980 application.SendNotification();
981 application.Render();
982 application.SendNotification();
984 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
986 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
987 std::string shaderBinaryFile("shader.bin");
988 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
989 DALI_TEST_CHECK( ticket );
991 application.GetPlatform().SetLoadFileResult( true, buffer );
992 application.GetGlAbstraction().EnableShaderCallTrace( true );
993 application.GetGlAbstraction().SetLinkStatus(1);
995 application.SendNotification(); // Flush update messages
996 application.Render(); // Process load shader request (immediately)
998 application.SendNotification();
999 application.Render();
1001 application.SendNotification();
1002 application.Render();
1004 // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
1005 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1006 DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
1008 // Ensure no request sent to platform abstraction
1009 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1013 int UtcDaliInternalAllocateBitmapImage01(void)
1015 TestApplication application;
1016 tet_infoline("Testing AllocateBitmapImage()");
1017 testTicketObserver.Reset();
1019 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1020 Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1021 imageTicket->AddObserver( testTicketObserver );
1023 DALI_TEST_CHECK( imageTicket );
1024 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1025 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1026 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1027 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1029 application.SendNotification(); // Flush update queue
1030 application.Render(0); // Process message
1031 application.SendNotification(); // Send message to tickets
1033 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1034 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1035 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1036 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1037 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1039 Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1040 DALI_TEST_CHECK ( bitmap != NULL );
1041 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1042 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1043 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1044 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1045 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1049 int UtcDaliInternalAddBitmapImage01(void)
1051 TestApplication application;
1052 tet_infoline("Testing AddBitmap with reserved buffer()");
1053 testTicketObserver.Reset();
1054 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1055 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1056 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1058 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1059 DALI_TEST_CHECK( imageTicket );
1060 imageTicket->AddObserver( testTicketObserver );
1062 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1063 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1064 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1065 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1067 application.SendNotification(); // Flush update queue
1068 application.Render(0); // Process message
1069 application.SendNotification(); // Send message to tickets
1071 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1072 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1073 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1074 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1075 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1077 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1078 DALI_TEST_CHECK ( theBitmap != NULL );
1079 DALI_TEST_CHECK ( bitmap == theBitmap );
1080 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1081 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1082 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1083 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1084 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1088 int UtcDaliInternalAddBitmapImage02(void)
1090 TestApplication application;
1091 tet_infoline("Testing AddBitmap without reserved buffer()");
1092 testTicketObserver.Reset();
1093 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1094 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1096 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1097 DALI_TEST_CHECK( imageTicket );
1098 imageTicket->AddObserver( testTicketObserver );
1100 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1101 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1102 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1103 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1104 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1106 application.SendNotification(); // Flush update queue
1107 application.Render(0); // Process message
1108 application.SendNotification(); // Send message to tickets
1110 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1111 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1112 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1113 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1114 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1116 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1117 DALI_TEST_CHECK ( theBitmap != NULL );
1118 DALI_TEST_CHECK ( bitmap == theBitmap );
1119 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1120 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1121 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1122 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1123 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1125 // There is no way for the ticket's image attributes to be updated if the bitmap
1126 // reserves a buffer after ticket generation.
1127 // Probably not an issue - there is no public API in BufferImage to change the image size.
1132 int UtcDaliInternalAddBitmapImage03(void)
1134 TestApplication application;
1135 tet_infoline("Testing AddBitmap() with invalid bitmap");
1136 testTicketObserver.Reset();
1138 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1139 Internal::ImageTicketPtr imageTicket;
1140 bool exceptionRaised=false;
1143 imageTicket = resourceClient.AddBitmapImage( NULL );
1145 catch( DaliException& e )
1147 exceptionRaised = true;
1149 DALI_TEST_CHECK( exceptionRaised );
1150 DALI_TEST_CHECK( ! imageTicket );
1154 int UtcDaliInternalGetBitmapImage01(void)
1156 TestApplication application;
1157 tet_infoline("Testing GetBitmap() with valid ticket");
1158 testTicketObserver.Reset();
1160 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1161 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
1162 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1163 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1165 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1166 DALI_TEST_CHECK ( theBitmap != NULL );
1167 DALI_TEST_CHECK ( bitmap == theBitmap );
1168 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1169 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1170 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1171 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1172 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1174 imageTicket->AddObserver( testTicketObserver );
1175 application.SendNotification(); // Flush update queue
1176 application.Render(0); // Process message
1177 application.SendNotification(); // Send message to tickets
1179 theBitmap = resourceClient.GetBitmap(imageTicket);
1180 DALI_TEST_CHECK ( theBitmap != NULL );
1181 DALI_TEST_CHECK ( bitmap == theBitmap );
1182 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1183 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1184 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1185 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1186 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1190 int UtcDaliInternalGetBitmapImage02(void)
1192 TestApplication application;
1193 tet_infoline("Testing GetBitmap() with invalid ticket");
1195 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1196 Internal::ImageTicketPtr imageTicket;
1197 Integration::Bitmap* theBitmap = NULL;
1198 bool exceptionRaised = false;
1201 theBitmap = resourceClient.GetBitmap(imageTicket);
1202 } catch (DaliException& e)
1204 exceptionRaised = true;
1206 DALI_TEST_CHECK( exceptionRaised );
1207 DALI_TEST_CHECK( ! theBitmap );
1211 int UtcDaliInternalGetBitmapImage03(void)
1213 TestApplication application;
1214 tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1216 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1217 Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1219 Integration::Bitmap* theBitmap = NULL;
1220 theBitmap = resourceClient.GetBitmap(imageTicket);
1221 DALI_TEST_CHECK( ! theBitmap );
1223 theBitmap = resourceClient.GetBitmap(modelTicket);
1224 DALI_TEST_CHECK( ! theBitmap );
1228 int UtcDaliInternalAllocateTexture01(void)
1230 TestApplication application;
1231 tet_infoline("Testing AllocateTexture()");
1232 testTicketObserver.Reset();
1234 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1235 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1236 resourceTicket->AddObserver( testTicketObserver );
1238 DALI_TEST_CHECK( resourceTicket );
1239 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1240 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1242 application.SendNotification(); // Flush update queue
1243 application.Render(0); // Process message
1244 application.SendNotification(); // Send message to tickets
1246 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1247 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1251 int UtcDaliInternalAddNativeImage(void)
1253 TestApplication application;
1254 tet_infoline("Testing AddNativeImage()");
1256 testTicketObserver.Reset();
1257 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1258 Internal::ResourceTicketPtr ticket;
1259 Internal::ImageTicketPtr imageTicket;
1260 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1261 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1262 ticket = resourceClient.AddNativeImage( *nativeImage );
1263 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1264 DALI_TEST_CHECK( imageTicket );
1265 imageTicket->AddObserver( testTicketObserver );
1268 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1269 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1270 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1271 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1273 application.SendNotification(); // Flush update queue
1274 application.Render(0); // Process message
1275 application.SendNotification(); // Send message to tickets
1277 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1278 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1279 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1280 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1282 Integration::Bitmap* theBitmap = NULL;
1283 theBitmap = resourceClient.GetBitmap(imageTicket);
1285 DALI_TEST_CHECK ( theBitmap == NULL );
1289 int UtcDaliInternalAddFrameBufferImage(void)
1291 TestApplication application;
1292 tet_infoline("Testing AddFrameBufferImage()");
1294 testTicketObserver.Reset();
1295 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1296 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1297 DALI_TEST_CHECK( imageTicket );
1298 imageTicket->AddObserver( testTicketObserver );
1300 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1301 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1302 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1303 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1304 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1306 application.SendNotification(); // Flush update queue
1307 application.Render(0); // Process message
1308 application.SendNotification(); // Send message to tickets
1310 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1311 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1312 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1313 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1314 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1316 Integration::Bitmap* theBitmap = NULL;
1317 theBitmap = resourceClient.GetBitmap(imageTicket);
1318 DALI_TEST_CHECK ( theBitmap == NULL );
1322 int UtcDaliInternalAllocateMesh01(void)
1324 TestApplication application;
1325 tet_infoline("Testing AllocateMesh() with vald mesh data");
1327 MeshData publicMeshData;
1328 MeshData::VertexContainer vertices;
1329 MeshData::FaceIndices faces;
1330 BoneContainer bones;
1331 ConstructVertices(vertices, 60);
1332 ConstructFaces(vertices, faces);
1333 Material customMaterial = ConstructMaterial();
1334 publicMeshData.SetData(vertices, faces, bones, customMaterial);
1335 publicMeshData.SetHasNormals(true);
1336 publicMeshData.SetHasTextureCoords(true);
1338 testTicketObserver.Reset();
1339 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1340 Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, ResourcePolicy::DISCARD, true ) );
1341 Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1342 DALI_TEST_CHECK( meshTicket );
1343 meshTicket->AddObserver( testTicketObserver );
1345 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1347 application.SendNotification(); // Flush update queue
1348 application.Render(0); // Process message
1349 application.SendNotification(); // Send message to tickets
1351 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );