Dali 3D User Interface Engine
utc-Dali-BitmapLoader.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 <stdlib.h>
19 #include <dali/dali.h>
20 #include <dali-test-suite-utils.h>
21 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
22 
23 using namespace Dali;
24 
25 namespace
26 {
27 // resolution: 34*34, pixel format: RGBA8888
28 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
29 // resolution: 128*128, pixel format: RGB888
30 static const char* gImage_128_RGB = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
31 
32 // this is image is not exist, for negative test
33 static const char* gImageNonExist = "non-exist.jpg";
34 }
35 
37 {
39 }
40 
42 {
44 }
45 
47 {
48  TestApplication application;
49 
50  // invoke default handle constructor
51  BitmapLoader loader;
52 
53  DALI_TEST_CHECK( !loader );
54 
55  // initialise handle
57 
58  DALI_TEST_CHECK( loader );
59  END_TEST;
60 }
61 
63 {
64  TestApplication application;
65 
66  BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA);
67  BitmapLoader loaderCopy(loader);
68 
69  DALI_TEST_EQUALS( (bool)loaderCopy, true, TEST_LOCATION );
70  END_TEST;
71 }
72 
74 {
75  TestApplication application;
76 
77  BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA );
78 
79  BitmapLoader loader2;
80  DALI_TEST_EQUALS( (bool)loader2, false, TEST_LOCATION );
81 
82  loader2 = loader;
83  DALI_TEST_EQUALS( (bool)loader2, true, TEST_LOCATION );
84 
85  END_TEST;
86 }
87 
89 {
90  TestApplication application;
91 
92  BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA );
93  DALI_TEST_CHECK( loader.GetUrl() == gImage_34_RGBA );
94 
95  END_TEST;
96 }
97 
98 
100 {
101  TestApplication application;
102 
103  BitmapLoader loader1 = BitmapLoader::New( gImage_34_RGBA );
104  DALI_TEST_CHECK( ! loader1.IsLoaded() );
105  loader1.Load();
106  DALI_TEST_CHECK( loader1.IsLoaded() );
107  PixelDataPtr pixelData1 = loader1.GetPixelData();
108  DALI_TEST_CHECK( pixelData1 );
109  DALI_TEST_CHECK( pixelData1->GetWidth() == 34u );
110  DALI_TEST_CHECK( pixelData1->GetHeight() == 34u );
111  DALI_TEST_CHECK( pixelData1->GetPixelFormat() == Pixel::RGBA8888 );
112 
113  BitmapLoader loader2 = BitmapLoader::New( gImage_128_RGB );
114  DALI_TEST_CHECK( ! loader2.IsLoaded() );
115  loader2.Load();
116  DALI_TEST_CHECK( loader2.IsLoaded() );
117  PixelDataPtr pixelData2 = loader2.GetPixelData();
118  DALI_TEST_CHECK( pixelData2 );
119  DALI_TEST_CHECK( pixelData2->GetWidth() == 128u );
120  DALI_TEST_CHECK( pixelData2->GetHeight() == 128u );
121  DALI_TEST_CHECK( pixelData2->GetPixelFormat() == Pixel::RGB888 );
122 
123  END_TEST;
124 }
125 
127 {
128  TestApplication application;
129 
130  BitmapLoader loader = BitmapLoader::New( gImageNonExist );
131  DALI_TEST_CHECK( ! loader.IsLoaded() );
132  loader.Load();
133 
134  // cannot load image that is not exist
135  DALI_TEST_CHECK( ! loader.IsLoaded() );
136  PixelDataPtr pixelData = loader.GetPixelData();
137  DALI_TEST_CHECK( !pixelData);
138 
139  END_TEST;
140 }
Dali Docs Home
Read more about Dali