Fix a gif crash
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-GifLoading.cpp
1 /*
2  * Copyright (c) 2022 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
30 // this image if not exist, for negative test
31 static const char* gGifNonExist = "non-exist.gif";
32
33 // this image exists but it is not a gif file.
34 static const char* gGifInvalid = TEST_RESOURCE_DIR "/invalid.gif";
35
36 } // namespace
37
38 void utc_dali_animated_image_loader_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void utc_dali_animated_image_loader_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 int UtcDaliAnimatedImageLoadingGetImageSizeP(void)
49 {
50   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGif_100_None, true);
51   ImageDimensions            imageSize            = animatedImageLoading.GetImageSize();
52
53   // Check that the image size is [100, 100]
54   DALI_TEST_EQUALS(imageSize.GetWidth(), 100u, TEST_LOCATION);
55   DALI_TEST_EQUALS(imageSize.GetHeight(), 100u, TEST_LOCATION);
56
57   END_TEST;
58 }
59
60 int UtcDaliAnimatedImageLoadingGetImageSizeN(void)
61 {
62   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGifNonExist, true);
63   ImageDimensions            imageSize            = animatedImageLoading.GetImageSize();
64
65   // Check that it returns zero size when the animated image is not valid
66   DALI_TEST_EQUALS(imageSize.GetWidth(), 0u, TEST_LOCATION);
67   DALI_TEST_EQUALS(imageSize.GetHeight(), 0u, TEST_LOCATION);
68
69   END_TEST;
70 }
71
72 int UtcDaliAnimatedImageLoadingInvalidGif(void)
73 {
74   Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGifInvalid, true);
75   Dali::Devel::PixelBuffer   pixelBuffer          = animatedImageLoading.LoadFrame(0);
76
77   // The pixel buffer should be empty.
78   DALI_TEST_CHECK(!pixelBuffer);
79
80   END_TEST;
81 }