Bitmap core patch 2 of 4 - Replace all uses of the Bitmap class with new simpler...
[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 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/integration-api/image-data.h>
38 #include <dali/integration-api/resource-types.h>
39 #include <dali/internal/render/gl-resources/texture-declarations.h>
40 #include <dali/internal/render/shaders/shader.h>
41 #include <dali/internal/common/owner-pointer.h>
42 #include <dali/public-api/shader-effects/shader-effect.h>
43
44
45 using namespace Dali;
46 #include <mesh-builder.h>
47
48 namespace
49 {
50
51 class TestTicketObserver : public Internal::ResourceTicketObserver
52 {
53 public:
54   TestTicketObserver()
55   : mLoadingFailedCalled(0), mLoadingSucceededCalled(0),
56     mSavingFailedCalled(0), mSavingSucceededCalled(0),
57     mUploadedCount(0)
58   {}
59
60   int LoadFailedCalled() {
61     tet_printf("TicketObserver: LoadingFailed() called %d times", mLoadingFailedCalled);
62     return mLoadingFailedCalled;
63   }
64   int LoadSucceededCalled() {
65     tet_printf("TicketObserver: LoadingSucceeded()  called %d times", mLoadingSucceededCalled);
66     return mLoadingSucceededCalled;
67   }
68   int SaveFailedCalled() {
69     tet_printf("TicketObserver: SavingFailed() called %d times", mSavingFailedCalled);
70     return mSavingFailedCalled;
71   }
72   int SaveSucceededCalled() {
73     tet_printf("TicketObserver: SavingSucceeded() called %d times", mSavingSucceededCalled);
74     return mSavingSucceededCalled;
75   }
76   int  UploadCalled() {
77     tet_printf("TicketObserver: Uploaded() called %d times", mUploadedCount);
78     return mUploadedCount;
79   }
80   void Reset() {
81     mLoadingFailedCalled    = 0;
82     mLoadingSucceededCalled = 0;
83     mSavingFailedCalled     = 0;
84     mSavingSucceededCalled  = 0;
85     mUploadedCount           = 0;
86   }
87
88 public: // From ResourceTicketObserver
89   virtual void ResourceLoadingFailed(const Internal::ResourceTicket& ticket) {mLoadingFailedCalled++;}
90   virtual void ResourceLoadingSucceeded(const Internal::ResourceTicket& ticket) {mLoadingSucceededCalled++;}
91   virtual void ResourceSavingFailed(const Internal::ResourceTicket& ticket) {mSavingFailedCalled++;}
92   virtual void ResourceSavingSucceeded(const Internal::ResourceTicket& ticket) {mSavingSucceededCalled++;}
93   virtual void ResourceUploaded(const Internal::ResourceTicket& ticket) {mUploadedCount++;}
94
95 private:
96   int mLoadingFailedCalled;
97   int mLoadingSucceededCalled;
98   int mSavingFailedCalled;
99   int mSavingSucceededCalled;
100   int mUploadedCount;
101 };
102
103 class TestTicketLifetimeObserver : public Internal::ResourceTicketLifetimeObserver
104 {
105 public:
106   TestTicketLifetimeObserver() : resourceTicketDiscarded(false) {}
107
108   virtual void ResourceTicketDiscarded( const Internal::ResourceTicket& ticket )
109   { resourceTicketDiscarded = true; }
110
111   void Reset() { resourceTicketDiscarded = false; }
112   bool resourceTicketDiscarded;
113 };
114
115 static TestTicketObserver testTicketObserver;
116 static TestTicketLifetimeObserver testTicketLifetimeObserver;
117
118
119 Internal::ImagePtr LoadImage(TestApplication& application, char* name)
120 {
121   Internal::ImagePtr image = Internal::Image::New(name);
122   application.SendNotification(); // Flush update messages
123   application.Render();           // Process resource request
124   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
125   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
126   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 80,80,80,80 );
127   Integration::ResourcePointer resourcePtr(bitmap); // reference it
128   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
129   application.Render();           // Process LoadComplete
130   application.SendNotification(); // Process event messages
131   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
132   req=NULL;
133   application.GetPlatform().ResetTrace();
134   return image;
135 }
136
137
138 Internal::ResourceTicketPtr CheckLoadBitmap(TestApplication& application, const char* name, int w, int h)
139 {
140   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
141   ImageAttributes attr;
142   Integration::ImageResourceType bitmapRequest( Integration::ResourceImageData, attr);
143   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, name );
144   ticket->AddObserver(testTicketObserver);
145   application.SendNotification(); // Flush update messages
146   application.Render();           // Process resource request
147   Integration::ResourceRequest*   req = application.GetPlatform().GetRequest();
148   Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( w, h, Pixel::RGBA8888 );
149   Integration::ResourcePointer resourcePtr(bitmap); // reference it
150   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
151   application.Render();           // Process LoadComplete
152   application.SendNotification(); // Process event messages
153   DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
154   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
155   req=NULL;
156   application.GetPlatform().ResetTrace();
157
158   return ticket;
159 }
160
161 Internal::ResourceTicketPtr CheckLoadModel(TestApplication& application, const char* name)
162 {
163   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
164   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), name );
165   ticket->AddObserver(testTicketObserver);
166
167   application.SendNotification(); // Flush update messages
168   application.Render();           // Process resource request
169   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
170   Dali::ModelData modelData = BuildTreeModel();
171   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
172   Integration::ResourcePointer resourcePtr(&modelDataImpl);
173   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
174   application.Render();           // Process LoadComplete
175   application.SendNotification(); // Process event messages
176   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
177   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
178   req=NULL;
179   application.GetPlatform().ResetTrace();
180
181   return ticket;
182 }
183
184 } //anonymous namespace
185
186
187 void utc_dali_internal_resource_client_startup()
188 {
189   test_return_value = TET_UNDEF;
190 }
191
192 void utc_dali_internal_resource_client_cleanup()
193 {
194   test_return_value = TET_PASS;
195 }
196
197 // Load a bitmap resource successfully, then discard it's ticket
198 int UtcDaliInternalRequestResourceBitmapRequests01(void)
199 {
200   TestApplication application; // Reset all test adapter return codes
201
202   tet_infoline("Testing bitmap requests");
203
204   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
205   ImageAttributes attr;
206   Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
207   Internal::ResourceId id(0);
208
209   testTicketObserver.Reset();
210
211   {
212     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
213     /************************************************************
214      * FUNCTION UNDER TEST
215      ***********************************************************/
216     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
217     ticket->AddObserver(testTicketObserver);
218
219     // Update thread will request the bitmap resource:
220     // Sets application.GetPlatform().mRequest
221     application.SendNotification(); // Run flush update queue
222     application.Render(1);          // Process update messages
223     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
224
225     application.SendNotification(); // Send any event messages
226     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
227     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
228     DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoading );
229
230     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
231     DALI_TEST_CHECK( imageTicket );
232     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
233     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
234
235     // Create a resource
236     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
237     Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
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::ResourceImageData, 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::ImageResourceType bitmapRequest (Integration::ResourceImageData, 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::ImageResourceType bitmapRequest (Integration::ResourceImageData, 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::ImageDataPtr bitmap2 = Integration::NewBitmapImageData( 120, 120, Pixel::RGBA8888 );
452     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
453     DALI_TEST_CHECK( req->GetId() == ticket->GetId() );
454     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr2);
455
456     application.Render(0);  // Process update messages / UpdateCache
457     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
458
459     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
460     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
461     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
462     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
463
464     // Ticket can't have been updated yet - it should still have old values
465     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
466     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
467
468     application.SendNotification(); // Process event messages
469     application.Render(0);          // Process update messages / UpdateCache
470     application.SendNotification(); // Process event messages
471
472     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
473     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
474     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
475     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
476     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
477
478   } // Discard ticket
479
480   application.SendNotification(); // Flush update queue (with ticket discarded message
481   application.Render(1);          // Process update messages
482   application.SendNotification(); // Send event notifications
483   application.Render(1);          // Process update messages
484
485   // Resource should have been discarded.
486   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::CancelLoadFunc ) );
487   DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
488
489   DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
490   DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
491   DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
492   END_TEST;
493 }
494
495
496 int UtcDaliInternalRequestReloadBitmapRequests02(void)
497 {
498   TestApplication application; // Reset all test adapter return codes
499
500   tet_infoline("Testing bitmap reload during first load");
501
502   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
503   ImageAttributes attr;
504   Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
505   Internal::ResourceId id(0);
506
507   testTicketObserver.Reset();
508
509   {
510     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
511     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
512     ticket->AddObserver(testTicketObserver);
513
514     // Update thread will request the bitmap resource:
515     // Sets application.GetPlatform().mRequest
516     application.SendNotification(); // Run flush update queue
517     application.Render(1);          // Process update messages
518     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
519
520     application.SendNotification(); // Send any event messages
521     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
522     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
523
524     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
525     DALI_TEST_CHECK( imageTicket );
526     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
527     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
528
529
530     /************************************************************
531      * FUNCTION UNDER TEST
532      ***********************************************************/
533     resourceClient.ReloadResource( ticket->GetId() );
534     /************************************************************
535      * Expected result - current load completes as usual, no reload requested
536      ************************************************************/
537
538     application.SendNotification(); // Flush update methods
539
540     // Reset call statistics - test that resource is not reloaded
541     application.GetPlatform().ResetTrace();
542
543     application.Render(0); // Process reload message (nothing for UpdateCache yet)
544
545     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
546     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
547     // Create a resource
548     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
549     Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
550     Integration::ResourcePointer resourcePtr(bitmap); // reference it
551
552     // Set up platform abstraction to load it
553     id=req->GetId();
554
555     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr);
556
557     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
558
559     application.GetPlatform().ResetTrace();
560     // load the cache, which will immediately have the loaded resource
561     application.Render(0);
562     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
563     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
564     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
565     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
566     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
567
568     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
569     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
570
571     // Trigger the event thread to process notify messages. Should then trigger the signals
572     // in the ticket observer
573     application.SendNotification();
574
575     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
576     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
577     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
578
579     // Check that the image ticket was updated with the image attributes
580     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
581     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
582
583     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
584
585     application.SendNotification(); // Flush update messages
586     application.Render(0);  // Process update messages
587
588     // There should be no reload
589     DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
590     application.SendNotification(); // Process event messages
591
592     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
593     DALI_TEST_EQUALS( testTicketObserver.LoadFailedCalled(), 0, TEST_LOCATION );
594     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
595     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
596
597     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
598     bitmapData = resourceManager.GetBitmapMetadata(id);
599     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
600     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
601     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
602     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
603
604   } // Discard ticket
605   END_TEST;
606 }
607
608
609 int UtcDaliInternalRequestReloadBitmapRequests03(void)
610 {
611   TestApplication application; // Reset all test adapter return codes
612
613   tet_infoline("Testing bitmap reload at end of first load");
614
615   Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
616   ImageAttributes attr;
617   Integration::ImageResourceType bitmapRequest (Integration::ResourceImageData, attr);
618   Internal::ResourceId id(0);
619
620   testTicketObserver.Reset();
621
622   {
623     Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
624     Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( bitmapRequest, "image.png" );
625     ticket->AddObserver(testTicketObserver);
626
627     // Update thread will request the bitmap resource:
628     // Sets application.GetPlatform().mRequest
629     application.SendNotification(); // Run flush update queue
630     application.Render(1);          // Process update messages
631     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
632
633     application.SendNotification(); // Send any event messages
634     DALI_TEST_CHECK( testTicketObserver.LoadFailedCalled() == 0 );
635     DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
636
637     Internal::ImageTicketPtr imageTicket(dynamic_cast<Internal::ImageTicket*>(ticket.Get()));
638     DALI_TEST_CHECK( imageTicket );
639     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
640     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
641
642
643     /************************************************************
644      * FUNCTION UNDER TEST
645      ***********************************************************/
646     resourceClient.ReloadResource( ticket->GetId() );
647     /************************************************************
648      * Expected result - current load completes as usual, no reload requested
649      ************************************************************/
650
651     application.SendNotification(); // Flush update methods
652
653     // Reset call statistics - test that resource is not reloaded
654     application.GetPlatform().ResetTrace();
655
656     // Create a resource
657     Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
658     Integration::ImageDataPtr bitmap = Integration::NewBitmapImageData( 80, 80, Pixel::RGBA8888 );
659     Integration::ResourcePointer resourcePtr(bitmap); // reference it
660
661     // Set up platform abstraction to load it
662     id=req->GetId();
663
664     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr);
665
666     DALI_TEST_CHECK( ! resourceManager.IsResourceLoaded(id));
667
668     application.GetPlatform().ResetTrace();
669     // load the cache, which will immediately have the loaded resource
670     application.Render(0);
671
672     // UpdateCache runs before ProcessMessages, so the loading resource completes before
673     // the reload request is handled.
674     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc ) );
675     DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::GetResourcesFunc ) );
676
677     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
678     Internal::BitmapMetadata bitmapData = resourceManager.GetBitmapMetadata(id);
679     DALI_TEST_CHECK( bitmapData.GetWidth() == 80 );
680     DALI_TEST_CHECK( bitmapData.GetHeight() == 80 );
681
682     DALI_TEST_EQUALS( imageTicket->GetWidth(), 0, TEST_LOCATION );
683     DALI_TEST_EQUALS( imageTicket->GetHeight(), 0, TEST_LOCATION );
684
685     // Trigger the event thread to process notify messages. Should then trigger the signals
686     // in the ticket observer
687     application.SendNotification();
688
689     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 1, TEST_LOCATION );
690     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
691     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
692
693     // Check that the image ticket was updated with the image attributes
694     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
695     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
696
697     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), true, TEST_LOCATION );
698
699     // Create a new resource - the image size could have changed in the meantime
700     req = application.GetPlatform().GetRequest();
701     Integration::ImageDataPtr bitmap2 = Integration::NewBitmapImageData( 120, 120, Pixel::RGBA8888 );
702     Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
703     DALI_TEST_CHECK( req->GetId() == id );
704     application.GetPlatform().SetResourceLoaded(id, Integration::ResourceImageData, resourcePtr2);
705
706     application.Render(0);  // Process update messages / UpdateCache
707
708     DALI_TEST_CHECK( resourceManager.IsResourceLoaded(id));
709     bitmapData = resourceManager.GetBitmapMetadata(id);
710     DALI_TEST_CHECK( bitmapData.GetWidth() == 120 );
711     DALI_TEST_CHECK( bitmapData.GetHeight() == 120 );
712     DALI_TEST_EQUALS( imageTicket->GetWidth(), 80, TEST_LOCATION );
713     DALI_TEST_EQUALS( imageTicket->GetHeight(), 80, TEST_LOCATION );
714
715     application.SendNotification(); // Process event messages
716
717     DALI_TEST_EQUALS( testTicketObserver.LoadSucceededCalled(), 2, TEST_LOCATION );
718
719     // Not staged - no GL upload
720     DALI_TEST_EQUALS( testTicketObserver.UploadCalled(), 0, TEST_LOCATION );
721
722     DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
723     DALI_TEST_EQUALS( imageTicket->GetWidth(), 120, TEST_LOCATION );
724     DALI_TEST_EQUALS( imageTicket->GetHeight(), 120, TEST_LOCATION );
725     DALI_TEST_EQUALS( resourceManager.ResourcesToProcess(), false, TEST_LOCATION );
726   }
727   END_TEST;
728 }
729
730
731 int UtcDaliInternalSaveResource01(void)
732 {
733   TestApplication application;
734   tet_infoline("Testing SaveResource() with valid id, and valid filename");
735
736   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
737
738   Dali::ModelData modelData = BuildTreeModel();
739   testTicketObserver.Reset();
740
741   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
742   ticket->AddObserver(testTicketObserver);
743
744   // First, load a model resource
745   application.SendNotification(); // Flush update messages
746   application.Render();           // Process resource request
747   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
748   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
749   Integration::ResourcePointer resourcePtr(&modelDataImpl);
750
751   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
752   application.Render();           // Process LoadComplete
753   application.SendNotification(); // Process event messages
754   DALI_TEST_CHECK( ticket->GetLoadingState() == ResourceLoadingSucceeded );
755
756   // Try saving it
757   resourceClient.SaveResource( ticket, "model.dali-bin" );
758   application.SendNotification(); // Flush update messages
759   application.Render();           // Process save resource request
760
761   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
762   req = application.GetPlatform().GetRequest();
763   DALI_TEST_CHECK( req->GetType()->id == Integration::ResourceModel );
764   DALI_TEST_CHECK( req->GetPath().compare("model.dali-bin") == 0 );
765
766   // Set up success response
767   application.GetPlatform().SetResourceSaved(req->GetId(), req->GetType()->id);
768   application.Render();           // GetResources --> SaveComplete
769   application.SendNotification(); // Send event messages
770
771   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 1 );
772   DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
773 ;
774   END_TEST;
775 }
776
777
778 int UtcDaliInternalSaveResource02(void)
779 {
780   TestApplication application;
781   tet_infoline("Testing SaveResource() with invalid id");
782   testTicketObserver.Reset();
783
784   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
785
786   Dali::ModelData modelData = BuildTreeModel();
787
788   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
789   ticket->AddObserver(testTicketObserver);
790
791   // First, load a model resource
792   application.SendNotification(); // Flush update messages
793   application.Render();           // Process resource request
794   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
795   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
796   Integration::ResourcePointer resourcePtr(&modelDataImpl);
797   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
798   application.Render();           // Process LoadComplete
799   application.SendNotification(); // Process event messages
800   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
801   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
802
803   Internal::ResourceTypePath typePath(Integration::ModelResourceType(), "");
804   Internal::ResourceTicketPtr aTicket = new Internal::ResourceTicket( testTicketLifetimeObserver, 2000,  typePath );
805   try
806   {
807     resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
808   } catch (DaliException& e)
809   {
810     // Tests that a negative test of an assertion succeeds
811     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
812
813     DALI_TEST_ASSERT(e, "mImpl->mTickets.find(ticket->GetId()) != mImpl->mTickets.end()", TEST_LOCATION );
814   }
815
816   application.SendNotification(); // Flush update messages
817   application.Render();           // Process save resource request
818
819   // Ensure no request sent to platform abstraction
820   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
821   req = application.GetPlatform().GetRequest();
822   DALI_TEST_CHECK ( req == NULL );
823   END_TEST;
824 }
825
826 int UtcDaliInternalSaveResource03(void)
827 {
828   TestApplication application;
829   tet_infoline("Testing SaveResource() with invalid id");
830   testTicketObserver.Reset();
831
832   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
833
834   Dali::ModelData modelData = BuildTreeModel();
835
836   Internal::ResourceTicketPtr ticket = resourceClient.RequestResource( Integration::ModelResourceType(), "model.dae" );
837   ticket->AddObserver(testTicketObserver);
838
839   // First, load a model resource
840   application.SendNotification(); // Flush update messages
841   application.Render();           // Process resource request
842   Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
843   Internal::ModelData& modelDataImpl = GetImplementation(modelData);
844   Integration::ResourcePointer resourcePtr(&modelDataImpl);
845   application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
846   application.Render();           // Process LoadComplete
847   application.SendNotification(); // Process event messages
848   DALI_TEST_CHECK(ticket->GetLoadingState() == ResourceLoadingSucceeded);
849   application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
850
851   Internal::ResourceTicketPtr aTicket;
852   try
853   {
854     resourceClient.SaveResource( aTicket, "model.dali-bin" ); // Should be outside range of valid resources!
855   } catch (DaliException& e)
856   {
857     // Tests that a negative test of an assertion succeeds
858     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
859
860     DALI_TEST_EQUALS(e.mCondition, "ticket", TEST_LOCATION);
861   }
862
863   application.SendNotification(); // Flush update messages
864   application.Render();           // Process save resource request
865
866   // Ensure no request sent to platform abstraction
867   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
868   req = application.GetPlatform().GetRequest();
869   DALI_TEST_CHECK ( req == NULL );
870   END_TEST;
871 }
872
873
874 int UtcDaliInternalSaveResource04(void)
875 {
876   TestApplication application;
877   tet_infoline("Testing SaveResource() with valid id, but invalid filename");
878   testTicketObserver.Reset();
879
880   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
881
882   // First, load a model resource
883   Internal::ResourceTicketPtr ticket = CheckLoadModel(application, "model.dae");
884
885   resourceClient.SaveResource( ticket, "model.dali-bin" );
886   application.SendNotification(); // Flush update messages
887   application.Render();           // Process save resource request
888
889   // Set up fail response
890   application.GetPlatform().SetResourceSaveFailed(ticket->GetId(), Integration::FailureInvalidPath );
891   application.Render();           // GetResources --> SaveFailed
892   application.SendNotification(); // Send event messages
893
894   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() == 0 );
895   DALI_TEST_CHECK( testTicketObserver.SaveFailedCalled() == 1 );
896   DALI_TEST_EQUALS( ticket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION )
897 ;
898   END_TEST;
899 }
900
901 int UtcDaliInternalSaveResource05(void)
902 {
903   TestApplication application;
904   tet_infoline("Testing SaveResource() with valid id, but invalid resource type");
905   testTicketObserver.Reset();
906
907   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
908
909   // First, load a bitmap resource
910   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
911
912   // Try saving it
913   resourceClient.SaveResource( ticket, "bitmap.png" );
914   application.SendNotification(); // Flush update messages
915   application.Render();           // Process save resource request
916
917   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
918   END_TEST;
919 }
920
921 int UtcDaliInternalRequestResourceTicket01(void)
922 {
923   TestApplication application;
924   tet_infoline("Testing RequestResourceTicket() with valid id");
925
926   testTicketObserver.Reset();
927
928   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
929
930   // First, load a bitmap resource
931   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
932
933   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() );
934   DALI_TEST_CHECK( newTicket );
935   DALI_TEST_CHECK( newTicket->GetId() == ticket->GetId() );
936   DALI_TEST_CHECK( newTicket->GetTypePath().type->id == ticket->GetTypePath().type->id );
937   END_TEST;
938 }
939
940 int UtcDaliInternalRequestResourceTicket02(void)
941 {
942   TestApplication application;
943   tet_infoline("Testing RequestResourceTicket() with invalid id");
944
945   testTicketObserver.Reset();
946
947   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
948
949   // First, load a bitmap resource
950   Internal::ResourceTicketPtr ticket = CheckLoadBitmap(application, "bitmap.jpg", 80, 80);
951
952   Internal::ResourceTicketPtr newTicket = resourceClient.RequestResourceTicket( ticket->GetId() + 2000 );
953   DALI_TEST_CHECK( ! newTicket );
954   END_TEST;
955 }
956
957 int UtcDaliInternalLoadShaderRequest01(void)
958 {
959   TestApplication application;
960   tet_infoline("Testing LoadShader() success");
961   testTicketObserver.Reset();
962
963   // Clear through all of the outstanding shader load requests from the default shader effect
964   std::vector< unsigned char > buffer;
965   for( int i=0; i<10; i++ )
966   {
967     buffer.push_back((unsigned char)i);
968   }
969   application.GetPlatform().SetLoadFileResult( true, buffer );
970   application.GetGlAbstraction().SetLinkStatus(1);
971   application.SendNotification(); // Flush update messages
972   application.Render();           // Process load shader request (immediately)
973   application.SendNotification();
974   application.Render();
975   application.SendNotification();
976   application.Render();
977   application.SendNotification();
978
979   Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
980
981   Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
982   std::string shaderBinaryFile("shader.bin");
983   Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
984   DALI_TEST_CHECK( ticket );
985
986   application.GetPlatform().SetLoadFileResult( true, buffer );
987   application.GetGlAbstraction().EnableShaderCallTrace( true );
988   application.GetGlAbstraction().SetLinkStatus(1);
989
990   application.SendNotification(); // Flush update messages
991   application.Render();           // Process load shader request (immediately)
992
993   application.SendNotification();
994   application.Render();
995
996   application.SendNotification();
997   application.Render();
998
999   // If shader program loads OK, we shouldn't see any calls to CompileShader or SaveResource
1000   TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1001   DALI_TEST_CHECK( ! shaderTrace.FindMethod("CompileShader") );
1002
1003   // Ensure no request sent to platform abstraction
1004   DALI_TEST_CHECK( ! application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1005   END_TEST;
1006 }
1007
1008 int UtcDaliInternalLoadShaderRequest02(void)
1009 {
1010   TestApplication application;
1011   tet_infoline("Testing LoadShader() failure");
1012   testTicketObserver.Reset();
1013
1014   // Clear through all of the outstanding shader load requests from the default shader effect
1015   std::vector< unsigned char > buffer;
1016   for( int i=0; i<10; i++ )
1017   {
1018     buffer.push_back((unsigned char)i);
1019   }
1020   application.GetPlatform().SetLoadFileResult( true, buffer );
1021   application.GetGlAbstraction().SetLinkStatus(1);
1022   application.SendNotification(); // Flush update messages
1023   application.Render();           // Process load shader request (immediately)
1024   application.SendNotification();
1025   application.Render();
1026   application.SendNotification();
1027   application.Render();
1028   application.SendNotification();
1029
1030   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1031   Internal::SceneGraph::UpdateManager& updateManager = Internal::ThreadLocalStorage::Get().GetUpdateManager();
1032
1033   Integration::ShaderResourceType shaderRequest(123, "vertex src", "frag src");
1034   std::string shaderBinaryFile("shader.bin");
1035   Internal::ResourceTicketPtr ticket = resourceClient.LoadShader(shaderRequest, shaderBinaryFile);
1036   ticket->AddObserver(testTicketObserver);
1037
1038   ShaderEffect::GeometryHints hints = ShaderEffect::HINT_NONE;
1039   Internal::SceneGraph::Shader* sceneObject = new Internal::SceneGraph::Shader( hints );
1040   AddShaderMessage( updateManager, *sceneObject );
1041
1042   size_t shaderHash=0;
1043   SetShaderProgramMessage( updateManager, *sceneObject, GEOMETRY_TYPE_IMAGE, Internal::SHADER_DEFAULT, ticket->GetId(), shaderHash );
1044
1045   DALI_TEST_CHECK( ticket );
1046
1047   buffer.clear();
1048   DALI_TEST_CHECK(buffer.size() == 0);
1049
1050   application.GetPlatform().SetLoadFileResult( true, buffer );
1051   application.GetGlAbstraction().ResetShaderCallStack();
1052   application.GetGlAbstraction().EnableShaderCallTrace( true );
1053   application.GetGlAbstraction().SetLinkStatus(1);
1054   application.GetGlAbstraction().SetProgramBinaryLength(20);
1055   application.GetPlatform().SetResourceSaved (ticket->GetId(), Integration::ResourceShader );
1056
1057   application.SendNotification(); // Flush update messages
1058   application.Render();           // Process load shader request (immediately), add responses
1059                                   // to post process q
1060   application.Render();           // this update will process old post-process-q
1061   application.Render();           // this update will process new post-process-q
1062   application.SendNotification(); // Send save request to event thread
1063   application.Render();           // this update will process save request
1064   application.Render();           // this update will get SaveComplete
1065   application.SendNotification(); // Send save request response
1066
1067   TraceCallStack& shaderTrace = application.GetGlAbstraction().GetShaderTrace();
1068   DALI_TEST_CHECK( shaderTrace.FindMethod("CompileShader") );
1069
1070   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::SaveResourceFunc ) );
1071   DALI_TEST_CHECK( testTicketObserver.SaveSucceededCalled() );
1072   END_TEST;
1073 }
1074
1075 int UtcDaliInternalAllocateBitmapImage01(void)
1076 {
1077   TestApplication application;
1078   tet_infoline("Testing AllocateBitmapImage()");
1079   testTicketObserver.Reset();
1080
1081   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1082   Internal::ImageTicketPtr imageTicket = resourceClient.AllocateBitmapImage(80, 80, 80, 80, Pixel::RGB565);
1083   imageTicket->AddObserver( testTicketObserver );
1084
1085   DALI_TEST_CHECK( imageTicket );
1086   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1087   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1088   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1089   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1090
1091   application.SendNotification(); // Flush update queue
1092   application.Render(0); // Process message
1093   application.SendNotification(); // Send message to tickets
1094
1095   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1096   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1097   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1098   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1099   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1100
1101   Integration::Bitmap* bitmap = resourceClient.GetBitmap(imageTicket);
1102   DALI_TEST_CHECK ( bitmap != NULL );
1103   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1104   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1105   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1106   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1107   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1108   END_TEST;
1109 }
1110
1111 int UtcDaliInternalAddBitmapImage01(void)
1112 {
1113   TestApplication application;
1114   tet_infoline("Testing AddBitmap with reserved buffer()");
1115   testTicketObserver.Reset();
1116   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1117   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1118   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB565, 80, 80, 80, 80 );
1119
1120   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1121   DALI_TEST_CHECK( imageTicket );
1122   imageTicket->AddObserver( testTicketObserver );
1123
1124   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1125   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1126   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1127   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1128
1129   application.SendNotification(); // Flush update queue
1130   application.Render(0); // Process message
1131   application.SendNotification(); // Send message to tickets
1132
1133   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1134   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1135   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1136   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1137   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1138
1139   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1140   DALI_TEST_CHECK ( theBitmap != NULL );
1141   DALI_TEST_CHECK ( bitmap == theBitmap );
1142   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 80u, TEST_LOCATION );
1143   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 80u, TEST_LOCATION );
1144   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 80u, TEST_LOCATION );
1145   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1146   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
1147   END_TEST;
1148 }
1149
1150 int UtcDaliInternalAddBitmapImage02(void)
1151 {
1152   TestApplication application;
1153   tet_infoline("Testing AddBitmap without reserved buffer()");
1154   testTicketObserver.Reset();
1155   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1156   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1157
1158   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1159   DALI_TEST_CHECK( imageTicket );
1160   imageTicket->AddObserver( testTicketObserver );
1161
1162   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1163   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1164   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1165   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1166   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1167
1168   application.SendNotification(); // Flush update queue
1169   application.Render(0); // Process message
1170   application.SendNotification(); // Send message to tickets
1171
1172   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1173   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 0, TEST_LOCATION );
1174   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 0, TEST_LOCATION );
1175   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1176   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1177
1178   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1179   DALI_TEST_CHECK ( theBitmap != NULL );
1180   DALI_TEST_CHECK ( bitmap == theBitmap );
1181   DALI_TEST_EQUALS ( bitmap->GetImageWidth(), 0u, TEST_LOCATION );
1182   DALI_TEST_EQUALS ( bitmap->GetImageHeight(), 0u, TEST_LOCATION );
1183   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(), 0u, TEST_LOCATION );
1184   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 0u, TEST_LOCATION );
1185   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1186
1187   // There is no way for the ticket's image attributes to be updated if the bitmap
1188   // reserves a buffer after ticket generation.
1189   // Probably not an issue - there is no public API in BufferImage to change the image size.
1190   END_TEST;
1191 }
1192
1193
1194 int UtcDaliInternalAddBitmapImage03(void)
1195 {
1196   TestApplication application;
1197   tet_infoline("Testing AddBitmap() with invalid bitmap");
1198   testTicketObserver.Reset();
1199
1200   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1201   Internal::ImageTicketPtr imageTicket;
1202   bool exceptionRaised=false;
1203   try
1204   {
1205     imageTicket = resourceClient.AddBitmapImage( NULL );
1206   }
1207   catch( DaliException& e )
1208   {
1209     exceptionRaised = true;
1210   }
1211   DALI_TEST_CHECK( exceptionRaised );
1212   DALI_TEST_CHECK( ! imageTicket );
1213   END_TEST;
1214 }
1215
1216 int UtcDaliInternalGetBitmapImage01(void)
1217 {
1218   TestApplication application;
1219   tet_infoline("Testing GetBitmap() with valid ticket");
1220   testTicketObserver.Reset();
1221
1222   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1223   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  false  );
1224   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 20, 20, 80, 80 );
1225   Internal::ImageTicketPtr imageTicket = resourceClient.AddBitmapImage( bitmap );
1226
1227   Integration::Bitmap* theBitmap = resourceClient.GetBitmap(imageTicket);
1228   DALI_TEST_CHECK ( theBitmap != NULL );
1229   DALI_TEST_CHECK ( bitmap == theBitmap );
1230   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1231   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1232   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1233   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1234   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1235
1236   imageTicket->AddObserver( testTicketObserver );
1237   application.SendNotification(); // Flush update queue
1238   application.Render(0);          // Process message
1239   application.SendNotification(); // Send message to tickets
1240
1241   theBitmap = resourceClient.GetBitmap(imageTicket);
1242   DALI_TEST_CHECK ( theBitmap != NULL );
1243   DALI_TEST_CHECK ( bitmap == theBitmap );
1244   DALI_TEST_EQUALS ( bitmap->GetImageWidth(),   20u, TEST_LOCATION );
1245   DALI_TEST_EQUALS ( bitmap->GetImageHeight(),  20u, TEST_LOCATION );
1246   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferWidth(),  80u, TEST_LOCATION );
1247   DALI_TEST_EQUALS ( bitmap->GetPackedPixelsProfile()->GetBufferHeight(), 80u, TEST_LOCATION );
1248   DALI_TEST_EQUALS ( bitmap->GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
1249   END_TEST;
1250 }
1251
1252 int UtcDaliInternalGetBitmapImage02(void)
1253 {
1254   TestApplication application;
1255   tet_infoline("Testing GetBitmap() with invalid ticket");
1256
1257   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1258   Internal::ImageTicketPtr imageTicket;
1259   Integration::Bitmap* theBitmap = NULL;
1260   bool exceptionRaised = false;
1261   try
1262   {
1263     theBitmap = resourceClient.GetBitmap(imageTicket);
1264   } catch (DaliException& e)
1265   {
1266     exceptionRaised = true;
1267   }
1268   DALI_TEST_CHECK( exceptionRaised );
1269   DALI_TEST_CHECK( ! theBitmap );
1270   END_TEST;
1271 }
1272
1273 int UtcDaliInternalGetBitmapImage03(void)
1274 {
1275   TestApplication application;
1276   tet_infoline("Testing GetBitmap() with valid ticket for incorrect type");
1277
1278   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();  Internal::ResourceTicketPtr imageTicket = CheckLoadBitmap( application, "Stuff.png", 100, 100 );
1279   Internal::ResourceTicketPtr modelTicket = CheckLoadModel( application, "Stuff.dae");
1280
1281   Integration::Bitmap* theBitmap = NULL;
1282   theBitmap = resourceClient.GetBitmap(imageTicket);
1283   DALI_TEST_CHECK( ! theBitmap );
1284
1285   theBitmap = resourceClient.GetBitmap(modelTicket);
1286   DALI_TEST_CHECK( ! theBitmap );
1287   END_TEST;
1288 }
1289
1290 int UtcDaliInternalAllocateTexture01(void)
1291 {
1292   TestApplication application;
1293   tet_infoline("Testing AllocateTexture()");
1294   testTicketObserver.Reset();
1295
1296   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1297   Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture(80, 80, Pixel::L8 );
1298   resourceTicket->AddObserver( testTicketObserver );
1299
1300   DALI_TEST_CHECK( resourceTicket );
1301   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1302   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1303
1304   application.SendNotification(); // Flush update queue
1305   application.Render(0); // Process message
1306   application.SendNotification(); // Send message to tickets
1307
1308   DALI_TEST_EQUALS ( resourceTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1309   DALI_TEST_CHECK( testTicketObserver.LoadSucceededCalled() == 0 );
1310   END_TEST;
1311 }
1312
1313 int UtcDaliInternalAddNativeImage(void)
1314 {
1315   TestApplication application;
1316   tet_infoline("Testing AddNativeImage()");
1317
1318   testTicketObserver.Reset();
1319   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1320   Internal::ResourceTicketPtr ticket;
1321   Internal::ImageTicketPtr imageTicket;
1322   { // Test image going out of scope after ticket creation (message to Update thread holds a ref)
1323     TestNativeImagePointer nativeImage = TestNativeImage::New( 80, 80 );
1324     ticket = resourceClient.AddNativeImage( *nativeImage );
1325     imageTicket = dynamic_cast<Internal::ImageTicket*>(ticket.Get());
1326     DALI_TEST_CHECK( imageTicket );
1327     imageTicket->AddObserver( testTicketObserver );
1328   }
1329
1330   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1331   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1332   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1333   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1334
1335   application.SendNotification(); // Flush update queue
1336   application.Render(0); // Process message
1337   application.SendNotification(); // Send message to tickets
1338
1339   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1340   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1341   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1342   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1343
1344   Integration::Bitmap* theBitmap = NULL;
1345   theBitmap = resourceClient.GetBitmap(imageTicket);
1346
1347   DALI_TEST_CHECK ( theBitmap == NULL );
1348   END_TEST;
1349 }
1350
1351 int UtcDaliInternalAddFrameBufferImage(void)
1352 {
1353   TestApplication application;
1354   tet_infoline("Testing AddFrameBufferImage()");
1355
1356   testTicketObserver.Reset();
1357   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1358   Internal::ImageTicketPtr imageTicket = resourceClient.AddFrameBufferImage(80, 80, Pixel::A8 );
1359   DALI_TEST_CHECK( imageTicket );
1360   imageTicket->AddObserver( testTicketObserver );
1361
1362   DALI_TEST_EQUALS ( imageTicket->GetWidth(),  80, TEST_LOCATION );
1363   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1364   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1365   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1366   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1367
1368   application.SendNotification(); // Flush update queue
1369   application.Render(0); // Process message
1370   application.SendNotification(); // Send message to tickets
1371
1372   DALI_TEST_EQUALS ( imageTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1373   DALI_TEST_EQUALS ( imageTicket->GetWidth(), 80, TEST_LOCATION );
1374   DALI_TEST_EQUALS ( imageTicket->GetHeight(), 80, TEST_LOCATION );
1375   DALI_TEST_EQUALS ( imageTicket->GetAttributes().GetPixelFormat(), Pixel::A8, TEST_LOCATION );
1376   DALI_TEST_CHECK ( 0 == testTicketObserver.LoadSucceededCalled() ); // Check no message was sent
1377
1378   Integration::Bitmap* theBitmap = NULL;
1379   theBitmap = resourceClient.GetBitmap(imageTicket);
1380   DALI_TEST_CHECK ( theBitmap == NULL );
1381   END_TEST;
1382 }
1383
1384 int UtcDaliInternalAllocateMesh01(void)
1385 {
1386   TestApplication application;
1387   tet_infoline("Testing AllocateMesh() with vald mesh data");
1388
1389   MeshData publicMeshData;
1390   MeshData::VertexContainer    vertices;
1391   MeshData::FaceIndices        faces;
1392   BoneContainer                bones;
1393   ConstructVertices(vertices, 60);
1394   ConstructFaces(vertices, faces);
1395   Material customMaterial = ConstructMaterial();
1396   publicMeshData.SetData(vertices, faces, bones, customMaterial);
1397   publicMeshData.SetHasNormals(true);
1398   publicMeshData.SetHasTextureCoords(true);
1399
1400   testTicketObserver.Reset();
1401   Internal::ResourceClient& resourceClient  = Internal::ThreadLocalStorage::Get().GetResourceClient();
1402   Internal::OwnerPointer<Internal::MeshData> meshDataPtr( new Internal::MeshData( publicMeshData, true, true ) );
1403   Internal::ResourceTicketPtr meshTicket = resourceClient.AllocateMesh(meshDataPtr);
1404   DALI_TEST_CHECK( meshTicket );
1405   meshTicket->AddObserver( testTicketObserver );
1406
1407   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoading, TEST_LOCATION );
1408
1409   application.SendNotification(); // Flush update queue
1410   application.Render(0); // Process message
1411   application.SendNotification(); // Send message to tickets
1412
1413   DALI_TEST_EQUALS ( meshTicket->GetLoadingState(), ResourceLoadingSucceeded, TEST_LOCATION );
1414   END_TEST;
1415 }