2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_resource_image_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_resource_image_cleanup(void)
33 test_return_value = TET_PASS;
36 static const char* gTestImageFilename = "icon_wrt.png";
41 void LoadBitmapResource(TestPlatformAbstraction& platform)
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);
50 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
58 int UtcDaliResourceImageNew01(void)
60 TestApplication application;
62 tet_infoline("UtcDaliResourceImageNew01 - ResourceImage::New(const std::string&)");
64 // invoke default handle constructor
67 DALI_TEST_CHECK( !image );
70 image = ResourceImage::New(gTestImageFilename);
72 DALI_TEST_CHECK( image );
77 int UtcDaliResourceImageNew02(void)
79 TestApplication application;
81 tet_infoline("UtcDaliREsourceImageNew02 - ResourceImage New( const std::string& url, ImageDimensions size, FittingMode scalingMode, SamplingMode samplingMode, bool orientationCorrection = true )");
83 // invoke default handle constructor
86 DALI_TEST_CHECK( !image );
89 image = ResourceImage::New(gTestImageFilename, ImageDimensions( 128, 256 ), FittingMode::FIT_HEIGHT );
91 DALI_TEST_CHECK( image );
96 int UtcDaliResourceImageDownCast(void)
98 TestApplication application;
99 tet_infoline("Testing Dali::ResourceImage::DownCast()");
101 ResourceImage image = ResourceImage::New(gTestImageFilename);
103 BaseHandle object(image);
105 ResourceImage image2 = ResourceImage::DownCast(object);
106 DALI_TEST_CHECK(image2);
108 ResourceImage image3 = DownCast< ResourceImage >(object);
109 DALI_TEST_CHECK(image3);
111 BaseHandle unInitializedObject;
112 ResourceImage image4 = ResourceImage::DownCast(unInitializedObject);
113 DALI_TEST_CHECK(!image4);
115 ResourceImage image5 = DownCast< ResourceImage >(unInitializedObject);
116 DALI_TEST_CHECK(!image5);
118 Image image6 = ResourceImage::New(gTestImageFilename);
119 ResourceImage image7 = ResourceImage::DownCast(image6);
120 DALI_TEST_CHECK(image7);
125 int UtcDaliResourceImageGetImageSize(void)
127 TestApplication application;
128 TestPlatformAbstraction& platform = application.GetPlatform();
130 tet_infoline("UtcDaliResourceImageGetImageSize - ResourceImage::GetImageSize()");
132 Vector2 testSize(8.0f, 16.0f);
133 platform.SetClosestImageSize(testSize);
135 const ImageDimensions size = ResourceImage::GetImageSize(gTestImageFilename);
137 DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
138 DALI_TEST_EQUALS( Vector2( size.GetX(), size.GetY() ), testSize, TEST_LOCATION);
143 int UtcDaliResourceImageGetUrl(void)
145 TestApplication application;
147 tet_infoline("UtcDaliResourceImageGetFilename - ResourceImage::GetUrl()");
149 // invoke default handle constructor
152 DALI_TEST_CHECK( !image );
155 image = ResourceImage::New(gTestImageFilename);
157 DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION);
162 int UtcDaliResourceImageGetLoadingState01(void)
164 TestApplication application;
165 tet_infoline("UtcDaliResourceImageGetLoadingState01");
167 ResourceImage image = ResourceImage::New(gTestImageFilename);
168 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
169 application.SendNotification();
170 application.Render(16);
172 // simulate load success
173 TestPlatformAbstraction& platform = application.GetPlatform();
174 LoadBitmapResource( platform );
175 application.Render(16);
176 application.SendNotification();
178 // Test state == ResourceLoadingSucceeded
179 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
184 int UtcDaliResourceImageGetLoadingState02(void)
186 TestApplication application;
188 tet_infoline("UtcDaliResourceImageGetLoadingState02");
190 // invoke default handle constructor
193 DALI_TEST_CHECK( !image );
196 image = ResourceImage::New(gTestImageFilename);
198 // Test state == ResourceLoading
199 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoading);
200 application.SendNotification();
201 application.Render(16);
203 // simulate load failure
204 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
207 application.GetPlatform().SetResourceLoadFailed(request->GetId(), Integration::FailureUnknown);
209 application.Render(16);
210 application.SendNotification();
212 // Test state == ResourceLoadingFailed
213 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
217 static bool SignalLoadFlag = false;
219 static void SignalLoadHandler(ResourceImage image)
221 tet_infoline("Received image load finished signal");
223 SignalLoadFlag = true;
227 int UtcDaliResourceImageSignalLoadingFinished(void)
229 TestApplication application;
231 tet_infoline("UtcDaliResourceImageSignalLoadingFinished");
233 SignalLoadFlag = false;
235 ResourceImage image = ResourceImage::New(gTestImageFilename);
237 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
238 application.SendNotification();
239 application.Render(16);
241 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
244 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD)));
247 application.Render(16);
248 application.SendNotification();
250 DALI_TEST_CHECK( SignalLoadFlag == true );