Dali 3D User Interface Engine
utc-Dali-ResourceImage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #include <algorithm>
20 #include <stdlib.h>
22 #include <dali-test-suite-utils.h>
23 
24 using namespace Dali;
25 
27 {
29 }
30 
32 {
34 }
35 
36 static const char* gTestImageFilename = "icon_wrt.png";
37 
38 namespace
39 {
40 
42 {
43  Integration::ResourceRequest* request = platform.GetRequest();
45  Integration::ResourcePointer resource(bitmap);
46  bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
47 
48  if(request)
49  {
50  platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
51  }
52 }
53 
54 } // namespace
55 
56 
57 // 1.1
59 {
60  TestApplication application;
61 
62  tet_infoline("UtcDaliResourceImageNew01 - ResourceImage::New(const std::string&)");
63 
64  // invoke default handle constructor
65  ResourceImage image;
66 
67  DALI_TEST_CHECK( !image );
68 
69  // initialise handle
71 
72  DALI_TEST_CHECK( image );
73  END_TEST;
74 }
75 
76 // 1.2
78 {
79  TestApplication application;
80 
81  tet_infoline("UtcDaliREsourceImageNew02 - ResourceImage New( const std::string& url, ImageDimensions size, FittingMode scalingMode, SamplingMode samplingMode, bool orientationCorrection = true )");
82 
83  // invoke default handle constructor
84  ResourceImage image;
85 
86  DALI_TEST_CHECK( !image );
87 
88  // initialise handle
90 
91  DALI_TEST_CHECK( image );
92  END_TEST;
93 }
94 
95 // 1.3
97 {
98  TestApplication application;
99  TestPlatformAbstraction& platform = application.GetPlatform();
100 
101  // testing delayed loading
102  tet_infoline("UtcDaliResourceImageNewWithPolicies01 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Never");
105 
106  DALI_TEST_CHECK( image );
107 
108  application.SendNotification();
109  application.Render(16);
110 
111  // request file loading only when actor added to stage
113 
114  ImageActor actor = ImageActor::New(image);
115 
116  Stage::GetCurrent().Add(actor);
117 
118  application.SendNotification();
119  application.Render(16);
120 
122 
123  // testing ReleasePolicy::Never
124  // fake loading image
125  std::vector<GLuint> ids;
126  ids.push_back( 23 );
127  application.GetGlAbstraction().SetNextTextureIds( ids );
128  LoadBitmapResource( platform );
129 
130  application.Render(16);
131  application.SendNotification();
132 
134 
135  // never discard texture
136  Stage::GetCurrent().Remove(actor);
137  application.Render(16);
138  application.SendNotification();
139  application.Render(16);
140  application.SendNotification();
142  END_TEST;
143 }
144 
145 // 1.4
147 {
148  TestApplication application;
149  TestPlatformAbstraction& platform = application.GetPlatform();
150  const Vector2 closestImageSize( 80, 45);
151  platform.SetClosestImageSize(closestImageSize);
152 
153  // testing resource deletion when taken off stage
154  tet_infoline("UtcDaliResourceImageNewWithPolicies02 - Load image with LoadPolicy::OnDemand, ReleasePolicy::Unused");
155 
157 
158  DALI_TEST_CHECK( image );
159 
160  application.SendNotification();
161  application.Render(16);
162 
163  // request file loading only when actor added to stage
165 
166  ImageActor actor = ImageActor::New(image);
167 
168  Stage::GetCurrent().Add(actor);
169 
170  application.SendNotification();
171  application.Render(16);
172 
174 
175  // testing ReleasePolicy::Unused
176  // fake loading image
177  std::vector<GLuint> ids;
178  ids.push_back( 23 );
179  application.GetGlAbstraction().SetNextTextureIds( ids );
180  LoadBitmapResource( platform );
181 
182  application.Render(16);
183  application.SendNotification();
184 
186 
187  // discard texture when actor comes off stage
188  Stage::GetCurrent().Remove(actor);
189  application.Render(16);
190  application.SendNotification();
191  application.Render(16);
192  application.SendNotification();
194  END_TEST;
195 }
196 
197 // 1.5
199 {
200  TestApplication application;
201  TestPlatformAbstraction& platform = application.GetPlatform();
202  const Vector2 closestImageSize( 80, 45);
203  platform.SetClosestImageSize(closestImageSize);
204 
205  // load immediately -> resource deletion when taken off stage -> put actor back on stage -> load resource again
206  tet_infoline("UtcDaliResourceImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Unused");
207 
209 
210  DALI_TEST_CHECK( image );
211 
212  application.SendNotification();
213  application.Render(16);
214 
215  // request file loading immediately
217 
218  ImageActor actor = ImageActor::New(image);
219 
220  Stage::GetCurrent().Add(actor);
221 
222  application.SendNotification();
223  application.Render(16);
224 
225  // testing ReleasePolicy::Unused
226  // fake loading image
227  std::vector<GLuint> ids;
228  ids.push_back( 23 );
229  application.GetGlAbstraction().SetNextTextureIds( ids );
230  LoadBitmapResource( platform );
231 
232  application.Render(16);
233  application.SendNotification();
234 
236 
237  // discard texture when actor comes off stage
238  Stage::GetCurrent().Remove(actor);
239  application.Render(16);
240  application.SendNotification();
241  application.Render(16);
242  application.SendNotification();
244 
245  // check load request when actor added back to stage
246  application.GetPlatform().ResetTrace();
247 
248  Stage::GetCurrent().Add(actor);
249 
250  application.SendNotification();
251  application.Render(16);
252  application.SendNotification();
253  application.Render(16);
254 
256  END_TEST;
257 }
258 
259 // 1.6
261 {
262  TestApplication application;
263  TestPlatformAbstraction& platform = application.GetPlatform();
264 
265  // load immediately, don't release texture when off stage
266  tet_infoline("UtcDaliResourceImageNewWithPolicies03 - Load image with LoadPolicy::Immediate, ReleasePolicy::Never");
267 
269 
270  DALI_TEST_CHECK( image );
271 
272  application.SendNotification();
273  application.Render(16);
274 
275  // request file loading immediately
277 
278  ImageActor actor = ImageActor::New(image);
279 
280  Stage::GetCurrent().Add(actor);
281 
282  application.SendNotification();
283  application.Render(16);
284 
285  // testing ReleasePolicy::Never
286  // fake loading image
287  std::vector<GLuint> ids;
288  ids.push_back( 23 );
289  application.GetGlAbstraction().SetNextTextureIds( ids );
290  LoadBitmapResource(platform);
291 
292  application.Render(16);
293  application.SendNotification();
294 
296 
297  // texture is not discarded
298  Stage::GetCurrent().Remove(actor);
299  application.Render(16);
300  application.SendNotification();
301  application.Render(16);
302  application.SendNotification();
304 
305  // no load request when actor added back to stage
306  application.GetPlatform().ResetTrace();
307 
308  Stage::GetCurrent().Add(actor);
309 
310  application.SendNotification();
311  application.Render(16);
312  application.SendNotification();
313  application.Render(16);
314 
316  END_TEST;
317 }
318 
319 // 1.7
321 {
322  TestApplication application;
323  tet_infoline("Testing Dali::ResourceImage::DownCast()");
324 
326 
327  BaseHandle object(image);
328 
329  ResourceImage image2 = ResourceImage::DownCast(object);
330  DALI_TEST_CHECK(image2);
331 
332  ResourceImage image3 = DownCast< ResourceImage >(object);
333  DALI_TEST_CHECK(image3);
334 
335  BaseHandle unInitializedObject;
336  ResourceImage image4 = ResourceImage::DownCast(unInitializedObject);
337  DALI_TEST_CHECK(!image4);
338 
339  ResourceImage image5 = DownCast< ResourceImage >(unInitializedObject);
340  DALI_TEST_CHECK(!image5);
341 
343  ResourceImage image7 = ResourceImage::DownCast(image6);
344  DALI_TEST_CHECK(image7);
345  END_TEST;
346 }
347 
348 // 1.8
350 {
351  TestApplication application;
352  TestPlatformAbstraction& platform = application.GetPlatform();
353 
354  tet_infoline("UtcDaliResourceImageGetImageSize - ResourceImage::GetImageSize()");
355 
356  Vector2 testSize(8.0f, 16.0f);
357  platform.SetClosestImageSize(testSize);
358 
360 
361  DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
362  DALI_TEST_EQUALS( Vector2( size.GetX(), size.GetY() ), testSize, TEST_LOCATION);
363  END_TEST;
364 }
365 
366 // 1.9
368 {
369  TestApplication application;
370 
371  tet_infoline("UtcDaliResourceImageGetFilename - ResourceImage::GetUrl()");
372 
373  // invoke default handle constructor
374  ResourceImage image;
375 
376  DALI_TEST_CHECK( !image );
377 
378  // initialise handle
380 
382  END_TEST;
383 }
384 
385 // 1.10
387 {
388  TestApplication application;
389  tet_infoline("UtcDaliResourceImageGetLoadingState01");
390 
393  application.SendNotification();
394  application.Render(16);
395 
396  // simulate load success
397  TestPlatformAbstraction& platform = application.GetPlatform();
398  LoadBitmapResource( platform );
399  application.Render(16);
400  application.SendNotification();
401 
402  // Test state == ResourceLoadingSucceeded
404  END_TEST;
405 }
406 
407 // 1.11
409 {
410  TestApplication application;
411 
412  tet_infoline("UtcDaliResourceImageGetLoadingState02");
413 
414  // invoke default handle constructor
415  ResourceImage image;
416 
417  DALI_TEST_CHECK( !image );
418 
419  // initialise handle
421 
422  // Test state == ResourceLoading
424  application.SendNotification();
425  application.Render(16);
426 
427  // simulate load failure
428  Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
429  if(request)
430  {
432  }
433  application.Render(16);
434  application.SendNotification();
435 
436  // Test state == ResourceLoadingFailed
438  END_TEST;
439 }
440 
441 // 1.12
443 {
444  TestApplication application;
445 
446  tet_infoline("UtcDaliImageGetLoadPolicy");
447 
449 
450  DALI_TEST_CHECK( image );
451 
453  END_TEST;
454 }
455 
456 static bool SignalLoadFlag = false;
457 
459 {
460  tet_infoline("Received image load finished signal");
461 
462  SignalLoadFlag = true;
463 }
464 
465 // 1.13
467 {
468  TestApplication application;
469 
470  tet_infoline("UtcDaliResourceImageSignalLoadingFinished");
471 
472  SignalLoadFlag = false;
473 
475 
476  image.LoadingFinishedSignal().Connect( SignalLoadHandler );
477  application.SendNotification();
478  application.Render(16);
479 
480  Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
481  if(request)
482  {
484  }
485 
486  application.Render(16);
487  application.SendNotification();
488 
489  DALI_TEST_CHECK( SignalLoadFlag == true );
490  END_TEST;
491 }
Dali Docs Home
Read more about Dali