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
26 #include <dali/public-api/shader-effects/shader-effect.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/update/resources/bitmap-metadata.h>
29 #include <dali/internal/update/resources/resource-manager.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/event/resources/resource-client.h>
32 #include <dali/internal/event/resources/resource-ticket.h>
33 #include <dali/internal/event/resources/image-ticket.h>
34 #include <dali/internal/event/resources/resource-ticket-observer.h>
35 #include <dali/internal/event/images/resource-image-impl.h>
36 #include <dali/integration-api/resource-cache.h>
37 #include <dali/internal/render/gl-resources/texture-declarations.h>
38 #include <dali/internal/render/shaders/scene-graph-shader.h>
39 #include <dali/internal/common/owner-pointer.h>
40 #include <dali/internal/common/image-attributes.h>
44 #include <mesh-builder.h>
49 class TestTicketObserver : public Internal::ResourceTicketObserver
53 : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
57 int LoadFailedCalled() {
58 tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
59 return mLoadingFailedCalled;
61 int LoadSucceededCalled() {
62 tet_printf("TicketObserver: LoadingSucceeded() called %d times", mLoadingSucceededCalled);
63 return mLoadingSucceededCalled;
66 tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
67 return mUploadedCount;
70 mLoadingFailedCalled = 0;
71 mLoadingSucceededCalled = 0;
75 public: // From ResourceTicketObserver
76 virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
77 virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
78 virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
81 int mLoadingFailedCalled;
82 int mLoadingSucceededCalled;
86 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
89 TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
91 virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
92 { resourceTicketDiscarded = true; }
94 void Reset() { resourceTicketDiscarded = false; }
95 bool resourceTicketDiscarded;
98 static TestTicketObserver testTicketObserver;
99 static TestTicketLifetimeObserver testTicketLifetimeObserver;
102 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
104 Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Internal::ImageAttributes::DEFAULT_ATTRIBUTES );
105 application.SendNotification(); // Flush update messages
106 application.Render(); // Process resource request
107 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
108 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
109 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
110 Integration::ResourcePointer resourcePtr(bitmap); // reference it
111 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
112 application.Render(); // Process LoadComplete
113 application.SendNotification(); // Process event messages
114 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
116 application.GetPlatform().ResetTrace();
121 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
123 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
124 Integration::BitmapResourceType bitmapRequest;
125 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
126 ticket->AddObserver(testTicketObserver);
127 application.SendNotification(); // Flush update messages
128 application.Render(); // Process resource request
129 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
130 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
131 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
132 Integration::ResourcePointer resourcePtr(bitmap); // reference it
133 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
134 application.Render(); // Process LoadComplete
135 application.SendNotification(); // Process event messages
136 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
137 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
139 application.GetPlatform().ResetTrace();
144 } //anonymous namespace
147 void utc_dali_internal_resource_client_startup()
149 test_return_value = TET_UNDEF;
152 void utc_dali_internal_resource_client_cleanup()
154 test_return_value = TET_PASS;
157 // Load a bitmap resource successfully, then discard it's ticket
158 int UtcDaliInternalRequestResourceBitmapRequests01(void)
160 TestApplication application; // Reset all test adapter return codes
162 tet_infoline("Testing bitmap requests");
164 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
165 Integration::BitmapResourceType bitmapRequest;
166 Internal::ResourceId id(0);
168 testTicketObserver.Reset();
171 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
172 /************************************************************
173 * FUNCTION UNDER TEST
174 ***********************************************************/
175 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
176 ticket->AddObserver(testTicketObserver);
178 // Update thread will request the bitmap resource:
179 // Sets application.GetPlatform().mRequest
180 application.SendNotification(); // Run flush update queue
181 application.Render(1); // Process update messages
182 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
184 application.SendNotification(); // Send any event messages
185 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
186 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
187 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
189 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
190 DALI_TEST_CHECK( imageTicket );
191 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
192 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
195 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
196 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
197 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
198 Integration::ResourcePointer resourcePtr(bitmap); // reference it
200 // Set up platform abstraction to load it
202 application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
204 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
206 // load the cache, which will immediately have the loaded resource
207 application.Render(0);
209 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
211 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
212 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
213 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
214 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
216 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
217 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
219 // Trigger the event thread to process notify messages. Should then trigger the signals
220 // in the ticket observer
221 application.SendNotification();
223 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
224 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
226 // Check that the image ticket was updated with the image attributes
227 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
228 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
231 application.SendNotification(); // Flush update queue (with ticket discarded message
232 application.Render(1); // Process update messages
233 application.SendNotification(); // Send event notifications
234 application.Render(1); // Process update messages
236 // Resource should have been discarded.
237 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
238 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
240 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
241 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
245 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
246 int UtcDaliInternalRequestResourceBitmapRequests02(void)
248 TestApplication application; // Reset all test adapter return codes
250 tet_infoline("Testing bitmap request ticket discard before load complete");
252 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
253 Integration::BitmapResourceType bitmapRequest;
254 Internal::ResourceId id(0);
256 testTicketObserver.Reset();
259 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
260 /************************************************************
261 * FUNCTION UNDER TEST
262 ***********************************************************/
263 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
264 ticket->AddObserver(testTicketObserver);
265 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
266 DALI_TEST_CHECK( imageTicket );
267 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
268 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
270 // Update thread will request the bitmap resource:
271 // Sets application.GetPlatform().mRequest
272 application.SendNotification(); // Run flush update queue
273 application.Render(1);
274 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
275 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
278 application.SendNotification(); // Should produce no messages
279 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
280 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
282 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
284 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
285 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
286 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
290 // Ensure ticket discarded message is sent to update thread
291 application.SendNotification(); // Flush update queue
292 application.Render(0); // Process update messages
294 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
295 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
297 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
299 // Trigger the event thread to process notify messages. Should then trigger the signals
300 // in the ticket observer
301 application.SendNotification();
303 DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
304 DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
308 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
309 int UtcDaliInternalRequestResourceBitmapRequests03(void)
311 TestApplication application; // Reset all test adapter return codes
313 tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
315 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
316 Integration::BitmapResourceType bitmapRequest;
317 Internal::ResourceId id(0);
319 testTicketObserver.Reset();
320 { // Scope lifetime of ticket
321 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
323 /************************************************************
324 * FUNCTION UNDER TEST
325 ***********************************************************/
326 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
327 ticket->AddObserver(testTicketObserver);
328 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
329 DALI_TEST_CHECK( imageTicket );
330 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
331 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
333 // Update thread will request the bitmap resource:
334 // Sets application.GetPlatform().mRequest
335 application.SendNotification(); // Run flush update queue
336 application.Render(1); // process update messages
337 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
338 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
340 application.SendNotification(); // Should produce no messages
341 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
342 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
344 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
346 application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
348 application.Render(0); // Get failed result
349 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
350 application.SendNotification(); // send failed
351 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
352 DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
354 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
355 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
356 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
358 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
361 application.Render(0); // Send DiscardTicket
362 application.SendNotification();
364 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
370 // Load a bitmap resource successfully, then reload it
371 int UtcDaliInternalRequestReloadBitmapRequests01(void)
373 TestApplication application; // Reset all test adapter return codes
375 tet_infoline("Testing bitmap reload after successful load");
377 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
378 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
380 Internal::ResourceId id(0);
381 testTicketObserver.Reset();
384 Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
385 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
386 id = ticket->GetId();
388 // Reset call statistics - test that resource is reloaded
389 application.GetPlatform().ResetTrace();
391 /************************************************************
392 * FUNCTION UNDER TEST
393 ***********************************************************/
394 resourceClient.ReloadResource( ticket->GetId() );
396 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
397 application.SendNotification(); // Flush update messages
398 application.Render(0); // Process update messages
399 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
400 application.SendNotification(); // Process event messages
402 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
403 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
404 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
405 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
407 // Create a new resource - the image size could have changed in the meantime
408 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
409 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
410 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
411 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
412 DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
413 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
415 application.Render(0); // Process update messages / UpdateCache
416 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
418 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
419 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
420 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
421 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
423 // Ticket can't have been updated yet - it should still have old values
424 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
425 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
427 application.SendNotification(); // Process event messages
428 application.Render(0); // Process update messages / UpdateCache
429 application.SendNotification(); // Process event messages
431 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
432 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
433 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
434 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
435 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
439 application.SendNotification(); // Flush update queue (with ticket discarded message
440 application.Render(1); // Process update messages
441 application.SendNotification(); // Send event notifications
442 application.Render(1); // Process update messages
444 // Resource should have been discarded.
445 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
446 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
448 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
449 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
450 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
455 int UtcDaliInternalRequestReloadBitmapRequests02(void)
457 TestApplication application; // Reset all test adapter return codes
459 tet_infoline("Testing bitmap reload during first load");
461 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
462 Integration::BitmapResourceType bitmapRequest;
463 Internal::ResourceId id(0);
465 testTicketObserver.Reset();
468 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
469 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
470 ticket->AddObserver(testTicketObserver);
472 // Update thread will request the bitmap resource:
473 // Sets application.GetPlatform().mRequest
474 application.SendNotification(); // Run flush update queue
475 application.Render(1); // Process update messages
476 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
478 application.SendNotification(); // Send any event messages
479 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
480 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
482 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
483 DALI_TEST_CHECK( imageTicket );
484 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
485 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
488 /************************************************************
489 * FUNCTION UNDER TEST
490 ***********************************************************/
491 resourceClient.ReloadResource( ticket->GetId() );
492 /************************************************************
493 * Expected result - current load completes as usual, no reload requested
494 ************************************************************/
496 application.SendNotification(); // Flush update methods
498 // Reset call statistics - test that resource is not reloaded
499 application.GetPlatform().ResetTrace();
501 application.Render(0); // Process reload message (nothing for UpdateCache yet)
503 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
504 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
506 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
507 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
508 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
509 Integration::ResourcePointer resourcePtr(bitmap); // reference it
511 // Set up platform abstraction to load it
514 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
516 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
518 application.GetPlatform().ResetTrace();
519 // load the cache, which will immediately have the loaded resource
520 application.Render(0);
521 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
522 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
523 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
524 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
525 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
527 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
528 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
530 // Trigger the event thread to process notify messages. Should then trigger the signals
531 // in the ticket observer
532 application.SendNotification();
534 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
535 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
536 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
538 // Check that the image ticket was updated with the image attributes
539 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
540 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
542 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
544 application.SendNotification(); // Flush update messages
545 application.Render(0); // Process update messages
547 // There should be no reload
548 DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
549 application.SendNotification(); // Process event messages
551 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
552 DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
553 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
554 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
556 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
557 bitmapData = resourceManager.GetBitmapMetadata(id);
558 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
559 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
560 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
561 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
568 int UtcDaliInternalRequestReloadBitmapRequests03(void)
570 TestApplication application; // Reset all test adapter return codes
572 tet_infoline("Testing bitmap reload at end of first load");
574 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
575 Integration::BitmapResourceType bitmapRequest;
576 Internal::ResourceId id(0);
578 testTicketObserver.Reset();
581 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
582 Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
583 ticket->AddObserver(testTicketObserver);
585 // Update thread will request the bitmap resource:
586 // Sets application.GetPlatform().mRequest
587 application.SendNotification(); // Run flush update queue
588 application.Render(1); // Process update messages
589 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
591 application.SendNotification(); // Send any event messages
592 DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
593 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
595 Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
596 DALI_TEST_CHECK( imageTicket );
597 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
598 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
601 /************************************************************
602 * FUNCTION UNDER TEST
603 ***********************************************************/
604 resourceClient.ReloadResource( ticket->GetId() );
605 /************************************************************
606 * Expected result - current load completes as usual, no reload requested
607 ************************************************************/
609 application.SendNotification(); // Flush update methods
611 // Reset call statistics - test that resource is not reloaded
612 application.GetPlatform().ResetTrace();
615 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
616 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
617 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
618 Integration::ResourcePointer resourcePtr(bitmap); // reference it
620 // Set up platform abstraction to load it
623 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
625 DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
627 application.GetPlatform().ResetTrace();
628 // load the cache, which will immediately have the loaded resource
629 application.Render(0);
631 // UpdateCache runs before ProcessMessages, so the loading resource completes before
632 // the reload request is handled.
633 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
634 DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
636 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
637 Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
638 DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
639 DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
641 DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
642 DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
644 // Trigger the event thread to process notify messages. Should then trigger the signals
645 // in the ticket observer
646 application.SendNotification();
648 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
649 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
650 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
652 // Check that the image ticket was updated with the image attributes
653 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
654 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
656 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
658 // Create a new resource - the image size could have changed in the meantime
659 req = application.GetPlatform().GetRequest();
660 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
661 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
662 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
663 DALI_TEST_CHECK( req->GetId() == id );
664 application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
666 application.Render(0); // Process update messages / UpdateCache
668 DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
669 bitmapData = resourceManager.GetBitmapMetadata(id);
670 DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
671 DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
672 DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
673 DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
675 application.SendNotification(); // Process event messages
677 DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
679 // Not staged - no GL upload
680 DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
682 DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
683 DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
684 DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
685 DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
690 int UtcDaliInternalRequestResourceTicket01(void)
692 TestApplication application;
693 tet_infoline("Testing RequestResourceTicket() with valid id");
695 testTicketObserver.Reset();
697 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
699 // First, load a bitmap resource
700 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
702 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
703 DALI_TEST_CHECK( newTicket );
704 DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
705 DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
709 int UtcDaliInternalRequestResourceTicket02(void)
711 TestApplication application;
712 tet_infoline("Testing RequestResourceTicket() with invalid id");
714 testTicketObserver.Reset();
716 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
718 // First, load a bitmap resource
719 Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
721 Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
722 DALI_TEST_CHECK( ! newTicket );
726 int UtcDaliInternalAddBitmapImage01(void)
728 TestApplication application;
729 tet_infoline("Testing AddBitmap with reserved buffer()");
730 testTicketObserver.Reset();
731 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
732 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
733 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
735 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
736 DALI_TEST_CHECK( imageTicket );
737 imageTicket->AddObserver( testTicketObserver );
739 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
740 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
741 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
743 application.SendNotification(); // Flush update queue
744 application.Render(0); // Process message
745 application.SendNotification(); // Send message to tickets
747 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
748 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
749 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
750 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
754 int UtcDaliInternalAddBitmapImage02(void)
756 TestApplication application;
757 tet_infoline("Testing AddBitmap without reserved buffer()");
758 testTicketObserver.Reset();
759 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
760 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
762 Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
763 DALI_TEST_CHECK( imageTicket );
764 imageTicket->AddObserver( testTicketObserver );
766 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
767 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
768 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
769 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
771 application.SendNotification(); // Flush update queue
772 application.Render(0); // Process message
773 application.SendNotification(); // Send message to tickets
775 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
776 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
777 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
778 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
783 int UtcDaliInternalAddBitmapImage03(void)
785 TestApplication application;
786 tet_infoline("Testing AddBitmap() with invalid bitmap");
787 testTicketObserver.Reset();
789 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
790 Internal::ImageTicketPtr imageTicket;
791 bool exceptionRaised=false;
794 imageTicket = resourceClient.AddBitmapImage( NULL );
796 catch( DaliException& e )
798 exceptionRaised = true;
800 DALI_TEST_CHECK( exceptionRaised );
801 DALI_TEST_CHECK( ! imageTicket );
805 int UtcDaliInternalAllocateTexture01(void)
807 TestApplication application;
808 tet_infoline("Testing AllocateTexture()");
809 testTicketObserver.Reset();
811 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
812 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
813 resourceTicket->AddObserver( testTicketObserver );
815 DALI_TEST_CHECK( resourceTicket );
816 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
817 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
819 application.SendNotification(); // Flush update queue
820 application.Render(0); // Process message
821 application.SendNotification(); // Send message to tickets
823 DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
824 DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
828 int UtcDaliInternalAddNativeImage(void)
830 TestApplication application;
831 tet_infoline("Testing AddNativeImage()");
833 testTicketObserver.Reset();
834 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
835 Internal::ResourceTicketPtr ticket;
836 Internal::ImageTicketPtr imageTicket;
837 { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
838 TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
839 ticket = resourceClient.AddNativeImage( *nativeImage );
840 imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
841 DALI_TEST_CHECK( imageTicket );
842 imageTicket->AddObserver( testTicketObserver );
845 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
846 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
847 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
848 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
850 application.SendNotification(); // Flush update queue
851 application.Render(0); // Process message
852 application.SendNotification(); // Send message to tickets
854 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
855 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
856 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
857 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
861 int UtcDaliInternalAddFrameBufferImage(void)
863 TestApplication application;
864 tet_infoline("Testing AddFrameBufferImage()");
866 testTicketObserver.Reset();
867 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
868 Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8, RenderBuffer::COLOR );
869 DALI_TEST_CHECK( imageTicket );
870 imageTicket->AddObserver( testTicketObserver );
872 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
873 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
874 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
875 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
877 application.SendNotification(); // Flush update queue
878 application.Render(0); // Process message
879 application.SendNotification(); // Send message to tickets
881 DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
882 DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
883 DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
884 DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent