2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 #include <tzplatform_config.h>
19 #include "libmm_png_unittest.h"
20 #include "FileInterface.h"
21 #include "mm_util_png.h"
22 #include "mm_util_image.h"
24 #define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-png-unittest.png")
25 #define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-png-result.png")
27 using ::testing::InitGoogleTest;
28 using ::testing::Test;
29 using ::testing::TestCase;
31 class libmm_png_Test : public ::testing::Test {
34 std::cout << "SetUp()" << std::endl;
38 std::cout << "TearDown()" << std::endl;
42 TEST(libmm_png_Test, mm_util_decode_from_png_file_p)
44 int ret = MM_UTIL_ERROR_NONE;
45 mm_util_image_h decode_image = NULL;
47 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
48 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
49 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
51 mm_image_destroy_image(decode_image);
54 TEST(libmm_png_Test, mm_util_decode_from_png_file_n)
56 int ret = MM_UTIL_ERROR_NONE;
57 mm_util_image_h decode_image = NULL;
59 ret = mm_util_decode_from_png_file(NULL, &decode_image);
60 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
62 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, NULL);
63 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
66 TEST(libmm_png_Test, mm_util_decode_from_png_memory_p)
68 int ret = MM_UTIL_ERROR_NONE;
70 mm_util_image_h decode_image = NULL;
72 FileInterface IFile = FileInterface(DECODE_FILE_PATH);
73 err = IFile.ReadData();
76 ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, &decode_image);
77 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
78 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
80 mm_image_destroy_image(decode_image);
83 TEST(libmm_png_Test, mm_util_decode_from_png_memory_n)
85 int ret = MM_UTIL_ERROR_NONE;
87 mm_util_image_h decode_image = NULL;
89 FileInterface IFile = FileInterface(DECODE_FILE_PATH);
90 err = IFile.ReadData();
93 ret = mm_util_decode_from_png_memory(NULL, IFile.readDataSize, &decode_image);
94 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
96 ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, NULL);
97 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
100 TEST(libmm_png_Test, mm_util_encode_to_png_file_p)
102 int ret = MM_UTIL_ERROR_NONE;
103 mm_util_image_h decode_image = NULL;
105 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
106 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
107 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
109 ret = mm_util_encode_to_png_file(decode_image, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
110 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
112 mm_image_destroy_image(decode_image);
115 TEST(libmm_png_Test, mm_util_encode_to_png_file_n)
117 int ret = MM_UTIL_ERROR_NONE;
118 mm_util_image_h decode_image = NULL;
120 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
121 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
122 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
124 ret = mm_util_encode_to_png_file(NULL, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
125 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
127 ret = mm_util_encode_to_png_file(decode_image, MM_UTIL_COMPRESSION_6, NULL);
128 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
130 mm_image_destroy_image(decode_image);
133 TEST(libmm_png_Test, mm_util_encode_to_png_memory_p)
135 int ret = MM_UTIL_ERROR_NONE;
136 mm_util_image_h decode_image = NULL;
140 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
141 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
142 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
144 ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, &buffer, &size);
145 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
146 EXPECT_TRUE(buffer != NULL);
149 mm_image_destroy_image(decode_image);
155 TEST(libmm_png_Test, mm_util_encode_to_png_memory_n)
157 int ret = MM_UTIL_ERROR_NONE;
158 mm_util_image_h decode_image = NULL;
162 ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
163 EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
164 EXPECT_TRUE(mm_image_is_valid_image(decode_image));
166 ret = mm_util_encode_to_png_memory(NULL, MM_UTIL_COMPRESSION_6, &buffer, &size);
167 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
169 ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, NULL, &size);
170 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
172 ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, &buffer, NULL);
173 EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
175 mm_image_destroy_image(decode_image);
178 int main(int argc, char **argv)
180 InitGoogleTest(&argc, argv);
182 return RUN_ALL_TESTS();