Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-ResourceImage.cpp
1 /*
2  * Copyright (c) 2017 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>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 void utc_dali_resource_image_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_resource_image_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 namespace
37 {
38 const char* gTestImageFilename = "icon_wrt.png";
39 } // unnamed namespace
40
41
42 // 1.1
43 int UtcDaliResourceImageNew01(void)
44 {
45   TestApplication application;
46
47   tet_infoline("UtcDaliResourceImageNew01 - ResourceImage::New(const std::string&)");
48
49   // invoke default handle constructor
50   ResourceImage image;
51
52   DALI_TEST_CHECK( !image );
53
54   // initialise handle
55   image = ResourceImage::New(gTestImageFilename);
56
57   DALI_TEST_CHECK( image );
58   END_TEST;
59 }
60
61 // 1.2
62 int UtcDaliResourceImageNew02(void)
63 {
64   TestApplication application;
65
66   tet_infoline("UtcDaliREsourceImageNew02 - ResourceImage New( const std::string& url, ImageDimensions size, FittingMode scalingMode, SamplingMode samplingMode, bool orientationCorrection = true )");
67
68   // invoke default handle constructor
69   ResourceImage image;
70
71   DALI_TEST_CHECK( !image );
72
73   // initialise handle
74   image = ResourceImage::New(gTestImageFilename, ImageDimensions( 128, 256 ), FittingMode::FIT_HEIGHT );
75
76   DALI_TEST_CHECK( image );
77   END_TEST;
78 }
79
80 // 1.7
81 int UtcDaliResourceImageDownCast(void)
82 {
83   TestApplication application;
84   tet_infoline("Testing Dali::ResourceImage::DownCast()");
85
86   ResourceImage image = ResourceImage::New(gTestImageFilename);
87
88   BaseHandle object(image);
89
90   ResourceImage image2 = ResourceImage::DownCast(object);
91   DALI_TEST_CHECK(image2);
92
93   ResourceImage image3 = DownCast< ResourceImage >(object);
94   DALI_TEST_CHECK(image3);
95
96   BaseHandle unInitializedObject;
97   ResourceImage image4 = ResourceImage::DownCast(unInitializedObject);
98   DALI_TEST_CHECK(!image4);
99
100   ResourceImage image5 = DownCast< ResourceImage >(unInitializedObject);
101   DALI_TEST_CHECK(!image5);
102
103   Image image6 = ResourceImage::New(gTestImageFilename);
104   ResourceImage image7 = ResourceImage::DownCast(image6);
105   DALI_TEST_CHECK(image7);
106   END_TEST;
107 }
108
109 // 1.8
110 int UtcDaliResourceImageGetImageSize(void)
111 {
112   TestApplication application;
113   TestPlatformAbstraction& platform = application.GetPlatform();
114
115   tet_infoline("UtcDaliResourceImageGetImageSize - ResourceImage::GetImageSize()");
116
117   Vector2 testSize(8.0f, 16.0f);
118   platform.SetClosestImageSize(testSize);
119
120   const ImageDimensions size = ResourceImage::GetImageSize(gTestImageFilename);
121
122   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
123   DALI_TEST_EQUALS( Vector2( size.GetX(), size.GetY() ), testSize, TEST_LOCATION);
124   END_TEST;
125 }
126
127 // 1.9
128 int UtcDaliResourceImageGetUrl(void)
129 {
130   TestApplication application;
131
132   tet_infoline("UtcDaliResourceImageGetFilename - ResourceImage::GetUrl()");
133
134   // invoke default handle constructor
135   ResourceImage image;
136
137   DALI_TEST_CHECK( !image );
138
139   // initialise handle
140   image = ResourceImage::New(gTestImageFilename);
141
142   DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION);
143   END_TEST;
144 }
145
146 // 1.10
147 int UtcDaliResourceImageGetLoadingState01(void)
148 {
149   TestApplication application;
150   tet_infoline("UtcDaliResourceImageGetLoadingState01");
151
152   ResourceImage image = ResourceImage::New(gTestImageFilename);
153   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
154
155   // simulate load success
156   PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
157   image.Reload();
158
159   // Test state == ResourceLoadingSucceeded
160   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
161   END_TEST;
162 }
163
164 // 1.11
165 int UtcDaliResourceImageGetLoadingState02(void)
166 {
167   TestApplication application;
168
169   tet_infoline("UtcDaliResourceImageGetLoadingState02");
170
171   // invoke default handle constructor
172   ResourceImage image;
173
174   DALI_TEST_CHECK( !image );
175
176   // initialise handle
177   image = ResourceImage::New(gTestImageFilename);
178
179   // Test state == ResourceLoadingFailed
180   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
181
182   PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
183   image.Reload();
184
185   // Test state == ResourceLoadingFailed
186   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
187   END_TEST;
188 }
189
190 static bool SignalLoadFlag = false;
191
192 static void SignalLoadHandler(ResourceImage image)
193 {
194   tet_infoline("Received image load finished signal");
195
196   SignalLoadFlag = true;
197 }
198
199 // 1.13
200 int UtcDaliResourceImageSignalLoadingFinished(void)
201 {
202   TestApplication application;
203
204   tet_infoline("UtcDaliResourceImageSignalLoadingFinished");
205
206   SignalLoadFlag = false;
207
208   PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
209   ResourceImage image = ResourceImage::New(gTestImageFilename);
210
211   image.LoadingFinishedSignal().Connect( SignalLoadHandler );
212   image.Reload();
213   application.SendNotification();
214   application.Render(16);
215
216   DALI_TEST_CHECK( SignalLoadFlag == true );
217   END_TEST;
218 }