(AutomatedTests) Move devel-api dependent tests to internal tests
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-ResourceClient.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
24
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/shader.h>
39 #include <dali/internal/common/owner-pointer.h>
40 #include <dali/internal/common/image-attributes.h>
41
42 using namespace Dali;
43
44 #include <mesh-builder.h>
45
46 namespace
47 {
48
49 class TestTicketObserver : public Internal::ResourceTicketObserver
50 {
51 public:
52   TestTicketObserver()
53   : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
54     mSavingFailedCalled(0), mSavingSucceededCalled(0),
55     mUploadedCount(0)
56   {}
57
58   int LoadFailedCalled() {
59     tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
60     return mLoadingFailedCalled;
61   }
62   int LoadSucceededCalled() {
63     tet_printf("TicketObserver: LoadingSucceeded()  called %d times", mLoadingSucceededCalled);
64     return mLoadingSucceededCalled;
65   }
66   int SaveFailedCalled() {
67     tet_printf("TicketObserver: SavingFailed() called %d times", mSavingFailedCalled);
68     return mSavingFailedCalled;
69   }
70   int SaveSucceededCalled() {
71     tet_printf("TicketObserver: SavingSucceeded() called %d times", mSavingSucceededCalled);
72     return mSavingSucceededCalled;
73   }
74   int  UploadCalled() {
75     tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
76     return mUploadedCount;
77   }
78   void Reset() {
79     mLoadingFailedCalled    = 0;
80     mLoadingSucceededCalled = 0;
81     mSavingFailedCalled     = 0;
82     mSavingSucceededCalled  = 0;
83     mUploadedCount           = 0;
84   }
85
86 public: // From ResourceTicketObserver
87   virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
88   virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
89   virtual void ResourceSavingFailed(const Internal::ResourceTicket& ticket) {mSavingFailedCalled++;}
90   virtual void ResourceSavingSucceeded(const Internal::ResourceTicket& ticket) {mSavingSucceededCalled++;}
91   virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
92
93 private:
94   int mLoadingFailedCalled;
95   int mLoadingSucceededCalled;
96   int mSavingFailedCalled;
97   int mSavingSucceededCalled;
98   int mUploadedCount;
99 };
100
101 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
102 {
103 public:
104   TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
105
106   virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
107   { resourceTicketDiscarded = true; }
108
109   void Reset() { resourceTicketDiscarded = false; }
110   bool resourceTicketDiscarded;
111 };
112
113 static TestTicketObserver testTicketObserver;
114 static TestTicketLifetimeObserver testTicketLifetimeObserver;
115
116
117 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
118 {
119   Internal::ResourceImagePtr image = Internal::ResourceImage::New( name, Internal::ImageAttributes::DEFAULT_ATTRIBUTES );
120   application.SendNotification(); // Flush update messages
121   application.Render();           // Process resource request
122   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
123   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
124   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
125   Integration::ResourcePointer resourcePtr(bitmap); // reference it
126   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
127   application.Render();           // Process LoadComplete
128   application.SendNotification(); // Process event messages
129   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
130   req=NULL;
131   application.GetPlatform().ResetTrace();
132   return image;
133 }
134
135
136 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
137 {
138   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
139   Integration::BitmapResourceType bitmapRequest;
140   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
141   ticket->AddObserver(testTicketObserver);
142   application.SendNotification(); // Flush update messages
143   application.Render();           // Process resource request
144   Integration::ResourceRequest*   req = application.GetPlatform().GetRequest();
145   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
146   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
147   Integration::ResourcePointer resourcePtr(bitmap); // reference it
148   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
149   application.Render();           // Process LoadComplete
150   application.SendNotification(); // Process event messages
151   DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
152   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
153   req=NULL;
154   application.GetPlatform().ResetTrace();
155
156   return ticket;
157 }
158
159 } //anonymous namespace
160
161
162 void utc_dali_internal_resource_client_startup()
163 {
164   test_return_value = TET_UNDEF;
165 }
166
167 void utc_dali_internal_resource_client_cleanup()
168 {
169   test_return_value = TET_PASS;
170 }
171
172 // Load a bitmap resource successfully, then discard it's ticket
173 int UtcDaliInternalRequestResourceBitmapRequests01(void)
174 {
175   TestApplication application; // Reset all test adapter return codes
176
177   tet_infoline("Testing bitmap requests");
178
179   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
180   Integration::BitmapResourceType bitmapRequest;
181   Internal::ResourceId id(0);
182
183   testTicketObserver.Reset();
184
185   {
186     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
187     /************************************************************
188      * FUNCTION UNDER TEST
189      ***********************************************************/
190     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
191     ticket->AddObserver(testTicketObserver);
192
193     // Update thread will request the bitmap resource:
194     // Sets application.GetPlatform().mRequest
195     application.SendNotification(); // Run flush update queue
196     application.Render(1);          // Process update messages
197     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
198
199     application.SendNotification(); // Send any event messages
200     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
201     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
202     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
203
204     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
205     DALI_TEST_CHECK( imageTicket );
206     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
207     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
208
209     // Create a resource
210     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
211     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
212     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
213     Integration::ResourcePointer resourcePtr(bitmap); // reference it
214
215     // Set up platform abstraction to load it
216     id=req->GetId();
217     application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
218
219     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
220
221     // load the cache, which will immediately have the loaded resource
222     application.Render(0);
223
224     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
225
226     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
227     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
228     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
229     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
230
231     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
232     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
233
234     // Trigger the event thread to process notify messages. Should then trigger the signals
235     // in the ticket observer
236     application.SendNotification();
237
238     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
239     DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
240
241     // Check that the image ticket was updated with the image attributes
242     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
243     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
244   } // Discard ticket
245
246   application.SendNotification(); // Flush update queue (with ticket discarded message
247   application.Render(1);          // Process update messages
248   application.SendNotification(); // Send event notifications
249   application.Render(1);          // Process update messages
250
251   // Resource should have been discarded.
252   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
253   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
254
255   DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
256   DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
257   END_TEST;
258 }
259
260 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
261 int UtcDaliInternalRequestResourceBitmapRequests02(void)
262 {
263   TestApplication application; // Reset all test adapter return codes
264
265   tet_infoline("Testing bitmap request ticket discard before load complete");
266
267   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
268   Integration::BitmapResourceType bitmapRequest;
269   Internal::ResourceId id(0);
270
271   testTicketObserver.Reset();
272
273   {
274     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
275     /************************************************************
276      * FUNCTION UNDER TEST
277      ***********************************************************/
278     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
279     ticket->AddObserver(testTicketObserver);
280     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
281     DALI_TEST_CHECK( imageTicket );
282     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
283     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
284
285     // Update thread will request the bitmap resource:
286     // Sets application.GetPlatform().mRequest
287     application.SendNotification(); // Run flush update queue
288     application.Render(1);
289     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
290     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
291     id=req->GetId();
292
293     application.SendNotification(); // Should produce no messages
294     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
295     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
296
297     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
298
299     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
300     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
301     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
302
303   } // Discard ticket
304
305   // Ensure ticket discarded message is sent to update thread
306   application.SendNotification(); // Flush update queue
307   application.Render(0);          // Process update messages
308
309   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
310   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
311
312   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
313
314   // Trigger the event thread to process notify messages. Should then trigger the signals
315   // in the ticket observer
316   application.SendNotification();
317
318   DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
319   DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
320   END_TEST;
321 }
322
323 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
324 int UtcDaliInternalRequestResourceBitmapRequests03(void)
325 {
326   TestApplication application; // Reset all test adapter return codes
327
328   tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
329
330   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
331   Integration::BitmapResourceType bitmapRequest;
332   Internal::ResourceId id(0);
333
334   testTicketObserver.Reset();
335   { // Scope lifetime of ticket
336     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
337
338     /************************************************************
339      * FUNCTION UNDER TEST
340      ***********************************************************/
341     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
342     ticket->AddObserver(testTicketObserver);
343     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
344     DALI_TEST_CHECK( imageTicket );
345     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
346     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
347
348     // Update thread will request the bitmap resource:
349     // Sets application.GetPlatform().mRequest
350     application.SendNotification(); // Run flush update queue
351     application.Render(1);          // process update messages
352     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
353     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
354     id=req->GetId();
355     application.SendNotification(); // Should produce no messages
356     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
357     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
358
359     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
360
361     application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
362
363     application.Render(0); // Get failed result
364     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
365     application.SendNotification(); // send failed
366     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
367     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
368
369     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
370     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
371     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
372
373     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
374   } // Discard ticket
375
376   application.Render(0); // Send DiscardTicket
377   application.SendNotification();
378
379   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
380   END_TEST;
381 }
382
383
384
385 // Load a bitmap resource successfully, then reload it
386 int UtcDaliInternalRequestReloadBitmapRequests01(void)
387 {
388   TestApplication application; // Reset all test adapter return codes
389
390   tet_infoline("Testing bitmap reload after successful load");
391
392   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
393   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
394
395   Internal::ResourceId id(0);
396   testTicketObserver.Reset();
397
398   {
399     Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
400     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
401     id = ticket->GetId();
402
403     // Reset call statistics - test that resource is reloaded
404     application.GetPlatform().ResetTrace();
405
406     /************************************************************
407      * FUNCTION UNDER TEST
408      ***********************************************************/
409     resourceClient.ReloadResource( ticket->GetId() );
410
411     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
412     application.SendNotification(); // Flush update messages
413     application.Render(0);  // Process update messages
414     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
415     application.SendNotification(); // Process event messages
416
417     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
418     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
419     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
420     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
421
422     // Create a new resource - the image size could have changed in the meantime
423     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
424     Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
425     bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
426     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
427     DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
428     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
429
430     application.Render(0);  // Process update messages / UpdateCache
431     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
432
433     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
434     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
435     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
436     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
437
438     // Ticket can't have been updated yet - it should still have old values
439     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
440     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
441
442     application.SendNotification(); // Process event messages
443     application.Render(0);          // Process update messages / UpdateCache
444     application.SendNotification(); // Process event messages
445
446     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
447     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
448     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
449     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
450     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
451
452   } // Discard ticket
453
454   application.SendNotification(); // Flush update queue (with ticket discarded message
455   application.Render(1);          // Process update messages
456   application.SendNotification(); // Send event notifications
457   application.Render(1);          // Process update messages
458
459   // Resource should have been discarded.
460   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
461   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
462
463   DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
464   DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
465   DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
466   END_TEST;
467 }
468
469
470 int UtcDaliInternalRequestReloadBitmapRequests02(void)
471 {
472   TestApplication application; // Reset all test adapter return codes
473
474   tet_infoline("Testing bitmap reload during first load");
475
476   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
477   Integration::BitmapResourceType bitmapRequest;
478   Internal::ResourceId id(0);
479
480   testTicketObserver.Reset();
481
482   {
483     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
484     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
485     ticket->AddObserver(testTicketObserver);
486
487     // Update thread will request the bitmap resource:
488     // Sets application.GetPlatform().mRequest
489     application.SendNotification(); // Run flush update queue
490     application.Render(1);          // Process update messages
491     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
492
493     application.SendNotification(); // Send any event messages
494     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
495     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
496
497     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
498     DALI_TEST_CHECK( imageTicket );
499     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
500     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
501
502
503     /************************************************************
504      * FUNCTION UNDER TEST
505      ***********************************************************/
506     resourceClient.ReloadResource( ticket->GetId() );
507     /************************************************************
508      * Expected result - current load completes as usual, no reload requested
509      ************************************************************/
510
511     application.SendNotification(); // Flush update methods
512
513     // Reset call statistics - test that resource is not reloaded
514     application.GetPlatform().ResetTrace();
515
516     application.Render(0); // Process reload message (nothing for UpdateCache yet)
517
518     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
519     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
520     // Create a resource
521     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
522     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
523     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
524     Integration::ResourcePointer resourcePtr(bitmap); // reference it
525
526     // Set up platform abstraction to load it
527     id=req->GetId();
528
529     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
530
531     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
532
533     application.GetPlatform().ResetTrace();
534     // load the cache, which will immediately have the loaded resource
535     application.Render(0);
536     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
537     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
538     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
539     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
540     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
541
542     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
543     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
544
545     // Trigger the event thread to process notify messages. Should then trigger the signals
546     // in the ticket observer
547     application.SendNotification();
548
549     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
550     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
551     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
552
553     // Check that the image ticket was updated with the image attributes
554     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
555     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
556
557     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
558
559     application.SendNotification(); // Flush update messages
560     application.Render(0);  // Process update messages
561
562     // There should be no reload
563     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
564     application.SendNotification(); // Process event messages
565
566     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
567     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
568     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
569     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
570
571     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
572     bitmapData = resourceManager.GetBitmapMetadata(id);
573     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
574     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
575     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
576     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
577
578   } // Discard ticket
579   END_TEST;
580 }
581
582
583 int UtcDaliInternalRequestReloadBitmapRequests03(void)
584 {
585   TestApplication application; // Reset all test adapter return codes
586
587   tet_infoline("Testing bitmap reload at end of first load");
588
589   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
590   Integration::BitmapResourceType bitmapRequest;
591   Internal::ResourceId id(0);
592
593   testTicketObserver.Reset();
594
595   {
596     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
597     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
598     ticket->AddObserver(testTicketObserver);
599
600     // Update thread will request the bitmap resource:
601     // Sets application.GetPlatform().mRequest
602     application.SendNotification(); // Run flush update queue
603     application.Render(1);          // Process update messages
604     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
605
606     application.SendNotification(); // Send any event messages
607     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
608     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
609
610     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
611     DALI_TEST_CHECK( imageTicket );
612     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
613     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
614
615
616     /************************************************************
617      * FUNCTION UNDER TEST
618      ***********************************************************/
619     resourceClient.ReloadResource( ticket->GetId() );
620     /************************************************************
621      * Expected result - current load completes as usual, no reload requested
622      ************************************************************/
623
624     application.SendNotification(); // Flush update methods
625
626     // Reset call statistics - test that resource is not reloaded
627     application.GetPlatform().ResetTrace();
628
629     // Create a resource
630     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
631     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
632     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
633     Integration::ResourcePointer resourcePtr(bitmap); // reference it
634
635     // Set up platform abstraction to load it
636     id=req->GetId();
637
638     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
639
640     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
641
642     application.GetPlatform().ResetTrace();
643     // load the cache, which will immediately have the loaded resource
644     application.Render(0);
645
646     // UpdateCache runs before ProcessMessages, so the loading resource completes before
647     // the reload request is handled.
648     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
649     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
650
651     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
652     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
653     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
654     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
655
656     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
657     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
658
659     // Trigger the event thread to process notify messages. Should then trigger the signals
660     // in the ticket observer
661     application.SendNotification();
662
663     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
664     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
665     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
666
667     // Check that the image ticket was updated with the image attributes
668     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
669     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
670
671     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
672
673     // Create a new resource - the image size could have changed in the meantime
674     req = application.GetPlatform().GetRequest();
675     Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
676     bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
677     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
678     DALI_TEST_CHECK( req->GetId() == id );
679     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
680
681     application.Render(0);  // Process update messages / UpdateCache
682
683     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
684     bitmapData = resourceManager.GetBitmapMetadata(id);
685     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
686     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
687     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
688     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
689
690     application.SendNotification(); // Process event messages
691
692     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
693
694     // Not staged - no GL upload
695     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
696
697     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
698     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
699     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
700     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
701   }
702   END_TEST;
703 }
704
705 /**
706 //int UtcDaliInternalSaveResource01(void)//
707 {
708   TestApplication application;
709   tet_infoline("Testing SaveResource() with valid id, and valid filename");
710   testTicketObserver.Reset();
711
712   DALI_TEST_CHECK(0);
713   END_TEST;
714 }
715
716
717 //int UtcDaliInternalSaveResource02(void)//
718 {
719   TestApplication application;
720   tet_infoline("Testing SaveResource() with invalid id");
721   testTicketObserver.Reset();
722
723   DALI_TEST_CHECK(0);
724   END_TEST;
725 }
726
727 //int UtcDaliInternalSaveResource03(void)//
728 {
729   TestApplication application;
730   tet_infoline("Testing SaveResource() with invalid id");
731   testTicketObserver.Reset();
732
733   DALI_TEST_CHECK ( 0 );
734   END_TEST;
735 }
736
737
738 //int UtcDaliInternalSaveResource04(void)//
739 {
740   TestApplication application;
741   tet_infoline("Testing SaveResource() with valid id, but invalid filename");
742   testTicketObserver.Reset();
743   DALI_TEST_CHECK( 0 );
744   END_TEST;
745 }
746 */
747
748 int UtcDaliInternalSaveResource05(void)
749 {
750   TestApplication application;
751   tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
752   testTicketObserver.Reset();
753
754   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
755
756   // First, load a bitmap resource
757   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
758
759   // Try saving it
760   resourceClient.SaveResource( ticket, "bitmap.png" );
761   application.SendNotification(); // Flush update messages
762   application.Render();           // Process save resource request
763
764   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
765   END_TEST;
766 }
767
768 int UtcDaliInternalRequestResourceTicket01(void)
769 {
770   TestApplication application;
771   tet_infoline("Testing RequestResourceTicket() with valid id");
772
773   testTicketObserver.Reset();
774
775   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
776
777   // First, load a bitmap resource
778   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
779
780   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
781   DALI_TEST_CHECK( newTicket );
782   DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
783   DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
784   END_TEST;
785 }
786
787 int UtcDaliInternalRequestResourceTicket02(void)
788 {
789   TestApplication application;
790   tet_infoline("Testing RequestResourceTicket() with invalid id");
791
792   testTicketObserver.Reset();
793
794   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
795
796   // First, load a bitmap resource
797   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
798
799   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
800   DALI_TEST_CHECK( ! newTicket );
801   END_TEST;
802 }
803
804 int UtcDaliInternalLoadShaderRequest01(void)
805 {
806   TestApplication application;
807   tet_infoline("Testing LoadShader() success");
808   testTicketObserver.Reset();
809
810   // Clear through all of the outstanding shader load requests from the default shader effect
811   std::vector< unsigned char > buffer;
812   for( int i=0; i<10; i++ )
813   {
814     buffer.push_back((unsigned char)i);
815   }
816   application.GetPlatform().SetLoadFileResult( true, buffer );
817   application.GetGlAbstraction().SetLinkStatus(1);
818   application.SendNotification(); // Flush update messages
819   application.Render();           // Process load shader request (immediately)
820   application.SendNotification();
821   application.Render();
822   application.SendNotification();
823   application.Render();
824   application.SendNotification();
825
826   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
827
828   Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
829   std::string shaderBinaryFile("shader.bin");
830   Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
831   DALI_TEST_CHECK( ticket );
832
833   application.GetPlatform().SetLoadFileResult( true, buffer );
834   application.GetGlAbstraction().EnableShaderCallTrace( true );
835   application.GetGlAbstraction().SetLinkStatus(1);
836
837   application.SendNotification(); // Flush update messages
838   application.Render();           // Process load shader request (immediately)
839
840   application.SendNotification();
841   application.Render();
842
843   application.SendNotification();
844   application.Render();
845
846   // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
847   TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
848   DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
849
850   // Ensure no request sent to platform abstraction
851   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
852   END_TEST;
853 }
854
855 int UtcDaliInternalAllocateBitmapImage01(void)
856 {
857   TestApplication application;
858   tet_infoline("Testing AllocateBitmapImage()");
859   testTicketObserver.Reset();
860
861   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
862   Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
863   imageTicket->AddObserver( testTicketObserver );
864
865   DALI_TEST_CHECK( imageTicket );
866   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
867   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
868   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
869
870   application.SendNotification(); // Flush update queue
871   application.Render(0); // Process message
872   application.SendNotification(); // Send message to tickets
873
874   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
875   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
876   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
877   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
878
879   Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
880   DALI_TEST_CHECK ( bitmap != NULL );
881   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
882   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
883   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
884   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
885   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
886   END_TEST;
887 }
888
889 int UtcDaliInternalAddBitmapImage01(void)
890 {
891   TestApplication application;
892   tet_infoline("Testing AddBitmap with reserved buffer()");
893   testTicketObserver.Reset();
894   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
895   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  ResourcePolicy::RETAIN  );
896   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
897
898   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
899   DALI_TEST_CHECK( imageTicket );
900   imageTicket->AddObserver( testTicketObserver );
901
902   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
903   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
904   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
905
906   application.SendNotification(); // Flush update queue
907   application.Render(0); // Process message
908   application.SendNotification(); // Send message to tickets
909
910   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
911   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
912   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
913   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
914
915   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
916   DALI_TEST_CHECK ( theBitmap != NULL );
917   DALI_TEST_CHECK ( bitmap == theBitmap );
918   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
919   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
920   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
921   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
922   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
923   END_TEST;
924 }
925
926 int UtcDaliInternalAddBitmapImage02(void)
927 {
928   TestApplication application;
929   tet_infoline("Testing AddBitmap without reserved buffer()");
930   testTicketObserver.Reset();
931   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
932   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  ResourcePolicy::RETAIN  );
933
934   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
935   DALI_TEST_CHECK( imageTicket );
936   imageTicket->AddObserver( testTicketObserver );
937
938   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
939   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
940   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
941   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
942
943   application.SendNotification(); // Flush update queue
944   application.Render(0); // Process message
945   application.SendNotification(); // Send message to tickets
946
947   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
948   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
949   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
950   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
951
952   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
953   DALI_TEST_CHECK ( theBitmap != NULL );
954   DALI_TEST_CHECK ( bitmap == theBitmap );
955   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
956   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
957   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
958   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
959   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
960
961   // There is no way for the ticket's image attributes to be updated if the bitmap
962   // reserves a buffer after ticket generation.
963   // Probably not an issue - there is no public API in BufferImage to change the image size.
964   END_TEST;
965 }
966
967
968 int UtcDaliInternalAddBitmapImage03(void)
969 {
970   TestApplication application;
971   tet_infoline("Testing AddBitmap() with invalid bitmap");
972   testTicketObserver.Reset();
973
974   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
975   Internal::ImageTicketPtr imageTicket;
976   bool exceptionRaised=false;
977   try
978   {
979     imageTicket = resourceClient.AddBitmapImage( NULL );
980   }
981   catch( DaliException& e )
982   {
983     exceptionRaised = true;
984   }
985   DALI_TEST_CHECK( exceptionRaised );
986   DALI_TEST_CHECK( ! imageTicket );
987   END_TEST;
988 }
989
990 int UtcDaliInternalGetBitmapImage01(void)
991 {
992   TestApplication application;
993   tet_infoline("Testing GetBitmap() with valid ticket");
994   testTicketObserver.Reset();
995
996   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
997   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  ResourcePolicy::RETAIN  );
998   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
999   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1000
1001   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1002   DALI_TEST_CHECK ( theBitmap != NULL );
1003   DALI_TEST_CHECK ( bitmap == theBitmap );
1004   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1005   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1006   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1007   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1008   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1009
1010   imageTicket->AddObserver( testTicketObserver );
1011   application.SendNotification(); // Flush update queue
1012   application.Render(0);          // Process message
1013   application.SendNotification(); // Send message to tickets
1014
1015   theBitmap = resourceClient.GetBitmap(imageTicket);
1016   DALI_TEST_CHECK ( theBitmap != NULL );
1017   DALI_TEST_CHECK ( bitmap == theBitmap );
1018   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1019   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1020   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1021   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1022   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1023   END_TEST;
1024 }
1025
1026 int UtcDaliInternalGetBitmapImage02(void)
1027 {
1028   TestApplication application;
1029   tet_infoline("Testing GetBitmap() with invalid ticket");
1030
1031   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1032   Internal::ImageTicketPtr imageTicket;
1033   Integration::Bitmap* theBitmap = NULL;
1034   bool exceptionRaised = false;
1035   try
1036   {
1037     theBitmap = resourceClient.GetBitmap(imageTicket);
1038   } catch (DaliException& e)
1039   {
1040     exceptionRaised = true;
1041   }
1042   DALI_TEST_CHECK( exceptionRaised );
1043   DALI_TEST_CHECK( ! theBitmap );
1044   END_TEST;
1045 }
1046
1047 int UtcDaliInternalGetBitmapImage03(void)
1048 {
1049   TestApplication application;
1050   tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1051
1052   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();  Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1053
1054   Integration::Bitmap* theBitmap = NULL;
1055   theBitmap = resourceClient.GetBitmap(imageTicket);
1056   DALI_TEST_CHECK( ! theBitmap );
1057
1058   END_TEST;
1059 }
1060
1061 int UtcDaliInternalAllocateTexture01(void)
1062 {
1063   TestApplication application;
1064   tet_infoline("Testing AllocateTexture()");
1065   testTicketObserver.Reset();
1066
1067   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1068   Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1069   resourceTicket->AddObserver( testTicketObserver );
1070
1071   DALI_TEST_CHECK( resourceTicket );
1072   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1073   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1074
1075   application.SendNotification(); // Flush update queue
1076   application.Render(0); // Process message
1077   application.SendNotification(); // Send message to tickets
1078
1079   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1080   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1081   END_TEST;
1082 }
1083
1084 int UtcDaliInternalAddNativeImage(void)
1085 {
1086   TestApplication application;
1087   tet_infoline("Testing AddNativeImage()");
1088
1089   testTicketObserver.Reset();
1090   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1091   Internal::ResourceTicketPtr ticket;
1092   Internal::ImageTicketPtr imageTicket;
1093   { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1094     TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1095     ticket = resourceClient.AddNativeImage( *nativeImage );
1096     imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1097     DALI_TEST_CHECK( imageTicket );
1098     imageTicket->AddObserver( testTicketObserver );
1099   }
1100
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_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1105
1106   application.SendNotification(); // Flush update queue
1107   application.Render(0); // Process message
1108   application.SendNotification(); // Send message to tickets
1109
1110   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1111   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1112   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1113   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1114
1115   Integration::Bitmap* theBitmap = NULL;
1116   theBitmap = resourceClient.GetBitmap(imageTicket);
1117
1118   DALI_TEST_CHECK ( theBitmap == NULL );
1119   END_TEST;
1120 }
1121
1122 int UtcDaliInternalAddFrameBufferImage(void)
1123 {
1124   TestApplication application;
1125   tet_infoline("Testing AddFrameBufferImage()");
1126
1127   testTicketObserver.Reset();
1128   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1129   Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1130   DALI_TEST_CHECK( imageTicket );
1131   imageTicket->AddObserver( testTicketObserver );
1132
1133   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1134   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1135   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1136   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1137
1138   application.SendNotification(); // Flush update queue
1139   application.Render(0); // Process message
1140   application.SendNotification(); // Send message to tickets
1141
1142   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1143   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1144   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1145   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1146
1147   Integration::Bitmap* theBitmap = NULL;
1148   theBitmap = resourceClient.GetBitmap(imageTicket);
1149   DALI_TEST_CHECK ( theBitmap == NULL );
1150   END_TEST;
1151 }
1152
1153 int UtcDaliInternalAllocateMesh01(void)
1154 {
1155   TestApplication application;
1156   tet_infoline("Testing AllocateMesh() with vald mesh data");
1157
1158   MeshData publicMeshData;
1159   MeshData::VertexContainer    vertices;
1160   MeshData::FaceIndices        faces;
1161   BoneContainer                bones;
1162   ConstructVertices(vertices, 60);
1163   ConstructFaces(vertices, faces);
1164   Material customMaterial = ConstructMaterial();
1165   publicMeshData.SetData(vertices, faces, bones, customMaterial);
1166   publicMeshData.SetHasNormals(true);
1167   publicMeshData.SetHasTextureCoords(true);
1168
1169   testTicketObserver.Reset();
1170   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1171   Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, ResourcePolicy::DISCARD, true ) );
1172   Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1173   DALI_TEST_CHECK( meshTicket );
1174   meshTicket->AddObserver( testTicketObserver );
1175
1176   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1177
1178   application.SendNotification(); // Flush update queue
1179   application.Render(0); // Process message
1180   application.SendNotification(); // Send message to tickets
1181
1182   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1183   END_TEST;
1184 }