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/dali.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);
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, false );
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, false );
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, false );
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, false );
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, false );
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, false );
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, false );
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!
813 } catch (DaliException& e)
815 // Tests that a negative test of an assertion succeeds
816 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
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!
860 } catch (DaliException& e)
862 // Tests that a negative test of an assertion succeeds
863 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
865 DALI_TEST_EQUALS(e.mCondition, "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 UtcDaliInternalLoadShaderRequest02(void)
1015 TestApplication application;
1016 tet_infoline("Testing LoadShader() failure");
1017 testTicketObserver.Reset();
1019 // Clear through all of the outstanding shader load requests from the default shader effect
1020 std::vector< unsigned char > buffer;
1021 for( int i=0; i<10; i++ )
1023 buffer.push_back((unsigned char)i);
1025 application.GetPlatform().SetLoadFileResult( true, buffer );
1026 application.GetGlAbstraction().SetLinkStatus(1);
1027 application.SendNotification(); // Flush update messages
1028 application.Render(); // Process load shader request (immediately)
1029 application.SendNotification();
1030 application.Render();
1031 application.SendNotification();
1032 application.Render();
1033 application.SendNotification();
1035 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1036 Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
1038 Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
1039 std::string shaderBinaryFile("shader.bin");
1040 Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
1041 ticket->AddObserver(testTicketObserver);
1043 ShaderEffect::GeometryHints hints = ShaderEffect::HINT_NONE;
1044 Internal::SceneGraph::Shader* sceneObject = new Internal::SceneGraph::Shader( hints );
1045 AddShaderMessage( updateManager, *sceneObject );
1047 size_t shaderHash=0;
1048 SetShaderProgramMessage( updateManager, *sceneObject, GEOMETRY_TYPE_IMAGE, Internal::SHADER_DEFAULT, ticket->GetId(), shaderHash );
1050 DALI_TEST_CHECK( ticket );
1053 DALI_TEST_CHECK(buffer.size() == 0);
1055 application.GetPlatform().SetLoadFileResult( true, buffer );
1056 application.GetGlAbstraction().ResetShaderCallStack();
1057 application.GetGlAbstraction().EnableShaderCallTrace( true );
1058 application.GetGlAbstraction().SetLinkStatus(1);
1059 application.GetGlAbstraction().SetProgramBinaryLength(20);
1060 application.GetPlatform().SetResourceSaved (ticket->GetId(), Integration::ResourceShader );
1062 application.SendNotification(); // Flush update messages
1063 application.Render(); // Process load shader request (immediately), add responses
1064 // to post process q
1065 application.Render(); // this update will process old post-process-q
1066 application.Render(); // this update will process new post-process-q
1067 application.SendNotification(); // Send save request to event thread
1068 application.Render(); // this update will process save request
1069 application.Render(); // this update will get SaveComplete
1070 application.SendNotification(); // Send save request response
1072 TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1073 DALI_TEST_CHECK( shaderTrace.FindMethod("CompileShader") );
1075 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1076 DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() );
1080 int UtcDaliInternalAllocateBitmapImage01(void)
1082 TestApplication application;
1083 tet_infoline("Testing AllocateBitmapImage()");
1084 testTicketObserver.Reset();
1086 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1087 Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1088 imageTicket->AddObserver( testTicketObserver );
1090 DALI_TEST_CHECK( imageTicket );
1091 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1092 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1093 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1094 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1096 application.SendNotification(); // Flush update queue
1097 application.Render(0); // Process message
1098 application.SendNotification(); // Send message to tickets
1100 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1101 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1102 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1103 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1104 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1106 Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1107 DALI_TEST_CHECK ( bitmap != NULL );
1108 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1109 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1110 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1111 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1112 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1116 int UtcDaliInternalAddBitmapImage01(void)
1118 TestApplication application;
1119 tet_infoline("Testing AddBitmap with reserved buffer()");
1120 testTicketObserver.Reset();
1121 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1122 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1123 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1125 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1126 DALI_TEST_CHECK( imageTicket );
1127 imageTicket->AddObserver( testTicketObserver );
1129 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1130 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1131 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1132 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1134 application.SendNotification(); // Flush update queue
1135 application.Render(0); // Process message
1136 application.SendNotification(); // Send message to tickets
1138 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1139 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1140 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1141 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1142 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1144 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1145 DALI_TEST_CHECK ( theBitmap != NULL );
1146 DALI_TEST_CHECK ( bitmap == theBitmap );
1147 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1148 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1149 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1150 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1151 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1155 int UtcDaliInternalAddBitmapImage02(void)
1157 TestApplication application;
1158 tet_infoline("Testing AddBitmap without reserved buffer()");
1159 testTicketObserver.Reset();
1160 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1161 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1163 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1164 DALI_TEST_CHECK( imageTicket );
1165 imageTicket->AddObserver( testTicketObserver );
1167 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1168 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1169 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1170 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1171 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1173 application.SendNotification(); // Flush update queue
1174 application.Render(0); // Process message
1175 application.SendNotification(); // Send message to tickets
1177 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1178 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1179 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1180 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1181 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1183 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1184 DALI_TEST_CHECK ( theBitmap != NULL );
1185 DALI_TEST_CHECK ( bitmap == theBitmap );
1186 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1187 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1188 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1189 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1190 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1192 // There is no way for the ticket's image attributes to be updated if the bitmap
1193 // reserves a buffer after ticket generation.
1194 // Probably not an issue - there is no public API in BufferImage to change the image size.
1199 int UtcDaliInternalAddBitmapImage03(void)
1201 TestApplication application;
1202 tet_infoline("Testing AddBitmap() with invalid bitmap");
1203 testTicketObserver.Reset();
1205 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1206 Internal::ImageTicketPtr imageTicket;
1207 bool exceptionRaised=false;
1210 imageTicket = resourceClient.AddBitmapImage( NULL );
1212 catch( DaliException& e )
1214 exceptionRaised = true;
1216 DALI_TEST_CHECK( exceptionRaised );
1217 DALI_TEST_CHECK( ! imageTicket );
1221 int UtcDaliInternalGetBitmapImage01(void)
1223 TestApplication application;
1224 tet_infoline("Testing GetBitmap() with valid ticket");
1225 testTicketObserver.Reset();
1227 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1228 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
1229 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1230 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1232 Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1233 DALI_TEST_CHECK ( theBitmap != NULL );
1234 DALI_TEST_CHECK ( bitmap == theBitmap );
1235 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1236 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1237 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1238 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1239 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1241 imageTicket->AddObserver( testTicketObserver );
1242 application.SendNotification(); // Flush update queue
1243 application.Render(0); // Process message
1244 application.SendNotification(); // Send message to tickets
1246 theBitmap = resourceClient.GetBitmap(imageTicket);
1247 DALI_TEST_CHECK ( theBitmap != NULL );
1248 DALI_TEST_CHECK ( bitmap == theBitmap );
1249 DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 20u, TEST_LOCATION );
1250 DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 20u, TEST_LOCATION );
1251 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1252 DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1253 DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1257 int UtcDaliInternalGetBitmapImage02(void)
1259 TestApplication application;
1260 tet_infoline("Testing GetBitmap() with invalid ticket");
1262 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1263 Internal::ImageTicketPtr imageTicket;
1264 Integration::Bitmap* theBitmap = NULL;
1265 bool exceptionRaised = false;
1268 theBitmap = resourceClient.GetBitmap(imageTicket);
1269 } catch (DaliException& e)
1271 exceptionRaised = true;
1273 DALI_TEST_CHECK( exceptionRaised );
1274 DALI_TEST_CHECK( ! theBitmap );
1278 int UtcDaliInternalGetBitmapImage03(void)
1280 TestApplication application;
1281 tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1283 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient(); Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1284 Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1286 Integration::Bitmap* theBitmap = NULL;
1287 theBitmap = resourceClient.GetBitmap(imageTicket);
1288 DALI_TEST_CHECK( ! theBitmap );
1290 theBitmap = resourceClient.GetBitmap(modelTicket);
1291 DALI_TEST_CHECK( ! theBitmap );
1295 int UtcDaliInternalAllocateTexture01(void)
1297 TestApplication application;
1298 tet_infoline("Testing AllocateTexture()");
1299 testTicketObserver.Reset();
1301 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1302 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1303 resourceTicket->AddObserver( testTicketObserver );
1305 DALI_TEST_CHECK( resourceTicket );
1306 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1307 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1309 application.SendNotification(); // Flush update queue
1310 application.Render(0); // Process message
1311 application.SendNotification(); // Send message to tickets
1313 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1314 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1318 int UtcDaliInternalAddNativeImage(void)
1320 TestApplication application;
1321 tet_infoline("Testing AddNativeImage()");
1323 testTicketObserver.Reset();
1324 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1325 Internal::ResourceTicketPtr ticket;
1326 Internal::ImageTicketPtr imageTicket;
1327 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1328 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1329 ticket = resourceClient.AddNativeImage( *nativeImage );
1330 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1331 DALI_TEST_CHECK( imageTicket );
1332 imageTicket->AddObserver( testTicketObserver );
1335 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1336 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1337 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1338 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1340 application.SendNotification(); // Flush update queue
1341 application.Render(0); // Process message
1342 application.SendNotification(); // Send message to tickets
1344 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1345 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1346 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1347 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1349 Integration::Bitmap* theBitmap = NULL;
1350 theBitmap = resourceClient.GetBitmap(imageTicket);
1352 DALI_TEST_CHECK ( theBitmap == NULL );
1356 int UtcDaliInternalAddFrameBufferImage(void)
1358 TestApplication application;
1359 tet_infoline("Testing AddFrameBufferImage()");
1361 testTicketObserver.Reset();
1362 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1363 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1364 DALI_TEST_CHECK( imageTicket );
1365 imageTicket->AddObserver( testTicketObserver );
1367 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1368 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1369 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1370 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1371 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1373 application.SendNotification(); // Flush update queue
1374 application.Render(0); // Process message
1375 application.SendNotification(); // Send message to tickets
1377 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1378 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1379 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1380 DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1381 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1383 Integration::Bitmap* theBitmap = NULL;
1384 theBitmap = resourceClient.GetBitmap(imageTicket);
1385 DALI_TEST_CHECK ( theBitmap == NULL );
1389 int UtcDaliInternalAllocateMesh01(void)
1391 TestApplication application;
1392 tet_infoline("Testing AllocateMesh() with vald mesh data");
1394 MeshData publicMeshData;
1395 MeshData::VertexContainer vertices;
1396 MeshData::FaceIndices faces;
1397 BoneContainer bones;
1398 ConstructVertices(vertices, 60);
1399 ConstructFaces(vertices, faces);
1400 Material customMaterial = ConstructMaterial();
1401 publicMeshData.SetData(vertices, faces, bones, customMaterial);
1402 publicMeshData.SetHasNormals(true);
1403 publicMeshData.SetHasTextureCoords(true);
1405 testTicketObserver.Reset();
1406 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
1407 Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, true, true ) );
1408 Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1409 DALI_TEST_CHECK( meshTicket );
1410 meshTicket->AddObserver( testTicketObserver );
1412 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1414 application.SendNotification(); // Flush update queue
1415 application.Render(0); // Process message
1416 application.SendNotification(); // Send message to tickets
1418 DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );