2 * Copyright (c) 2017 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;
38 const char* gTestImageFilename = "icon_wrt.png";
39 } // unnamed namespace
43 int UtcDaliResourceImageNew01(void)
45 TestApplication application;
47 tet_infoline("UtcDaliResourceImageNew01 - ResourceImage::New(const std::string&)");
49 // invoke default handle constructor
52 DALI_TEST_CHECK( !image );
55 image = ResourceImage::New(gTestImageFilename);
57 DALI_TEST_CHECK( image );
62 int UtcDaliResourceImageNew02(void)
64 TestApplication application;
66 tet_infoline("UtcDaliREsourceImageNew02 - ResourceImage New( const std::string& url, ImageDimensions size, FittingMode scalingMode, SamplingMode samplingMode, bool orientationCorrection = true )");
68 // invoke default handle constructor
71 DALI_TEST_CHECK( !image );
74 image = ResourceImage::New(gTestImageFilename, ImageDimensions( 128, 256 ), FittingMode::FIT_HEIGHT );
76 DALI_TEST_CHECK( image );
81 int UtcDaliResourceImageDownCast(void)
83 TestApplication application;
84 tet_infoline("Testing Dali::ResourceImage::DownCast()");
86 ResourceImage image = ResourceImage::New(gTestImageFilename);
88 BaseHandle object(image);
90 ResourceImage image2 = ResourceImage::DownCast(object);
91 DALI_TEST_CHECK(image2);
93 ResourceImage image3 = DownCast< ResourceImage >(object);
94 DALI_TEST_CHECK(image3);
96 BaseHandle unInitializedObject;
97 ResourceImage image4 = ResourceImage::DownCast(unInitializedObject);
98 DALI_TEST_CHECK(!image4);
100 ResourceImage image5 = DownCast< ResourceImage >(unInitializedObject);
101 DALI_TEST_CHECK(!image5);
103 Image image6 = ResourceImage::New(gTestImageFilename);
104 ResourceImage image7 = ResourceImage::DownCast(image6);
105 DALI_TEST_CHECK(image7);
110 int UtcDaliResourceImageGetImageSize(void)
112 TestApplication application;
113 TestPlatformAbstraction& platform = application.GetPlatform();
115 tet_infoline("UtcDaliResourceImageGetImageSize - ResourceImage::GetImageSize()");
117 Vector2 testSize(8.0f, 16.0f);
118 platform.SetClosestImageSize(testSize);
120 const ImageDimensions size = ResourceImage::GetImageSize(gTestImageFilename);
122 DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
123 DALI_TEST_EQUALS( Vector2( size.GetX(), size.GetY() ), testSize, TEST_LOCATION);
128 int UtcDaliResourceImageGetUrl(void)
130 TestApplication application;
132 tet_infoline("UtcDaliResourceImageGetFilename - ResourceImage::GetUrl()");
134 // invoke default handle constructor
137 DALI_TEST_CHECK( !image );
140 image = ResourceImage::New(gTestImageFilename);
142 DALI_TEST_EQUALS( image.GetUrl(), gTestImageFilename, TEST_LOCATION);
147 int UtcDaliResourceImageGetLoadingState01(void)
149 TestApplication application;
150 tet_infoline("UtcDaliResourceImageGetLoadingState01");
152 ResourceImage image = ResourceImage::New(gTestImageFilename);
153 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
155 // simulate load success
156 PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
159 // Test state == ResourceLoadingSucceeded
160 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
165 int UtcDaliResourceImageGetLoadingState02(void)
167 TestApplication application;
169 tet_infoline("UtcDaliResourceImageGetLoadingState02");
171 // invoke default handle constructor
174 DALI_TEST_CHECK( !image );
177 image = ResourceImage::New(gTestImageFilename);
179 // Test state == ResourceLoadingFailed
180 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingFailed);
182 PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
185 // Test state == ResourceLoadingFailed
186 DALI_TEST_CHECK(image.GetLoadingState() == ResourceLoadingSucceeded);
190 static bool SignalLoadFlag = false;
192 static void SignalLoadHandler(ResourceImage image)
194 tet_infoline("Received image load finished signal");
196 SignalLoadFlag = true;
200 int UtcDaliResourceImageSignalLoadingFinished(void)
202 TestApplication application;
204 tet_infoline("UtcDaliResourceImageSignalLoadingFinished");
206 SignalLoadFlag = false;
208 PrepareResourceImage( application, 100u, 100u, Pixel::RGBA8888 );
209 ResourceImage image = ResourceImage::New(gTestImageFilename);
211 image.LoadingFinishedSignal().Connect( SignalLoadHandler );
213 application.SendNotification();
214 application.Render(16);
216 DALI_TEST_CHECK( SignalLoadFlag == true );