• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <fcntl.h>
18 #include <fstream>
19 #include "image_utils.h"
20 #include "image_trace.h"
21 #include "source_stream.h"
22 #include "istream_source_stream.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::Media;
26 using namespace OHOS::MultimediaPlugin;
27 namespace OHOS {
28 namespace Multimedia {
29 static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test.jpg";
30 
31 class ImageUtilsTest : public testing::Test {
32 public:
ImageUtilsTest()33     ImageUtilsTest() {}
~ImageUtilsTest()34     ~ImageUtilsTest() {}
35 };
36 
37 /**
38  * @tc.name: ImageTraceTest001
39  * @tc.desc: test SetData and ClearData data type is bool
40  * @tc.type: FUNC
41  */
42 HWTEST_F(ImageUtilsTest, ImageTraceTest001, TestSize.Level3)
43 {
44     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest001 start";
45     const std::string title = "title";
46     ImageTrace imagetrace(title);
47     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest001 end";
48 }
49 
50 /**
51  * @tc.name: ImageTraceTest002
52  * @tc.desc: test SetData and ClearData data type is bool
53  * @tc.type: FUNC
54  */
55 HWTEST_F(ImageUtilsTest, ImageTraceTest002, TestSize.Level3)
56 {
57     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest002 start";
58     const char *fmt = nullptr;
59     ImageTrace imagetrace(fmt);
60     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest002 end";
61 }
62 
63 /**
64  * @tc.name: ImageTraceTest003
65  * @tc.desc: test SetData and ClearData data type is bool
66  * @tc.type: FUNC
67  */
68 HWTEST_F(ImageUtilsTest, ImageTraceTest003, TestSize.Level3)
69 {
70     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest003 start";
71     const char *fmt = "mytrace";
72     ImageTrace imagetrace(fmt);
73     GTEST_LOG_(INFO) << "ImageUtilsTest: ImageTraceTest003 end";
74 }
75 
76 /**
77  * @tc.name: GetFileSize001
78  * @tc.desc: ImageUtils::GetFileSize(const string &pathName, size_t &size)
79  * @tc.type: FUNC
80  */
81 HWTEST_F(ImageUtilsTest, GetFileSize001, TestSize.Level3)
82 {
83     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize001 start";
84     ImageUtils imageUtils;
85     size_t size;
86     imageUtils.GetFileSize(IMAGE_INPUT_JPEG_PATH, size);
87     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize001 end";
88 }
89 
90 /**
91  * @tc.name: GetFileSize002
92  * @tc.desc: ImageUtils::GetFileSize(const string &pathName, size_t &size)
93  * @tc.type: FUNC
94  */
95 HWTEST_F(ImageUtilsTest, GetFileSize002, TestSize.Level3)
96 {
97     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize002 start";
98     ImageUtils imageUtils;
99     size_t size;
100     const std::string path = "";
101     imageUtils.GetFileSize(path, size);
102     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize002 end";
103 }
104 
105 /**
106  * @tc.name: GetFileSize003
107  * @tc.desc: ImageUtils::GetFileSize(const string &pathName, size_t &size)
108  * @tc.type: FUNC
109  */
110 HWTEST_F(ImageUtilsTest, GetFileSize003, TestSize.Level3)
111 {
112     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize003 start";
113     ImageUtils imageUtils;
114     size_t size;
115     const std::string path = "test/aaa";
116     imageUtils.GetFileSize(path, size);
117     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize003 end";
118 }
119 
120 /**
121  * @tc.name: GetFileSize004
122  * @tc.desc: bool ImageUtils::GetFileSize(const int fd, size_t &size)
123  * @tc.type: FUNC
124  */
125 HWTEST_F(ImageUtilsTest, GetFileSize004, TestSize.Level3)
126 {
127     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize004 start";
128     const int fd = open("/data/local/tmp/image/test.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
129     ImageUtils imageUtils;
130     size_t size;
131     imageUtils.GetFileSize(fd, size);
132     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize004 end";
133 }
134 
135 /**
136  * @tc.name: GetFileSize005
137  * @tc.desc: bool ImageUtils::GetFileSize(const int fd, size_t &size)
138  * @tc.type: FUNC
139  */
140 HWTEST_F(ImageUtilsTest, GetFileSize005, TestSize.Level3)
141 {
142     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize005 start";
143     const int fd = -1;
144     ImageUtils imageUtils;
145     size_t size;
146     imageUtils.GetFileSize(fd, size);
147     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize005 end";
148 }
149 
150 /**
151  * @tc.name: GetFileSize006
152  * @tc.desc: bool ImageUtils::GetFileSize(const int fd, size_t &size)
153  * @tc.type: FUNC
154  */
155 HWTEST_F(ImageUtilsTest, GetFileSize006, TestSize.Level3)
156 {
157     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize006 start";
158     const int fd = 100;
159     ImageUtils imageUtils;
160     size_t size;
161     imageUtils.GetFileSize(fd, size);
162     GTEST_LOG_(INFO) << "ImageUtilsTest: GetFileSize006 end";
163 }
164 
165 /**
166  * @tc.name: GetPixelBytes001
167  * @tc.desc: bool ImageUtils::GetInputStreamSize(istream &inputStream, size_t &size)
168  * @tc.type: FUNC
169  */
170 HWTEST_F(ImageUtilsTest, GetPixelBytes001, TestSize.Level3)
171 {
172     GTEST_LOG_(INFO) << "ImageUtilsTest: GetPixelBytes001 start";
173     ImageUtils::GetPixelBytes(PixelFormat::RGB_888);
174     ImageUtils::GetPixelBytes(PixelFormat::RGBA_F16);
175     ImageUtils::GetPixelBytes(PixelFormat::NV12);
176     GTEST_LOG_(INFO) << "ImageUtilsTest: GetPixelBytes001 end";
177 }
178 
179 /**
180  * @tc.name: PathToRealPath001
181  * @tc.desc: PathToRealPath
182  * @tc.type: FUNC
183  */
184 HWTEST_F(ImageUtilsTest, PathToRealPath001, TestSize.Level3)
185 {
186     GTEST_LOG_(INFO) << "ImageUtilsTest: PathToRealPath001 start";
187     const string path = "";
188     string realPath;
189     ImageUtils::PathToRealPath(path, realPath);
190     GTEST_LOG_(INFO) << "ImageUtilsTest: PathToRealPath001 end";
191 }
192 
193 /**
194  * @tc.name: PathToRealPath002
195  * @tc.desc: PathToRealPath
196  * @tc.type: FUNC
197  */
198 HWTEST_F(ImageUtilsTest, PathToRealPath002, TestSize.Level3)
199 {
200     GTEST_LOG_(INFO) << "ImageUtilsTest: PathToRealPath002 start";
201     char buffer[PATH_MAX+1] = {'\0'};
202     for (int i = 0; i <= PATH_MAX; i++) {
203         buffer[i] = i;
204     }
205     const string path = buffer;
206     string realPath;
207     ImageUtils::PathToRealPath(path, realPath);
208     GTEST_LOG_(INFO) << "ImageUtilsTest: PathToRealPath002 end";
209 }
210 
211 /**
212  * @tc.name: IsValidImageInfo001
213  * @tc.desc: IsValidImageInfo
214  * @tc.type: FUNC
215  */
216 HWTEST_F(ImageUtilsTest, IsValidImageInfo001, TestSize.Level3)
217 {
218     GTEST_LOG_(INFO) << "ImageUtilsTest: IsValidImageInfo001 start";
219     ImageInfo info;
220     ImageUtils::IsValidImageInfo(info);
221     info.size.width = 0;
222     info.size.height = 0;
223     ImageUtils::IsValidImageInfo(info);
224     info.size.width = 100;
225     info.size.height = 10;
226     ImageUtils::IsValidImageInfo(info);
227     GTEST_LOG_(INFO) << "ImageUtilsTest: IsValidImageInfo001 end";
228 }
229 
230 /**
231  * @tc.name: CheckMulOverflow001
232  * @tc.desc: CheckMulOverflow
233  * @tc.type: FUNC
234  */
235 HWTEST_F(ImageUtilsTest, CheckMulOverflow001, TestSize.Level3)
236 {
237     GTEST_LOG_(INFO) << "ImageUtilsTest: CheckMulOverflow001 start";
238     int32_t width = 0;
239     int32_t height = 0;
240     int32_t bytesPerPixel = 0;
241     ImageUtils::CheckMulOverflow(width, height, bytesPerPixel);
242     GTEST_LOG_(INFO) << "ImageUtilsTest: CheckMulOverflow001 end";
243 }
244 }
245 }