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