1 /*
2 * Copyright (c) 2025 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
18 #include "dcamera.h"
19 #include "constants.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedHardware {
25 class DCameraTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp(void);
30 void TearDown(void);
31 };
32
SetUpTestCase(void)33 void DCameraTest::SetUpTestCase(void)
34 {
35 }
36
TearDownTestCase(void)37 void DCameraTest::TearDownTestCase(void)
38 {
39 }
40
SetUp(void)41 void DCameraTest::SetUp(void)
42 {
43 }
44
TearDown(void)45 void DCameraTest::TearDown(void)
46 {
47 }
48
49 /**
50 * @tc.name: MapToExternalRetCode_001
51 * @tc.desc: Verify MapToExternalRetCode
52 * @tc.type: FUNC
53 * @tc.require: AR
54 */
55 HWTEST_F(DCameraTest, MapToExternalRetCode_001, TestSize.Level1)
56 {
57 CamRetCode result = MapToExternalRetCode(DCamRetCode::SUCCESS);
58 EXPECT_EQ(result, CamRetCode::NO_ERROR);
59
60 result = MapToExternalRetCode(DCamRetCode::CAMERA_BUSY);
61 EXPECT_EQ(result, CamRetCode::CAMERA_BUSY);
62
63 result = MapToExternalRetCode(DCamRetCode::INVALID_ARGUMENT);
64 EXPECT_EQ(result, CamRetCode::INVALID_ARGUMENT);
65
66 result = MapToExternalRetCode(DCamRetCode::METHOD_NOT_SUPPORTED);
67 EXPECT_EQ(result, CamRetCode::METHOD_NOT_SUPPORTED);
68
69 result = MapToExternalRetCode(DCamRetCode::CAMERA_OFFLINE);
70 EXPECT_EQ(result, CamRetCode::CAMERA_CLOSED);
71
72 result = MapToExternalRetCode(DCamRetCode::EXCEED_MAX_NUMBER);
73 EXPECT_EQ(result, CamRetCode::INSUFFICIENT_RESOURCES);
74
75 result = MapToExternalRetCode(DCamRetCode::FAILED);
76 EXPECT_EQ(result, CamRetCode::DEVICE_ERROR);
77
78 result = MapToExternalRetCode(static_cast<DCamRetCode>(999));
79 EXPECT_EQ(result, CamRetCode::DEVICE_ERROR);
80 }
81
82 /**
83 * @tc.name: SplitString_001
84 * @tc.desc: Verify SplitString
85 * @tc.type: FUNC
86 * @tc.require: AR
87 */
88 HWTEST_F(DCameraTest, SplitString_001, TestSize.Level1)
89 {
90 std::string input = "";
91 std::string delimiter = ",";
92 std::vector<std::string> tokens;
93 SplitString(input, tokens, delimiter);
94 EXPECT_TRUE(tokens.empty());
95 }
96
97 /**
98 * @tc.name: Base64Encode_001
99 * @tc.desc: Verify Base64Encode and Base64Decode
100 * @tc.type: FUNC
101 * @tc.require: AR
102 */
103 HWTEST_F(DCameraTest, Base64Encode_001, TestSize.Level1)
104 {
105 const unsigned char* input = nullptr;
106 unsigned int length = 0;
107
108 std::string result = Base64Encode(input, length);
109 EXPECT_EQ(result, "");
110
111 length = 1;
112 result = Base64Encode(input, length);
113 EXPECT_EQ(result, "");
114
115 std::string ret = Base64Decode(result);
116 EXPECT_EQ(ret, "");
117 }
118
119 /**
120 * @tc.name: Base64Encode_002
121 * @tc.desc: Verify Base64Encode and Base64Decode
122 * @tc.type: FUNC
123 * @tc.require: AR
124 */
125 HWTEST_F(DCameraTest, Base64Encode_002, TestSize.Level1)
126 {
127 const unsigned char input[] = "A";
128 unsigned int length = 1;
129
130 std::string result = Base64Encode(input, length);
131 EXPECT_FALSE(result.empty());
132
133 std::string ret = Base64Decode(result);
134 EXPECT_FALSE(ret.empty());
135 }
136
137 /**
138 * @tc.name: Base64Encode_003
139 * @tc.desc: Verify Base64Encode and Base64Decode
140 * @tc.type: FUNC
141 * @tc.require: AR
142 */
143 HWTEST_F(DCameraTest, Base64Encode_003, TestSize.Level1)
144 {
145 const unsigned char input[] = "AB";
146 unsigned int length = 2;
147
148 std::string result = Base64Encode(input, length);
149 EXPECT_FALSE(result.empty());
150
151 std::string ret = Base64Decode(result);
152 EXPECT_FALSE(ret.empty());
153 }
154
155 /**
156 * @tc.name: Base64Encode_004
157 * @tc.desc: Verify Base64Encode and Base64Decode
158 * @tc.type: FUNC
159 * @tc.require: AR
160 */
161 HWTEST_F(DCameraTest, Base64Encode_004, TestSize.Level1)
162 {
163 const unsigned char input[] = "ABC";
164 unsigned int length = 3;
165
166 std::string result = Base64Encode(input, length);
167 EXPECT_FALSE(result.empty());
168
169 std::string ret = Base64Decode(result);
170 EXPECT_FALSE(ret.empty());
171 }
172
173 /**
174 * @tc.name: Base64Encode_005
175 * @tc.desc: Verify Base64Encode and Base64Decode
176 * @tc.type: FUNC
177 * @tc.require: AR
178 */
179 HWTEST_F(DCameraTest, Base64Encode_005, TestSize.Level1)
180 {
181 const unsigned char input[] = "ABCD";
182 unsigned int length = 4;
183
184 std::string result = Base64Encode(input, length);
185 EXPECT_FALSE(result.empty());
186
187 std::string ret = Base64Decode(result);
188 EXPECT_FALSE(ret.empty());
189 }
190
191 /**
192 * @tc.name: Base64Encode_006
193 * @tc.desc: Verify Base64Encode and Base64Decode
194 * @tc.type: FUNC
195 * @tc.require: AR
196 */
197 HWTEST_F(DCameraTest, Base64Encode_006, TestSize.Level1)
198 {
199 const unsigned char input[] = "Hello World";
200 unsigned int length = 11;
201
202 std::string result = Base64Encode(input, length);
203 EXPECT_FALSE(result.empty());
204
205 std::string ret = Base64Decode(result);
206 EXPECT_FALSE(ret.empty());
207 }
208
209 /**
210 * @tc.name: GetCurrentLocalTimeStamp_001
211 * @tc.desc: Verify GetCurrentLocalTimeStamp
212 * @tc.type: FUNC
213 * @tc.require: AR
214 */
215 HWTEST_F(DCameraTest, GetCurrentLocalTimeStamp_001, TestSize.Level1)
216 {
217 uint64_t ret = GetCurrentLocalTimeStamp();
218 EXPECT_TRUE(ret);
219 }
220 }
221 }