1 /*
2  * Copyright (C) 2023 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 "image_packer_mdk.h"
18 #include "file_packer_stream.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS::Media;
22 
23 namespace OHOS {
24 namespace Multimedia {
25 static constexpr int TEST_FD = -1;
26 static constexpr size_t TEST_SIZE = 0;
27 class ImagePackerMdkTest : public testing::Test {
28 public:
ImagePackerMdkTest()29     ImagePackerMdkTest() {}
~ImagePackerMdkTest()30     ~ImagePackerMdkTest() {}
31 };
32 
33 /**
34  * @tc.name: OH_ImagePacker_Create
35  * @tc.desc: test OH_ImagePacker_Create
36  * @tc.type: FUNC
37  */
38 HWTEST_F(ImagePackerMdkTest, OH_ImagePacker_Create, TestSize.Level3)
39 {
40     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_Create start";
41     napi_env env = nullptr;
42     napi_value* packer = nullptr;
43     int32_t ret = OH_ImagePacker_Create(env, packer);
44     ASSERT_EQ(ret, IMAGE_RESULT_BAD_PARAMETER);
45     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_Create end";
46 }
47 
48 /**
49  * @tc.name: OH_ImagePacker_InitNative
50  * @tc.desc: test OH_ImagePacker_InitNative
51  * @tc.type: FUNC
52  */
53 HWTEST_F(ImagePackerMdkTest, OH_ImagePacker_InitNative, TestSize.Level3)
54 {
55     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_InitNative start";
56     napi_env env = nullptr;
57     napi_value packer = nullptr;
58     ImagePacker_Native*  ret = OH_ImagePacker_InitNative(env, packer);
59     ASSERT_EQ(ret, nullptr);
60     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_InitNative end";
61 }
62 
63 /**
64  * @tc.name: OH_ImagePacker_PackToData
65  * @tc.desc: test OH_ImagePacker_PackToData
66  * @tc.type: FUNC
67  */
68 HWTEST_F(ImagePackerMdkTest, OH_ImagePacker_PackToData, TestSize.Level3)
69 {
70     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_PackToData start";
71     ImagePacker_Native* native = nullptr;
72     napi_value source = nullptr;
73     ImagePacker_Opts opts;
74     uint8_t* outData = nullptr;
75     size_t size = TEST_SIZE;
76     int32_t ret = OH_ImagePacker_PackToData(native, source, &opts, outData, &size);
77     ASSERT_NE(ret, IMAGE_RESULT_SUCCESS);
78     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_PackToData end";
79 }
80 
81 /**
82  * @tc.name: OH_ImagePacker_PackToFile
83  * @tc.desc: test OH_ImagePacker_PackToFile
84  * @tc.type: FUNC
85  */
86 HWTEST_F(ImagePackerMdkTest, OH_ImagePacker_PackToFile, TestSize.Level3)
87 {
88     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_PackToFile start";
89     ImagePacker_Native* native = nullptr;
90     napi_value source = nullptr;
91     ImagePacker_Opts opts;
92     int fd = TEST_FD;
93     int32_t ret = OH_ImagePacker_PackToFile(native, source, &opts, fd);
94     ASSERT_NE(ret, IMAGE_RESULT_SUCCESS);
95     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_PackToFile end";
96 }
97 
98 /**
99  * @tc.name: OH_ImagePacker_Release
100  * @tc.desc: test OH_ImagePacker_Release
101  * @tc.type: FUNC
102  */
103 HWTEST_F(ImagePackerMdkTest, OH_ImagePacker_Release, TestSize.Level3)
104 {
105     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_Release start";
106     ImagePacker_Native* native = nullptr;
107     int32_t ret = OH_ImagePacker_Release(native);
108     ASSERT_EQ(ret, IMAGE_RESULT_SUCCESS);
109     GTEST_LOG_(INFO) << "ImagePackerMdkTest: OH_ImagePacker_Release end";
110 }
111 }
112 }