Upload package dali_0.9.11.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-DaliInternal-ResourceClient.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali/dali.h>
21 #include <dali-test-suite-utils.h>
22 #include <test-native-image.h>
23
24 // Internal headers are allowed here
25
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/update/resources/bitmap-metadata.h>
28 #include <dali/internal/update/resources/resource-manager.h>
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/internal/event/resources/resource-client.h>
31 #include <dali/internal/event/resources/resource-ticket.h>
32 #include <dali/internal/event/resources/image-ticket.h>
33 #include <dali/internal/event/resources/resource-ticket-observer.h>
34 #include <dali/internal/event/images/image-impl.h>
35 #include <dali/internal/event/modeling/model-data-impl.h>
36 #include <dali/integration-api/resource-cache.h>
37 #include <dali/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/public-api/shader-effects/shader-effect.h>
41
42
43 using namespace Dali;
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::ImagePtr image = Internal::Image::New(name);
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, false );
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   ImageAttributes attr;
140   Integration::BitmapResourceType bitmapRequest(attr);
141   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
142   ticket->AddObserver(testTicketObserver);
143   application.SendNotification(); // Flush update messages
144   application.Render();           // Process resource request
145   Integration::ResourceRequest*   req = application.GetPlatform().GetRequest();
146   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
147   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h, w, h );
148   Integration::ResourcePointer resourcePtr(bitmap); // reference it
149   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
150   application.Render();           // Process LoadComplete
151   application.SendNotification(); // Process event messages
152   DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
153   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
154   req=NULL;
155   application.GetPlatform().ResetTrace();
156
157   return ticket;
158 }
159
160 Internal::ResourceTicketPtr CheckLoadModel(TestApplication& application, const char* name)
161 {
162   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
163   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), name );
164   ticket->AddObserver(testTicketObserver);
165
166   application.SendNotification(); // Flush update messages
167   application.Render();           // Process resource request
168   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
169   Dali::ModelData modelData = BuildTreeModel();
170   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
171   Integration::ResourcePointer resourcePtr(&modelDataImpl);
172   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
173   application.Render();           // Process LoadComplete
174   application.SendNotification(); // Process event messages
175   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
176   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
177   req=NULL;
178   application.GetPlatform().ResetTrace();
179
180   return ticket;
181 }
182
183 } //anonymous namespace
184
185
186 void utc_dali_internal_resource_client_startup()
187 {
188   test_return_value = TET_UNDEF;
189 }
190
191 void utc_dali_internal_resource_client_cleanup()
192 {
193   test_return_value = TET_PASS;
194 }
195
196 // Load a bitmap resource successfully, then discard it's ticket
197 int UtcDaliInternalRequestResourceBitmapRequests01(void)
198 {
199   TestApplication application; // Reset all test adapter return codes
200
201   tet_infoline("Testing bitmap requests");
202
203   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
204   ImageAttributes attr;
205   Integration::BitmapResourceType bitmapRequest (attr);
206   Internal::ResourceId id(0);
207
208   testTicketObserver.Reset();
209
210   {
211     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
212     /************************************************************
213      * FUNCTION UNDER TEST
214      ***********************************************************/
215     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
216     ticket->AddObserver(testTicketObserver);
217
218     // Update thread will request the bitmap resource:
219     // Sets application.GetPlatform().mRequest
220     application.SendNotification(); // Run flush update queue
221     application.Render(1);          // Process update messages
222     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
223
224     application.SendNotification(); // Send any event messages
225     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
226     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
227     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
228
229     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
230     DALI_TEST_CHECK( imageTicket );
231     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
232     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
233
234     // Create a resource
235     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
236     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
237     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
238     Integration::ResourcePointer resourcePtr(bitmap); // reference it
239
240     // Set up platform abstraction to load it
241     id=req->GetId();
242     application.GetPlatform().SetResourceLoaded( id, Integration::ResourceBitmap, resourcePtr );
243
244     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(req->GetId()) );
245
246     // load the cache, which will immediately have the loaded resource
247     application.Render(0);
248
249     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
250
251     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(req->GetId()) );
252     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(req->GetId());
253     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
254     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
255
256     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
257     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
258
259     // Trigger the event thread to process notify messages. Should then trigger the signals
260     // in the ticket observer
261     application.SendNotification();
262
263     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
264     DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
265
266     // Check that the image ticket was updated with the image attributes
267     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
268     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
269   } // Discard ticket
270
271   application.SendNotification(); // Flush update queue (with ticket discarded message
272   application.Render(1);          // Process update messages
273   application.SendNotification(); // Send event notifications
274   application.Render(1);          // Process update messages
275
276   // Resource should have been discarded.
277   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
278   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
279
280   DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
281   DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
282   END_TEST;
283 }
284
285 // Starting Loading a bitmap resource, then discard it's ticket before loading complete.
286 int UtcDaliInternalRequestResourceBitmapRequests02(void)
287 {
288   TestApplication application; // Reset all test adapter return codes
289
290   tet_infoline("Testing bitmap request ticket discard before load complete");
291
292   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
293   ImageAttributes attr;
294   Integration::BitmapResourceType bitmapRequest (attr);
295   Internal::ResourceId id(0);
296
297   testTicketObserver.Reset();
298
299   {
300     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
301     /************************************************************
302      * FUNCTION UNDER TEST
303      ***********************************************************/
304     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
305     ticket->AddObserver(testTicketObserver);
306     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
307     DALI_TEST_CHECK( imageTicket );
308     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
309     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
310
311     // Update thread will request the bitmap resource:
312     // Sets application.GetPlatform().mRequest
313     application.SendNotification(); // Run flush update queue
314     application.Render(1);
315     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
316     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
317     id=req->GetId();
318
319     application.SendNotification(); // Should produce no messages
320     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
321     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
322
323     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
324
325     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
326     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
327     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
328
329   } // Discard ticket
330
331   // Ensure ticket discarded message is sent to update thread
332   application.SendNotification(); // Flush update queue
333   application.Render(0);          // Process update messages
334
335   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
336   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
337
338   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
339
340   // Trigger the event thread to process notify messages. Should then trigger the signals
341   // in the ticket observer
342   application.SendNotification();
343
344   DALI_TEST_EQUALS(testTicketObserver.LoadSucceededCalled(), 0, TEST_LOCATION );
345   DALI_TEST_EQUALS(testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
346   END_TEST;
347 }
348
349 // start loading a bitmap resource that doesn't exist, then discard it's ticket after failure
350 int UtcDaliInternalRequestResourceBitmapRequests03(void)
351 {
352   TestApplication application; // Reset all test adapter return codes
353
354   tet_infoline("Load bitmap that doesn't exist, followed by ticket discard. Expect LoadingFailed");
355
356   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
357   ImageAttributes attr;
358   Integration::BitmapResourceType bitmapRequest (attr);
359   Internal::ResourceId id(0);
360
361   testTicketObserver.Reset();
362   { // Scope lifetime of ticket
363     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
364
365     /************************************************************
366      * FUNCTION UNDER TEST
367      ***********************************************************/
368     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
369     ticket->AddObserver(testTicketObserver);
370     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
371     DALI_TEST_CHECK( imageTicket );
372     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
373     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
374
375     // Update thread will request the bitmap resource:
376     // Sets application.GetPlatform().mRequest
377     application.SendNotification(); // Run flush update queue
378     application.Render(1);          // process update messages
379     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
380     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
381     id=req->GetId();
382     application.SendNotification(); // Should produce no messages
383     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
384     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
385
386     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
387
388     application.GetPlatform().SetResourceLoadFailed(id, Integration::FailureFileNotFound );
389
390     application.Render(0); // Get failed result
391     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
392     application.SendNotification(); // send failed
393     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() != 0 );
394     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingFailed );
395
396     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
397     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
398     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
399
400     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
401   } // Discard ticket
402
403   application.Render(0); // Send DiscardTicket
404   application.SendNotification();
405
406   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
407   END_TEST;
408 }
409
410
411
412 // Load a bitmap resource successfully, then reload it
413 int UtcDaliInternalRequestReloadBitmapRequests01(void)
414 {
415   TestApplication application; // Reset all test adapter return codes
416
417   tet_infoline("Testing bitmap reload after successful load");
418
419   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
420   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
421
422   Internal::ResourceId id(0);
423   testTicketObserver.Reset();
424
425   {
426     Internal::ResourceTicketPtr ticket = CheckLoadBitmap( application, "image.png", 80, 80 );
427     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
428     id = ticket->GetId();
429
430     // Reset call statistics - test that resource is reloaded
431     application.GetPlatform().ResetTrace();
432
433     /************************************************************
434      * FUNCTION UNDER TEST
435      ***********************************************************/
436     resourceClient.ReloadResource( ticket->GetId() );
437
438     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
439     application.SendNotification(); // Flush update messages
440     application.Render(0);  // Process update messages
441     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
442     application.SendNotification(); // Process event messages
443
444     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
445     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
446     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
447     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
448
449     // Create a new resource - the image size could have changed in the meantime
450     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
451     Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
452     bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
453     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
454     DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
455     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
456
457     application.Render(0);  // Process update messages / UpdateCache
458     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
459
460     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
461     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
462     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
463     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
464
465     // Ticket can't have been updated yet - it should still have old values
466     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
467     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
468
469     application.SendNotification(); // Process event messages
470     application.Render(0);          // Process update messages / UpdateCache
471     application.SendNotification(); // Process event messages
472
473     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
474     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
475     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
476     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
477     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
478
479   } // Discard ticket
480
481   application.SendNotification(); // Flush update queue (with ticket discarded message
482   application.Render(1);          // Process update messages
483   application.SendNotification(); // Send event notifications
484   application.Render(1);          // Process update messages
485
486   // Resource should have been discarded.
487   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
488   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
489
490   DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
491   DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
492   DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
493   END_TEST;
494 }
495
496
497 int UtcDaliInternalRequestReloadBitmapRequests02(void)
498 {
499   TestApplication application; // Reset all test adapter return codes
500
501   tet_infoline("Testing bitmap reload during first load");
502
503   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
504   ImageAttributes attr;
505   Integration::BitmapResourceType bitmapRequest (attr);
506   Internal::ResourceId id(0);
507
508   testTicketObserver.Reset();
509
510   {
511     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
512     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
513     ticket->AddObserver(testTicketObserver);
514
515     // Update thread will request the bitmap resource:
516     // Sets application.GetPlatform().mRequest
517     application.SendNotification(); // Run flush update queue
518     application.Render(1);          // Process update messages
519     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
520
521     application.SendNotification(); // Send any event messages
522     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
523     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
524
525     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
526     DALI_TEST_CHECK( imageTicket );
527     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
528     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
529
530
531     /************************************************************
532      * FUNCTION UNDER TEST
533      ***********************************************************/
534     resourceClient.ReloadResource( ticket->GetId() );
535     /************************************************************
536      * Expected result - current load completes as usual, no reload requested
537      ************************************************************/
538
539     application.SendNotification(); // Flush update methods
540
541     // Reset call statistics - test that resource is not reloaded
542     application.GetPlatform().ResetTrace();
543
544     application.Render(0); // Process reload message (nothing for UpdateCache yet)
545
546     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
547     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
548     // Create a resource
549     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
550     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
551     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
552     Integration::ResourcePointer resourcePtr(bitmap); // reference it
553
554     // Set up platform abstraction to load it
555     id=req->GetId();
556
557     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
558
559     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
560
561     application.GetPlatform().ResetTrace();
562     // load the cache, which will immediately have the loaded resource
563     application.Render(0);
564     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
565     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
566     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
567     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
568     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
569
570     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
571     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
572
573     // Trigger the event thread to process notify messages. Should then trigger the signals
574     // in the ticket observer
575     application.SendNotification();
576
577     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
578     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
579     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
580
581     // Check that the image ticket was updated with the image attributes
582     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
583     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
584
585     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
586
587     application.SendNotification(); // Flush update messages
588     application.Render(0);  // Process update messages
589
590     // There should be no reload
591     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
592     application.SendNotification(); // Process event messages
593
594     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
595     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
596     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
597     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
598
599     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
600     bitmapData = resourceManager.GetBitmapMetadata(id);
601     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
602     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
603     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
604     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
605
606   } // Discard ticket
607   END_TEST;
608 }
609
610
611 int UtcDaliInternalRequestReloadBitmapRequests03(void)
612 {
613   TestApplication application; // Reset all test adapter return codes
614
615   tet_infoline("Testing bitmap reload at end of first load");
616
617   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
618   ImageAttributes attr;
619   Integration::BitmapResourceType bitmapRequest (attr);
620   Internal::ResourceId id(0);
621
622   testTicketObserver.Reset();
623
624   {
625     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
626     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
627     ticket->AddObserver(testTicketObserver);
628
629     // Update thread will request the bitmap resource:
630     // Sets application.GetPlatform().mRequest
631     application.SendNotification(); // Run flush update queue
632     application.Render(1);          // Process update messages
633     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
634
635     application.SendNotification(); // Send any event messages
636     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
637     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
638
639     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
640     DALI_TEST_CHECK( imageTicket );
641     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
642     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
643
644
645     /************************************************************
646      * FUNCTION UNDER TEST
647      ***********************************************************/
648     resourceClient.ReloadResource( ticket->GetId() );
649     /************************************************************
650      * Expected result - current load completes as usual, no reload requested
651      ************************************************************/
652
653     application.SendNotification(); // Flush update methods
654
655     // Reset call statistics - test that resource is not reloaded
656     application.GetPlatform().ResetTrace();
657
658     // Create a resource
659     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
660     Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
661     bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80, 80, 80, 80 );
662     Integration::ResourcePointer resourcePtr(bitmap); // reference it
663
664     // Set up platform abstraction to load it
665     id=req->GetId();
666
667     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr);
668
669     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
670
671     application.GetPlatform().ResetTrace();
672     // load the cache, which will immediately have the loaded resource
673     application.Render(0);
674
675     // UpdateCache runs before ProcessMessages, so the loading resource completes before
676     // the reload request is handled.
677     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
678     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
679
680     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
681     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
682     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
683     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
684
685     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
686     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
687
688     // Trigger the event thread to process notify messages. Should then trigger the signals
689     // in the ticket observer
690     application.SendNotification();
691
692     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
693     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
694     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
695
696     // Check that the image ticket was updated with the image attributes
697     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
698     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
699
700     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
701
702     // Create a new resource - the image size could have changed in the meantime
703     req = application.GetPlatform().GetRequest();
704     Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
705     bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 120, 120, 120, 120 );
706     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
707     DALI_TEST_CHECK( req->GetId() == id );
708     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceBitmap, resourcePtr2);
709
710     application.Render(0);  // Process update messages / UpdateCache
711
712     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
713     bitmapData = resourceManager.GetBitmapMetadata(id);
714     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
715     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
716     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
717     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
718
719     application.SendNotification(); // Process event messages
720
721     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
722
723     // Not staged - no GL upload
724     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
725
726     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
727     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
728     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
729     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
730   }
731   END_TEST;
732 }
733
734
735 int UtcDaliInternalSaveResource01(void)
736 {
737   TestApplication application;
738   tet_infoline("Testing SaveResource() with valid id, and valid filename");
739
740   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
741
742   Dali::ModelData modelData = BuildTreeModel();
743   testTicketObserver.Reset();
744
745   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
746   ticket->AddObserver(testTicketObserver);
747
748   // First, load a model resource
749   application.SendNotification(); // Flush update messages
750   application.Render();           // Process resource request
751   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
752   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
753   Integration::ResourcePointer resourcePtr(&modelDataImpl);
754
755   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
756   application.Render();           // Process LoadComplete
757   application.SendNotification(); // Process event messages
758   DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
759
760   // Try saving it
761   resourceClient.SaveResource( ticket, "model.dali-bin" );
762   application.SendNotification(); // Flush update messages
763   application.Render();           // Process save resource request
764
765   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
766   req = application.GetPlatform().GetRequest();
767   DALI_TEST_CHECK( req->GetType()->id == Integration::ResourceModel );
768   DALI_TEST_CHECK( req->GetPath().compare("model.dali-bin") == 0 );
769
770   // Set up success response
771   application.GetPlatform().SetResourceSaved(req->GetId(), req->GetType()->id);
772   application.Render();           // GetResources --> SaveComplete
773   application.SendNotification(); // Send event messages
774
775   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 1 );
776   DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
777 ;
778   END_TEST;
779 }
780
781
782 int UtcDaliInternalSaveResource02(void)
783 {
784   TestApplication application;
785   tet_infoline("Testing SaveResource() with invalid id");
786   testTicketObserver.Reset();
787
788   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
789
790   Dali::ModelData modelData = BuildTreeModel();
791
792   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
793   ticket->AddObserver(testTicketObserver);
794
795   // First, load a model resource
796   application.SendNotification(); // Flush update messages
797   application.Render();           // Process resource request
798   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
799   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
800   Integration::ResourcePointer resourcePtr(&modelDataImpl);
801   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
802   application.Render();           // Process LoadComplete
803   application.SendNotification(); // Process event messages
804   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
805   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
806
807   Internal::ResourceTypePath typePath(Integration::ModelResourceType(), "");
808   Internal::ResourceTicketPtr aTicket = new Internal::ResourceTicket( testTicketLifetimeObserver, 2000,  typePath );
809   try
810   {
811     resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
812   } catch (DaliException& e)
813   {
814     // Tests that a negative test of an assertion succeeds
815     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
816
817     DALI_TEST_ASSERT(e, "mImpl->mTickets.find(ticket->GetId()) != mImpl->mTickets.end()", TEST_LOCATION );
818   }
819
820   application.SendNotification(); // Flush update messages
821   application.Render();           // Process save resource request
822
823   // Ensure no request sent to platform abstraction
824   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
825   req = application.GetPlatform().GetRequest();
826   DALI_TEST_CHECK ( req == NULL );
827   END_TEST;
828 }
829
830 int UtcDaliInternalSaveResource03(void)
831 {
832   TestApplication application;
833   tet_infoline("Testing SaveResource() with invalid id");
834   testTicketObserver.Reset();
835
836   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
837
838   Dali::ModelData modelData = BuildTreeModel();
839
840   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
841   ticket->AddObserver(testTicketObserver);
842
843   // First, load a model resource
844   application.SendNotification(); // Flush update messages
845   application.Render();           // Process resource request
846   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
847   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
848   Integration::ResourcePointer resourcePtr(&modelDataImpl);
849   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
850   application.Render();           // Process LoadComplete
851   application.SendNotification(); // Process event messages
852   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
853   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
854
855   Internal::ResourceTicketPtr aTicket;
856   try
857   {
858     resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
859   } catch (DaliException& e)
860   {
861     // Tests that a negative test of an assertion succeeds
862     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
863
864     DALI_TEST_EQUALS(e.mCondition, "ticket", TEST_LOCATION);
865   }
866
867   application.SendNotification(); // Flush update messages
868   application.Render();           // Process save resource request
869
870   // Ensure no request sent to platform abstraction
871   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
872   req = application.GetPlatform().GetRequest();
873   DALI_TEST_CHECK ( req == NULL );
874   END_TEST;
875 }
876
877
878 int UtcDaliInternalSaveResource04(void)
879 {
880   TestApplication application;
881   tet_infoline("Testing SaveResource() with valid id, but invalid filename");
882   testTicketObserver.Reset();
883
884   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
885
886   // First, load a model resource
887   Internal::ResourceTicketPtr ticket = CheckLoadModel(application, "model.dae");
888
889   resourceClient.SaveResource( ticket, "model.dali-bin" );
890   application.SendNotification(); // Flush update messages
891   application.Render();           // Process save resource request
892
893   // Set up fail response
894   application.GetPlatform().SetResourceSaveFailed(ticket->GetId(), Integration::FailureInvalidPath );
895   application.Render();           // GetResources --> SaveFailed
896   application.SendNotification(); // Send event messages
897
898   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 0 );
899   DALI_TEST_CHECK( testTicketObserver.SaveFailedCalled() == 1 );
900   DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
901 ;
902   END_TEST;
903 }
904
905 int UtcDaliInternalSaveResource05(void)
906 {
907   TestApplication application;
908   tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
909   testTicketObserver.Reset();
910
911   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
912
913   // First, load a bitmap resource
914   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
915
916   // Try saving it
917   resourceClient.SaveResource( ticket, "bitmap.png" );
918   application.SendNotification(); // Flush update messages
919   application.Render();           // Process save resource request
920
921   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
922   END_TEST;
923 }
924
925 int UtcDaliInternalRequestResourceTicket01(void)
926 {
927   TestApplication application;
928   tet_infoline("Testing RequestResourceTicket() with valid id");
929
930   testTicketObserver.Reset();
931
932   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
933
934   // First, load a bitmap resource
935   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
936
937   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
938   DALI_TEST_CHECK( newTicket );
939   DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
940   DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
941   END_TEST;
942 }
943
944 int UtcDaliInternalRequestResourceTicket02(void)
945 {
946   TestApplication application;
947   tet_infoline("Testing RequestResourceTicket() with invalid id");
948
949   testTicketObserver.Reset();
950
951   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
952
953   // First, load a bitmap resource
954   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
955
956   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
957   DALI_TEST_CHECK( ! newTicket );
958   END_TEST;
959 }
960
961 int UtcDaliInternalLoadShaderRequest01(void)
962 {
963   TestApplication application;
964   tet_infoline("Testing LoadShader() success");
965   testTicketObserver.Reset();
966
967   // Clear through all of the outstanding shader load requests from the default shader effect
968   std::vector< unsigned char > buffer;
969   for( int i=0; i<10; i++ )
970   {
971     buffer.push_back((unsigned char)i);
972   }
973   application.GetPlatform().SetLoadFileResult( true, buffer );
974   application.GetGlAbstraction().SetLinkStatus(1);
975   application.SendNotification(); // Flush update messages
976   application.Render();           // Process load shader request (immediately)
977   application.SendNotification();
978   application.Render();
979   application.SendNotification();
980   application.Render();
981   application.SendNotification();
982
983   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
984
985   Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
986   std::string shaderBinaryFile("shader.bin");
987   Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
988   DALI_TEST_CHECK( ticket );
989
990   application.GetPlatform().SetLoadFileResult( true, buffer );
991   application.GetGlAbstraction().EnableShaderCallTrace( true );
992   application.GetGlAbstraction().SetLinkStatus(1);
993
994   application.SendNotification(); // Flush update messages
995   application.Render();           // Process load shader request (immediately)
996
997   application.SendNotification();
998   application.Render();
999
1000   application.SendNotification();
1001   application.Render();
1002
1003   // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
1004   TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1005   DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
1006
1007   // Ensure no request sent to platform abstraction
1008   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1009   END_TEST;
1010 }
1011
1012 int UtcDaliInternalLoadShaderRequest02(void)
1013 {
1014   TestApplication application;
1015   tet_infoline("Testing LoadShader() failure");
1016   testTicketObserver.Reset();
1017
1018   // Clear through all of the outstanding shader load requests from the default shader effect
1019   std::vector< unsigned char > buffer;
1020   for( int i=0; i<10; i++ )
1021   {
1022     buffer.push_back((unsigned char)i);
1023   }
1024   application.GetPlatform().SetLoadFileResult( true, buffer );
1025   application.GetGlAbstraction().SetLinkStatus(1);
1026   application.SendNotification(); // Flush update messages
1027   application.Render();           // Process load shader request (immediately)
1028   application.SendNotification();
1029   application.Render();
1030   application.SendNotification();
1031   application.Render();
1032   application.SendNotification();
1033
1034   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1035   Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
1036
1037   Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
1038   std::string shaderBinaryFile("shader.bin");
1039   Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
1040   ticket->AddObserver(testTicketObserver);
1041
1042   ShaderEffect::GeometryHints hints = ShaderEffect::HINT_NONE;
1043   Internal::SceneGraph::Shader* sceneObject = new Internal::SceneGraph::Shader( hints );
1044   AddShaderMessage( updateManager, *sceneObject );
1045
1046   size_t shaderHash=0;
1047   SetShaderProgramMessage( updateManager, *sceneObject, GEOMETRY_TYPE_IMAGE, Internal::SHADER_DEFAULT, ticket->GetId(), shaderHash );
1048
1049   DALI_TEST_CHECK( ticket );
1050
1051   buffer.clear();
1052   DALI_TEST_CHECK(buffer.size() == 0);
1053
1054   application.GetPlatform().SetLoadFileResult( true, buffer );
1055   application.GetGlAbstraction().ResetShaderCallStack();
1056   application.GetGlAbstraction().EnableShaderCallTrace( true );
1057   application.GetGlAbstraction().SetLinkStatus(1);
1058   application.GetGlAbstraction().SetProgramBinaryLength(20);
1059   application.GetPlatform().SetResourceSaved (ticket->GetId(), Integration::ResourceShader );
1060
1061   application.SendNotification(); // Flush update messages
1062   application.Render();           // Process load shader request (immediately), add responses
1063                                   // to post process q
1064   application.Render();           // this update will process old post-process-q
1065   application.Render();           // this update will process new post-process-q
1066   application.SendNotification(); // Send save request to event thread
1067   application.Render();           // this update will process save request
1068   application.Render();           // this update will get SaveComplete
1069   application.SendNotification(); // Send save request response
1070
1071   TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1072   DALI_TEST_CHECK( shaderTrace.FindMethod("CompileShader") );
1073
1074   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1075   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() );
1076   END_TEST;
1077 }
1078
1079 int UtcDaliInternalAllocateBitmapImage01(void)
1080 {
1081   TestApplication application;
1082   tet_infoline("Testing AllocateBitmapImage()");
1083   testTicketObserver.Reset();
1084
1085   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1086   Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1087   imageTicket->AddObserver( testTicketObserver );
1088
1089   DALI_TEST_CHECK( imageTicket );
1090   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1091   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1092   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1093   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1094
1095   application.SendNotification(); // Flush update queue
1096   application.Render(0); // Process message
1097   application.SendNotification(); // Send message to tickets
1098
1099   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1100   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1101   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1102   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1103   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1104
1105   Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1106   DALI_TEST_CHECK ( bitmap != NULL );
1107   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1108   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1109   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1110   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1111   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1112   END_TEST;
1113 }
1114
1115 int UtcDaliInternalAddBitmapImage01(void)
1116 {
1117   TestApplication application;
1118   tet_infoline("Testing AddBitmap with reserved buffer()");
1119   testTicketObserver.Reset();
1120   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1121   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1122   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1123
1124   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1125   DALI_TEST_CHECK( imageTicket );
1126   imageTicket->AddObserver( testTicketObserver );
1127
1128   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1129   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1130   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1131   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1132
1133   application.SendNotification(); // Flush update queue
1134   application.Render(0); // Process message
1135   application.SendNotification(); // Send message to tickets
1136
1137   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1138   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1139   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1140   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1141   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1142
1143   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1144   DALI_TEST_CHECK ( theBitmap != NULL );
1145   DALI_TEST_CHECK ( bitmap == theBitmap );
1146   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1147   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1148   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1149   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1150   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1151   END_TEST;
1152 }
1153
1154 int UtcDaliInternalAddBitmapImage02(void)
1155 {
1156   TestApplication application;
1157   tet_infoline("Testing AddBitmap without reserved buffer()");
1158   testTicketObserver.Reset();
1159   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1160   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1161
1162   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1163   DALI_TEST_CHECK( imageTicket );
1164   imageTicket->AddObserver( testTicketObserver );
1165
1166   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1167   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1168   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1169   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1170   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1171
1172   application.SendNotification(); // Flush update queue
1173   application.Render(0); // Process message
1174   application.SendNotification(); // Send message to tickets
1175
1176   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1177   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1178   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1179   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1180   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1181
1182   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1183   DALI_TEST_CHECK ( theBitmap != NULL );
1184   DALI_TEST_CHECK ( bitmap == theBitmap );
1185   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1186   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1187   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1188   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1189   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1190
1191   // There is no way for the ticket's image attributes to be updated if the bitmap
1192   // reserves a buffer after ticket generation.
1193   // Probably not an issue - there is no public API in BufferImage to change the image size.
1194   END_TEST;
1195 }
1196
1197
1198 int UtcDaliInternalAddBitmapImage03(void)
1199 {
1200   TestApplication application;
1201   tet_infoline("Testing AddBitmap() with invalid bitmap");
1202   testTicketObserver.Reset();
1203
1204   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1205   Internal::ImageTicketPtr imageTicket;
1206   bool exceptionRaised=false;
1207   try
1208   {
1209     imageTicket = resourceClient.AddBitmapImage( NULL );
1210   }
1211   catch( DaliException& e )
1212   {
1213     exceptionRaised = true;
1214   }
1215   DALI_TEST_CHECK( exceptionRaised );
1216   DALI_TEST_CHECK( ! imageTicket );
1217   END_TEST;
1218 }
1219
1220 int UtcDaliInternalGetBitmapImage01(void)
1221 {
1222   TestApplication application;
1223   tet_infoline("Testing GetBitmap() with valid ticket");
1224   testTicketObserver.Reset();
1225
1226   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1227   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1228   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1229   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1230
1231   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1232   DALI_TEST_CHECK ( theBitmap != NULL );
1233   DALI_TEST_CHECK ( bitmap == theBitmap );
1234   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1235   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1236   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1237   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1238   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1239
1240   imageTicket->AddObserver( testTicketObserver );
1241   application.SendNotification(); // Flush update queue
1242   application.Render(0);          // Process message
1243   application.SendNotification(); // Send message to tickets
1244
1245   theBitmap = resourceClient.GetBitmap(imageTicket);
1246   DALI_TEST_CHECK ( theBitmap != NULL );
1247   DALI_TEST_CHECK ( bitmap == theBitmap );
1248   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1249   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1250   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1251   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1252   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1253   END_TEST;
1254 }
1255
1256 int UtcDaliInternalGetBitmapImage02(void)
1257 {
1258   TestApplication application;
1259   tet_infoline("Testing GetBitmap() with invalid ticket");
1260
1261   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1262   Internal::ImageTicketPtr imageTicket;
1263   Integration::Bitmap* theBitmap = NULL;
1264   bool exceptionRaised = false;
1265   try
1266   {
1267     theBitmap = resourceClient.GetBitmap(imageTicket);
1268   } catch (DaliException& e)
1269   {
1270     exceptionRaised = true;
1271   }
1272   DALI_TEST_CHECK( exceptionRaised );
1273   DALI_TEST_CHECK( ! theBitmap );
1274   END_TEST;
1275 }
1276
1277 int UtcDaliInternalGetBitmapImage03(void)
1278 {
1279   TestApplication application;
1280   tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1281
1282   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();  Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1283   Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1284
1285   Integration::Bitmap* theBitmap = NULL;
1286   theBitmap = resourceClient.GetBitmap(imageTicket);
1287   DALI_TEST_CHECK( ! theBitmap );
1288
1289   theBitmap = resourceClient.GetBitmap(modelTicket);
1290   DALI_TEST_CHECK( ! theBitmap );
1291   END_TEST;
1292 }
1293
1294 int UtcDaliInternalAllocateTexture01(void)
1295 {
1296   TestApplication application;
1297   tet_infoline("Testing AllocateTexture()");
1298   testTicketObserver.Reset();
1299
1300   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1301   Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1302   resourceTicket->AddObserver( testTicketObserver );
1303
1304   DALI_TEST_CHECK( resourceTicket );
1305   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1306   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1307
1308   application.SendNotification(); // Flush update queue
1309   application.Render(0); // Process message
1310   application.SendNotification(); // Send message to tickets
1311
1312   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1313   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1314   END_TEST;
1315 }
1316
1317 int UtcDaliInternalAddNativeImage(void)
1318 {
1319   TestApplication application;
1320   tet_infoline("Testing AddNativeImage()");
1321
1322   testTicketObserver.Reset();
1323   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1324   Internal::ResourceTicketPtr ticket;
1325   Internal::ImageTicketPtr imageTicket;
1326   { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1327     TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1328     ticket = resourceClient.AddNativeImage( *nativeImage );
1329     imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1330     DALI_TEST_CHECK( imageTicket );
1331     imageTicket->AddObserver( testTicketObserver );
1332   }
1333
1334   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1335   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1336   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1337   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1338
1339   application.SendNotification(); // Flush update queue
1340   application.Render(0); // Process message
1341   application.SendNotification(); // Send message to tickets
1342
1343   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1344   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1345   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1346   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1347
1348   Integration::Bitmap* theBitmap = NULL;
1349   theBitmap = resourceClient.GetBitmap(imageTicket);
1350
1351   DALI_TEST_CHECK ( theBitmap == NULL );
1352   END_TEST;
1353 }
1354
1355 int UtcDaliInternalAddFrameBufferImage(void)
1356 {
1357   TestApplication application;
1358   tet_infoline("Testing AddFrameBufferImage()");
1359
1360   testTicketObserver.Reset();
1361   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1362   Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1363   DALI_TEST_CHECK( imageTicket );
1364   imageTicket->AddObserver( testTicketObserver );
1365
1366   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1367   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1368   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1369   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1370   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1371
1372   application.SendNotification(); // Flush update queue
1373   application.Render(0); // Process message
1374   application.SendNotification(); // Send message to tickets
1375
1376   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1377   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1378   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1379   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1380   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1381
1382   Integration::Bitmap* theBitmap = NULL;
1383   theBitmap = resourceClient.GetBitmap(imageTicket);
1384   DALI_TEST_CHECK ( theBitmap == NULL );
1385   END_TEST;
1386 }
1387
1388 int UtcDaliInternalAllocateMesh01(void)
1389 {
1390   TestApplication application;
1391   tet_infoline("Testing AllocateMesh() with vald mesh data");
1392
1393   MeshData publicMeshData;
1394   MeshData::VertexContainer    vertices;
1395   MeshData::FaceIndices        faces;
1396   BoneContainer                bones;
1397   ConstructVertices(vertices, 60);
1398   ConstructFaces(vertices, faces);
1399   Material customMaterial = ConstructMaterial();
1400   publicMeshData.SetData(vertices, faces, bones, customMaterial);
1401   publicMeshData.SetHasNormals(true);
1402   publicMeshData.SetHasTextureCoords(true);
1403
1404   testTicketObserver.Reset();
1405   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1406   Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, true, true ) );
1407   Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1408   DALI_TEST_CHECK( meshTicket );
1409   meshTicket->AddObserver( testTicketObserver );
1410
1411   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1412
1413   application.SendNotification(); // Flush update queue
1414   application.Render(0); // Process message
1415   application.SendNotification(); // Send message to tickets
1416
1417   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1418   END_TEST;
1419 }