[3.0] Modify texture bind for OES_EGL_image_external
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-ResourceImage.cpp
1 /*
2  * Copyright (c) 2016 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 static const char* gTestImageFilename = "icon_wrt.png";
37
38 namespace
39 {
40
41 void LoadBitmapResource(TestPlatformAbstraction& platform)
42 {
43   Integration::ResourceRequest* request = platform.GetRequest();
44   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
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
58 int UtcDaliResourceImageNew01(void)
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
70   image = ResourceImage::New(gTestImageFilename);
71
72   DALI_TEST_CHECK( image );
73   END_TEST;
74 }
75
76 // 1.2
77 int UtcDaliResourceImageNew02(void)
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
89   image = ResourceImage::New(gTestImageFilename, ImageDimensions( 128, 256 ), FittingMode::FIT_HEIGHT );
90
91   DALI_TEST_CHECK( image );
92   END_TEST;
93 }
94
95 // 1.7
96 int UtcDaliResourceImageDownCast(void)
97 {
98   TestApplication application;
99   tet_infoline("Testing Dali::ResourceImage::DownCast()");
100
101   ResourceImage image = ResourceImage::New(gTestImageFilename);
102
103   BaseHandle object(image);
104
105   ResourceImage image2 = ResourceImage::DownCast(object);
106   DALI_TEST_CHECK(image2);
107
108   ResourceImage image3 = DownCast< ResourceImage >(object);
109   DALI_TEST_CHECK(image3);
110
111   BaseHandle unInitializedObject;
112   ResourceImage image4 = ResourceImage::DownCast(unInitializedObject);
113   DALI_TEST_CHECK(!image4);
114
115   ResourceImage image5 = DownCast< ResourceImage >(unInitializedObject);
116   DALI_TEST_CHECK(!image5);
117
118   Image image6 = ResourceImage::New(gTestImageFilename);
119   ResourceImage image7 = ResourceImage::DownCast(image6);
120   DALI_TEST_CHECK(image7);
121   END_TEST;
122 }
123
124 // 1.8
125 int UtcDaliResourceImageGetImageSize(void)
126 {
127   TestApplication application;
128   TestPlatformAbstraction& platform = application.GetPlatform();
129
130   tet_infoline("UtcDaliResourceImageGetImageSize - ResourceImage::GetImageSize()");
131
132   Vector2 testSize(8.0f, 16.0f);
133   platform.SetClosestImageSize(testSize);
134
135   const ImageDimensions size = ResourceImage::GetImageSize(gTestImageFilename);
136
137   DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
138   DALI_TEST_EQUALS( Vector2( size.GetX(), size.GetY() ), testSize, TEST_LOCATION);
139   END_TEST;
140 }
141
142 // 1.9
143 int UtcDaliResourceImageGetUrl(void)
144 {
145   TestApplication application;
146
147   tet_infoline("UtcDaliResourceImageGetFilename - ResourceImage::GetUrl()");
148
149   // invoke default handle constructor
150   ResourceImage image;
151
152   DALI_TEST_CHECK( !image );
153
154   // initialise handle
155   image = ResourceImage::New(gTestImageFilename);
156
157   DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION);
158   END_TEST;
159 }
160
161 // 1.10
162 int UtcDaliResourceImageGetLoadingState01(void)
163 {
164   TestApplication application;
165   tet_infoline("UtcDaliResourceImageGetLoadingState01");
166
167   ResourceImage image = ResourceImage::New(gTestImageFilename);
168   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
169   application.SendNotification();
170   application.Render(16);
171
172   // simulate load success
173   TestPlatformAbstraction& platform = application.GetPlatform();
174   LoadBitmapResource( platform );
175   application.Render(16);
176   application.SendNotification();
177
178   // Test state == ResourceLoadingSucceeded
179   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
180   END_TEST;
181 }
182
183 // 1.11
184 int UtcDaliResourceImageGetLoadingState02(void)
185 {
186   TestApplication application;
187
188   tet_infoline("UtcDaliResourceImageGetLoadingState02");
189
190   // invoke default handle constructor
191   ResourceImage image;
192
193   DALI_TEST_CHECK( !image );
194
195   // initialise handle
196   image = ResourceImage::New(gTestImageFilename);
197
198   // Test state == ResourceLoading
199   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
200   application.SendNotification();
201   application.Render(16);
202
203   // simulate load failure
204   Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
205   if(request)
206   {
207     application.GetPlatform().SetResourceLoadFailed(request->GetId(), Integration::FailureUnknown);
208   }
209   application.Render(16);
210   application.SendNotification();
211
212   // Test state == ResourceLoadingFailed
213   DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
214   END_TEST;
215 }
216
217 static bool SignalLoadFlag = false;
218
219 static void SignalLoadHandler(ResourceImage image)
220 {
221   tet_infoline("Received image load finished signal");
222
223   SignalLoadFlag = true;
224 }
225
226 // 1.13
227 int UtcDaliResourceImageSignalLoadingFinished(void)
228 {
229   TestApplication application;
230
231   tet_infoline("UtcDaliResourceImageSignalLoadingFinished");
232
233   SignalLoadFlag = false;
234
235   ResourceImage image = ResourceImage::New(gTestImageFilename);
236
237   image.LoadingFinishedSignal().Connect( SignalLoadHandler );
238   application.SendNotification();
239   application.Render(16);
240
241   Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
242   if(request)
243   {
244     application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD)));
245   }
246
247   application.Render(16);
248   application.SendNotification();
249
250   DALI_TEST_CHECK( SignalLoadFlag == true );
251   END_TEST;
252 }