Formatting automated-tests
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-GifLoading.cpp
1 /*
2  * Copyright (c) 2020 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 <dali-test-suite-utils.h>
19 #include <dali/dali.h>
20 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
21 #include <stdlib.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, uint32_t frameCount, uint32_t width, uint32_t height, uint32_t delay)
38 {
39   DALI_TEST_EQUALS(pixelDataList.size(), frameCount, TEST_LOCATION);
40   DALI_TEST_EQUALS(frameDelayList.Size(), frameCount, TEST_LOCATION);
41
42   for(uint32_t idx = 0; idx < frameCount; idx++)
43   {
44     // Check the image size and delay of each frame
45     DALI_TEST_EQUALS(pixelDataList[idx].GetWidth(), width, TEST_LOCATION);
46     DALI_TEST_EQUALS(pixelDataList[idx].GetHeight(), height, TEST_LOCATION);
47     DALI_TEST_EQUALS(frameDelayList[idx], delay, TEST_LOCATION);
48   }
49 }
50 } // namespace
51
52 void utc_dali_animated_image_loader_startup(void)
53 {
54   test_return_value = TET_UNDEF;
55 }
56
57 void utc_dali_animated_image_loader_cleanup(void)
58 {
59   test_return_value = TET_PASS;
60 }
61
62 int UtcDaliAnimatedImageLoadingP(void)
63 {
64   std::vector<Dali::PixelData> pixelDataList;
65   Dali::Vector<uint32_t>       frameDelayList;
66
67   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGif_100_None, true);
68   bool                       succeed              = animatedImageLoading.LoadNextNFrames(0u, animatedImageLoading.GetImageCount(), pixelDataList);
69   frameDelayList.Clear();
70   frameDelayList.Resize(animatedImageLoading.GetImageCount(), 0);
71   for(uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i)
72   {
73     frameDelayList[i] = animatedImageLoading.GetFrameInterval(i);
74   }
75
76   // Check that the loading succeed
77   DALI_TEST_CHECK(succeed);
78   VerifyLoad(pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u);
79
80   pixelDataList.clear();
81   animatedImageLoading = Dali::AnimatedImageLoading::New(gGif_100_Prev, true);
82   succeed              = animatedImageLoading.LoadNextNFrames(0u, animatedImageLoading.GetImageCount(), pixelDataList);
83   frameDelayList.Clear();
84   frameDelayList.Resize(animatedImageLoading.GetImageCount(), 0);
85   for(uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i)
86   {
87     frameDelayList[i] = animatedImageLoading.GetFrameInterval(i);
88   }
89
90   // Check that the loading succeed
91   DALI_TEST_CHECK(succeed);
92   VerifyLoad(pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u);
93
94   pixelDataList.clear();
95   animatedImageLoading = Dali::AnimatedImageLoading::New(gGif_100_Bgnd, true);
96   succeed              = animatedImageLoading.LoadNextNFrames(0u, animatedImageLoading.GetImageCount(), pixelDataList);
97   frameDelayList.Clear();
98   frameDelayList.Resize(animatedImageLoading.GetImageCount(), 0);
99   for(uint32_t i = 0; i < animatedImageLoading.GetImageCount(); ++i)
100   {
101     frameDelayList[i] = animatedImageLoading.GetFrameInterval(i);
102   }
103
104   // Check that the loading succeed
105   DALI_TEST_CHECK(succeed);
106   VerifyLoad(pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u);
107
108   END_TEST;
109 }
110
111 int UtcDaliAnimatedImageLoadingN(void)
112 {
113   std::vector<Dali::PixelData> pixelDataList;
114   Dali::Vector<uint32_t>       frameDelayList;
115
116   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGifNonExist, true);
117   bool                       succeed              = animatedImageLoading.LoadNextNFrames(0u, animatedImageLoading.GetImageCount(), pixelDataList);
118
119   // Check that the loading failed
120   DALI_TEST_CHECK(!succeed);
121
122   // Check that both pixelDataList and frameDelayList are empty
123   DALI_TEST_EQUALS(pixelDataList.size(), 0u, TEST_LOCATION);
124
125   END_TEST;
126 }
127
128 int UtcDaliAnimatedImageLoadingGetImageSizeP(void)
129 {
130   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGif_100_None, true);
131   ImageDimensions            imageSize            = animatedImageLoading.GetImageSize();
132
133   // Check that the image size is [100, 100]
134   DALI_TEST_EQUALS(imageSize.GetWidth(), 100u, TEST_LOCATION);
135   DALI_TEST_EQUALS(imageSize.GetHeight(), 100u, TEST_LOCATION);
136
137   END_TEST;
138 }
139
140 int UtcDaliAnimatedImageLoadingGetImageSizeN(void)
141 {
142   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGifNonExist, true);
143   ImageDimensions            imageSize            = animatedImageLoading.GetImageSize();
144
145   // Check that it returns zero size when the animated image is not valid
146   DALI_TEST_EQUALS(imageSize.GetWidth(), 0u, TEST_LOCATION);
147   DALI_TEST_EQUALS(imageSize.GetHeight(), 0u, TEST_LOCATION);
148
149   END_TEST;
150 }