Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-ImageLoading.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 <stdlib.h>
19 #include <dali/dali.h>
20 #include <dali-test-suite-utils.h>
21 #include <dali/devel-api/adaptor-framework/image-loading.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
36 void utc_dali_load_image_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void utc_dali_load_image_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 int UtcDaliLoadImageP(void)
47 {
48   Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( gImage_34_RGBA );
49   DALI_TEST_CHECK( pixelBuffer );
50   DALI_TEST_EQUALS( pixelBuffer.GetWidth(), 34u, TEST_LOCATION );
51   DALI_TEST_EQUALS( pixelBuffer.GetHeight(), 34u, TEST_LOCATION );
52   DALI_TEST_EQUALS( pixelBuffer.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION  );
53
54   Devel::PixelBuffer pixelBuffer2 = Dali::LoadImageFromFile( gImage_128_RGB );
55   DALI_TEST_CHECK( pixelBuffer2 );
56   DALI_TEST_EQUALS( pixelBuffer2.GetWidth(), 128u, TEST_LOCATION  );
57   DALI_TEST_EQUALS( pixelBuffer2.GetHeight(), 128u, TEST_LOCATION  );
58   DALI_TEST_EQUALS( pixelBuffer2.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION  );
59
60   END_TEST;
61 }
62
63 int UtcDaliLoadImageN(void)
64 {
65   Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( gImageNonExist );
66   DALI_TEST_CHECK( !pixelBuffer );
67
68   END_TEST;
69 }
70
71
72 int UtcDaliDownloadImageP(void)
73 {
74   std::string url("file://");
75   url.append( gImage_34_RGBA );
76
77   std::string url2("file://");
78   url2.append( gImage_128_RGB );
79
80   Devel::PixelBuffer pixelBuffer = Dali::DownloadImageSynchronously( url );
81   DALI_TEST_CHECK( pixelBuffer );
82   DALI_TEST_EQUALS( pixelBuffer.GetWidth(), 34u, TEST_LOCATION );
83   DALI_TEST_EQUALS( pixelBuffer.GetHeight(), 34u, TEST_LOCATION );
84   DALI_TEST_EQUALS( pixelBuffer.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION  );
85
86   Devel::PixelBuffer pixelBuffer2 = Dali::DownloadImageSynchronously( url2 );
87   DALI_TEST_CHECK( pixelBuffer2 );
88   DALI_TEST_EQUALS( pixelBuffer2.GetWidth(), 128u, TEST_LOCATION  );
89   DALI_TEST_EQUALS( pixelBuffer2.GetHeight(), 128u, TEST_LOCATION  );
90   DALI_TEST_EQUALS( pixelBuffer2.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION  );
91
92   END_TEST;
93 }
94
95 int UtcDaliDownloadImageN(void)
96 {
97   Devel::PixelBuffer pixelBuffer = Dali::DownloadImageSynchronously( gImageNonExist );
98   DALI_TEST_CHECK( !pixelBuffer );
99
100   END_TEST;
101 }