b87ce8eb6084423ee897bd34dca8cf1d401f987b
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-GifLoading.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/animated-image-loading.h>
22
23 using namespace Dali;
24
25 namespace
26 {
27 // test gif image, resolution: 100*100, 5 frames, delay: 1 second, disposal method: none
28 static const char* gGif_100_None = TEST_RESOURCE_DIR "/canvas-none.gif";
29 // test gif image, resolution: 100*100, 5 frames, delay: 1 second, disposal method: none for first frame and previous for the rest
30 static const char* gGif_100_Prev = TEST_RESOURCE_DIR "/canvas-prev.gif";
31 // test gif image, resolution: 100*100, 5 frames, delay: 1 second, disposal method: background
32 static const char* gGif_100_Bgnd = TEST_RESOURCE_DIR "/canvas-bgnd.gif";
33
34 // this image if not exist, for negative test
35 static const char* gGifNonExist = "non-exist.gif";
36
37 void VerifyLoad( std::vector<Dali::PixelData>& pixelDataList, Dali::Vector<uint32_t>& frameDelayList,
38                  uint32_t frameCount, uint32_t width, uint32_t height, uint32_t delay )
39 {
40   DALI_TEST_EQUALS( pixelDataList.size(), frameCount, TEST_LOCATION );
41   DALI_TEST_EQUALS( frameDelayList.Size(), frameCount, TEST_LOCATION );
42
43   for( uint32_t idx = 0; idx<frameCount; idx++ )
44   {
45     // Check the image size and delay of each frame
46     DALI_TEST_EQUALS( pixelDataList[idx].GetWidth(), width, TEST_LOCATION );
47     DALI_TEST_EQUALS( pixelDataList[idx].GetHeight(), height, TEST_LOCATION );
48     DALI_TEST_EQUALS( frameDelayList[idx], delay, TEST_LOCATION );
49   }
50 }
51 }
52
53 void utc_dali_animated_image_loader_startup(void)
54 {
55   test_return_value = TET_UNDEF;
56 }
57
58 void utc_dali_animated_image_loader_cleanup(void)
59 {
60   test_return_value = TET_PASS;
61 }
62
63 int UtcDaliAnimatedImageLoadingP(void)
64 {
65   std::vector<Dali::PixelData> pixelDataList;
66   Dali::Vector<uint32_t> frameDelayList;
67
68   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New( gGif_100_None, true );
69   bool succeed = animatedImageLoading.LoadNextNFrames( 0u, animatedImageLoading.GetImageCount(), pixelDataList );
70   frameDelayList.Clear();
71   frameDelayList.Resize( animatedImageLoading.GetImageCount(), 0 );
72   for( uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i )
73   {
74     frameDelayList[i] = animatedImageLoading.GetFrameInterval( i );
75   }
76
77   // Check that the loading succeed
78   DALI_TEST_CHECK( succeed );
79   VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u );
80
81   pixelDataList.clear();
82   animatedImageLoading = Dali::AnimatedImageLoading::New( gGif_100_Prev, true );
83   succeed = animatedImageLoading.LoadNextNFrames( 0u, animatedImageLoading.GetImageCount(), pixelDataList );
84   frameDelayList.Clear();
85   frameDelayList.Resize( animatedImageLoading.GetImageCount(), 0 );
86   for( uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i )
87   {
88     frameDelayList[i] = animatedImageLoading.GetFrameInterval( i );
89   }
90
91   // Check that the loading succeed
92   DALI_TEST_CHECK( succeed );
93   VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u );
94
95   pixelDataList.clear();
96   animatedImageLoading = Dali::AnimatedImageLoading::New( gGif_100_Bgnd, true );
97   succeed = animatedImageLoading.LoadNextNFrames( 0u, animatedImageLoading.GetImageCount(), pixelDataList );
98   frameDelayList.Clear();
99   frameDelayList.Resize( animatedImageLoading.GetImageCount(), 0 );
100   for( uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i )
101   {
102     frameDelayList[i] = animatedImageLoading.GetFrameInterval( i );
103   }
104
105   // Check that the loading succeed
106   DALI_TEST_CHECK( succeed );
107   VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u  );
108
109   END_TEST;
110 }
111
112 int UtcDaliAnimatedImageLoadingN(void)
113 {
114   std::vector<Dali::PixelData> pixelDataList;
115   Dali::Vector<uint32_t> frameDelayList;
116
117   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New( gGifNonExist, true );
118   bool succeed = animatedImageLoading.LoadNextNFrames( 0u, animatedImageLoading.GetImageCount(), pixelDataList );
119
120   // Check that the loading failed
121   DALI_TEST_CHECK( !succeed );
122
123   // Check that both pixelDataList and frameDelayList are empty
124   DALI_TEST_EQUALS( pixelDataList.size(), 0u, TEST_LOCATION );
125
126   END_TEST;
127 }
128
129 int UtcDaliAnimatedImageLoadingGetImageSizeP(void)
130 {
131   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New( gGif_100_None, true );
132   ImageDimensions imageSize = animatedImageLoading.GetImageSize();
133
134   // Check that the image size is [100, 100]
135   DALI_TEST_EQUALS( imageSize.GetWidth(), 100u, TEST_LOCATION );
136   DALI_TEST_EQUALS( imageSize.GetHeight(), 100u, TEST_LOCATION );
137
138   END_TEST;
139 }
140
141 int UtcDaliAnimatedImageLoadingGetImageSizeN(void)
142 {
143   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New( gGifNonExist, true );
144   ImageDimensions imageSize = animatedImageLoading.GetImageSize();
145
146   // Check that it returns zero size when the animated image is not valid
147   DALI_TEST_EQUALS( imageSize.GetWidth(), 0u, TEST_LOCATION );
148   DALI_TEST_EQUALS( imageSize.GetHeight(), 0u, TEST_LOCATION );
149
150   END_TEST;
151 }