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.
19 #include <dali/dali.h>
20 #include <dali-test-suite-utils.h>
21 #include <dali/devel-api/adaptor-framework/gif-loading.h>
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";
34 // this image if not exist, for negative test
35 static const char* gGifNonExist = "non-exist.gif";
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 )
40 DALI_TEST_EQUALS( pixelDataList.size(), frameCount, TEST_LOCATION );
41 DALI_TEST_EQUALS( frameDelayList.Size(), frameCount, TEST_LOCATION );
43 for( uint32_t idx = 0; idx<frameCount; idx++ )
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 );
53 void utc_dali_gif_loader_startup(void)
55 test_return_value = TET_UNDEF;
58 void utc_dali_gif_loader_cleanup(void)
60 test_return_value = TET_PASS;
63 int UtcDaliGifLoadingP(void)
65 std::vector<Dali::PixelData> pixelDataList;
66 Dali::Vector<uint32_t> frameDelayList;
68 std::unique_ptr<Dali::GifLoading> gifLoading = GifLoading::New( gGif_100_None, true );
69 bool succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList );
71 // Check that the loading succeed
72 DALI_TEST_CHECK( succeed );
73 VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u );
75 pixelDataList.clear();
76 gifLoading = GifLoading::New( gGif_100_Prev, true );
77 succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList );
78 // Check that the loading succeed
79 DALI_TEST_CHECK( succeed );
80 VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u );
82 pixelDataList.clear();
83 gifLoading = GifLoading::New( gGif_100_Bgnd, true );
84 succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList );
86 // Check that the loading succeed
87 DALI_TEST_CHECK( succeed );
88 VerifyLoad( pixelDataList, frameDelayList, 5u, 100u, 100u, 1000u );
93 int UtcDaliGifLoadingN(void)
95 std::vector<Dali::PixelData> pixelDataList;
96 Dali::Vector<uint32_t> frameDelayList;
98 std::unique_ptr<Dali::GifLoading> gifLoading = GifLoading::New( gGifNonExist, true );
99 bool succeed = gifLoading->LoadAllFrames( pixelDataList, frameDelayList );
101 // Check that the loading failed
102 DALI_TEST_CHECK( !succeed );
104 // Check that both pixelDataList and frameDelayList are empty
105 DALI_TEST_EQUALS( pixelDataList.size(), 0u, TEST_LOCATION );
106 DALI_TEST_EQUALS( frameDelayList.Size(), 0u, TEST_LOCATION );
111 int UtcDaliGifLoadingGetImageSizeP(void)
113 std::unique_ptr<Dali::GifLoading> gifLoading = GifLoading::New( gGif_100_None, true );
114 ImageDimensions imageSize = gifLoading->GetImageSize();
116 // Check that the image size is [100, 100]
117 DALI_TEST_EQUALS( imageSize.GetWidth(), 100u, TEST_LOCATION );
118 DALI_TEST_EQUALS( imageSize.GetHeight(), 100u, TEST_LOCATION );
123 int UtcDaliGifLoadingGetImageSizeN(void)
125 std::unique_ptr<Dali::GifLoading> gifLoading = GifLoading::New( gGifNonExist, true );
126 ImageDimensions imageSize = gifLoading->GetImageSize();
128 // Check that it returns zero size when the gif is not valid
129 DALI_TEST_EQUALS( imageSize.GetWidth(), 0u, TEST_LOCATION );
130 DALI_TEST_EQUALS( imageSize.GetHeight(), 0u, TEST_LOCATION );