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 <string>
18 #include <vector>
19 #include <iostream>
20
21 #include "distributed_device_profile_constants.h"
22 #include "distributed_device_profile_log.h"
23 #include "distributed_device_profile_errors.h"
24
25 #include "profile_data_manager.h"
26
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace DistributedDeviceProfile {
30 using namespace std;
31 namespace {
32 const std::string TAG = "ProfileDataManagerTest";
33 }
34 class ProfileDataManagerTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase()42 void ProfileDataManagerTest::SetUpTestCase()
43 {}
44
TearDownTestCase()45 void ProfileDataManagerTest::TearDownTestCase()
46 {}
47
SetUp()48 void ProfileDataManagerTest::SetUp()
49 {}
50
TearDown()51 void ProfileDataManagerTest::TearDown()
52 {}
53
54 /*
55 * @tc.name: Init001
56 * @tc.desc: Init
57 * @tc.type: FUNC
58 * @tc.require:
59 */
60 HWTEST_F(ProfileDataManagerTest, Init001, TestSize.Level1)
61 {
62 ProfileDataManager profileDataManager_;
63 int32_t result = profileDataManager_.Init();
64 EXPECT_EQ(result, 0);
65 }
66
67 /*
68 * @tc.name: UnInit001
69 * @tc.desc: Init
70 * @tc.type: FUNC
71 * @tc.require:
72 */
73 HWTEST_F(ProfileDataManagerTest, UnInit001, TestSize.Level1)
74 {
75 ProfileDataManager profileDataManager_;
76 int32_t result = profileDataManager_.UnInit();
77 EXPECT_EQ(result, 0);
78 }
79
80 /*
81 * @tc.name: PutDeviceProfile_001
82 * @tc.desc: Init
83 * @tc.type: FUNC
84 * @tc.require:
85 */
86 HWTEST_F(ProfileDataManagerTest, PutDeviceProfile_001, TestSize.Level1)
87 {
88 DeviceProfile deviceProfile;
89 deviceProfile.SetDeviceId("deviceId");
90 deviceProfile.SetDeviceId("anything" + SLASHES + "123" + SEPARATOR + "abc");
91 int32_t result = ProfileDataManager::GetInstance().PutDeviceProfile(deviceProfile);
92 EXPECT_EQ(result, DP_INVALID_PARAMS);
93 }
94
95 /*
96 * @tc.name: PutDeviceProfile_002
97 * @tc.desc: Init
98 * @tc.type: FUNC
99 * @tc.require:
100 */
101 HWTEST_F(ProfileDataManagerTest, PutDeviceProfile_002, TestSize.Level1)
102 {
103 DeviceProfile deviceProfile;
104 int32_t result = ProfileDataManager::GetInstance().PutDeviceProfile(deviceProfile);
105 EXPECT_EQ(result, DP_INVALID_PARAMS);
106 }
107
108 /*
109 * @tc.name: FilterInvaildSymbol_001
110 * @tc.desc: Init
111 * @tc.type: FUNC
112 * @tc.require:
113 */
114 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_001, TestSize.Level1)
115 {
116 std::string str = "";
117 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(str);
118 EXPECT_EQ(result, false);
119 }
120
121 /*
122 * @tc.name: FilterInvaildSymbol_002
123 * @tc.desc: Init
124 * @tc.type: FUNC
125 * @tc.require:
126 */
127 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_002, TestSize.Level1)
128 {
129 std::string longString(MAX_STRING_LEN + 1, 'A');
130 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(longString);
131 EXPECT_EQ(result, false);
132 }
133
134 /*
135 * @tc.name: FilterInvaildSymbol_003
136 * @tc.desc: Init
137 * @tc.type: FUNC
138 * @tc.require:
139 */
140 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_003, TestSize.Level1)
141 {
142 std::string str = SEPARATOR;
143 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(str);
144 EXPECT_EQ(result, false);
145 }
146
147 /*
148 * @tc.name: FilterInvaildSymbol_004
149 * @tc.desc: Init
150 * @tc.type: FUNC
151 * @tc.require:
152 */
153 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_004, TestSize.Level1)
154 {
155 std::string str = SLASHES;
156 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(str);
157 EXPECT_EQ(result, false);
158 }
159
160 /*
161 * @tc.name: FilterInvaildSymbol_005
162 * @tc.desc: Init
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_005, TestSize.Level1)
167 {
168 std::string str = "abcdef";
169 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(str);
170 EXPECT_EQ(result, false);
171 }
172
173 /*
174 * @tc.name: FilterInvaildSymbol_006
175 * @tc.desc: Init
176 * @tc.type: FUNC
177 * @tc.require:
178 */
179 HWTEST_F(ProfileDataManagerTest, FilterInvaildSymbol_006, TestSize.Level1)
180 {
181 std::string str = "abc" + SEPARATOR + "xyz" + SLASHES + "123";
182 int32_t result = ProfileDataManager::GetInstance().FilterInvaildSymbol(str);
183 EXPECT_EQ(result, true);
184 }
185
186 /*
187 * @tc.name: PutDeviceProfileBatch_001
188 * @tc.desc: Init
189 * @tc.type: FUNC
190 * @tc.require:
191 */
192 HWTEST_F(ProfileDataManagerTest, PutDeviceProfileBatch_001, TestSize.Level1)
193 {
194 std::vector<DeviceProfile> deviceProfiles;
195 int32_t result = ProfileDataManager::GetInstance().PutDeviceProfileBatch(deviceProfiles);
196 EXPECT_EQ(result, DP_INVALID_PARAM);
197 }
198
199 /*
200 * @tc.name: PutDeviceProfileBatch_002
201 * @tc.desc: Init
202 * @tc.type: FUNC
203 * @tc.require:
204 */
205 HWTEST_F(ProfileDataManagerTest, PutDeviceProfileBatch_002, TestSize.Level1)
206 {
207 DeviceProfile deviceProfile;
208 std::vector<DeviceProfile> deviceProfiles = {deviceProfile};
209 int32_t result = ProfileDataManager::GetInstance().PutDeviceProfileBatch(deviceProfiles);
210 EXPECT_EQ(result, 98566144);
211 }
212
213 /*
214 * @tc.name: GetDeviceProfiles_001
215 * @tc.desc: Init
216 * @tc.type: FUNC
217 * @tc.require:
218 */
219 HWTEST_F(ProfileDataManagerTest, GetDeviceProfiles_001, TestSize.Level1)
220 {
221 DeviceProfileFilterOptions options;
222 std::vector<DeviceProfile> deviceProfiles;
223 int32_t result = ProfileDataManager::GetInstance().GetDeviceProfiles(options, deviceProfiles);
224 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
225 }
226
227 /*
228 * @tc.name: DeleteDeviceProfileBatch_001
229 * @tc.desc: Init
230 * @tc.type: FUNC
231 * @tc.require:
232 */
233 HWTEST_F(ProfileDataManagerTest, DeleteDeviceProfileBatch_001, TestSize.Level1)
234 {
235 std::vector<DeviceProfile> deviceProfiles;
236 int32_t result = ProfileDataManager::GetInstance().DeleteDeviceProfileBatch(deviceProfiles);
237 EXPECT_EQ(result, DP_INVALID_PARAM);
238 }
239
240 /*
241 * @tc.name: DeleteDeviceProfileBatch_002
242 * @tc.desc: Init
243 * @tc.type: FUNC
244 * @tc.require:
245 */
246 HWTEST_F(ProfileDataManagerTest, DeleteDeviceProfileBatch_002, TestSize.Level1)
247 {
248 DeviceProfile deviceProfile;
249 std::vector<DeviceProfile> deviceProfiles = {deviceProfile};
250 int32_t result = ProfileDataManager::GetInstance().DeleteDeviceProfileBatch(deviceProfiles);
251 EXPECT_NE(result, DP_SUCCESS);
252 }
253
254 /*
255 * @tc.name: GetDeviceIconInfos_001
256 * @tc.desc: Init
257 * @tc.type: FUNC
258 * @tc.require:
259 */
260 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_001, TestSize.Level1)
261 {
262 DeviceIconInfoFilterOptions filterOptions;
263 std::vector<DeviceIconInfo> deviceIconInfos;
264 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
265 EXPECT_EQ(result, DP_INVALID_PARAM);
266 }
267
268 /*
269 * @tc.name: GetDeviceIconInfos_002
270 * @tc.desc: Init
271 * @tc.type: FUNC
272 * @tc.require:
273 */
274 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_002, TestSize.Level1)
275 {
276 DeviceIconInfoFilterOptions filterOptions;
277 filterOptions.SetSubProductId("subId");
278 filterOptions.SetImageType("imageType");
279 filterOptions.SetSpecName("specName");
280 std::vector<DeviceIconInfo> deviceIconInfos;
281 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
282 EXPECT_EQ(result, DP_INVALID_PARAM);
283 }
284
285 /*
286 * @tc.name: GetDeviceIconInfos_003
287 * @tc.desc: Init
288 * @tc.type: FUNC
289 * @tc.require:
290 */
291 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_003, TestSize.Level1)
292 {
293 DeviceIconInfoFilterOptions filterOptions;
294 filterOptions.SetProductIds({"productId"});
295 filterOptions.SetImageType("imageType");
296 filterOptions.SetSpecName("specName");
297 std::vector<DeviceIconInfo> deviceIconInfos;
298 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
299 EXPECT_NE(result, DP_SUCCESS);
300 }
301
302 /*
303 * @tc.name: GetDeviceIconInfos_004
304 * @tc.desc: Init
305 * @tc.type: FUNC
306 * @tc.require:
307 */
308 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_004, TestSize.Level1)
309 {
310 DeviceIconInfoFilterOptions filterOptions;
311 filterOptions.SetProductIds({"productId"});
312 filterOptions.SetSubProductId("subId");
313 filterOptions.SetSpecName("specName");
314 std::vector<DeviceIconInfo> deviceIconInfos;
315 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
316 EXPECT_EQ(result, DP_INVALID_PARAM);
317 }
318
319 /*
320 * @tc.name: GetDeviceIconInfos_005
321 * @tc.desc: Init
322 * @tc.type: FUNC
323 * @tc.require:
324 */
325 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_005, TestSize.Level1)
326 {
327 DeviceIconInfoFilterOptions filterOptions;
328 filterOptions.SetProductIds({"productId"});
329 filterOptions.SetSubProductId("subId");
330 filterOptions.SetImageType("imageType");
331 std::vector<DeviceIconInfo> deviceIconInfos;
332 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
333 EXPECT_EQ(result, DP_INVALID_PARAM);
334 }
335
336 /*
337 * @tc.name: GetDeviceIconInfos_006
338 * @tc.desc: Init
339 * @tc.type: FUNC
340 * @tc.require:
341 */
342 HWTEST_F(ProfileDataManagerTest, GetDeviceIconInfos_006, TestSize.Level1)
343 {
344 DeviceIconInfoFilterOptions filterOptions;
345 filterOptions.SetProductIds({"productId"});
346 filterOptions.SetSubProductId("subId");
347 filterOptions.SetImageType("imageType");
348 filterOptions.SetSpecName("specName");
349 std::vector<DeviceIconInfo> deviceIconInfos;
350 int32_t result = ProfileDataManager::GetInstance().GetDeviceIconInfos(filterOptions, deviceIconInfos);
351 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
352 }
353
354 /*
355 * @tc.name: PutDeviceIconInfoBatch_001
356 * @tc.desc: PutDeviceIconInfoBatch
357 * @tc.type: FUNC
358 * @tc.require:
359 */
360 HWTEST_F(ProfileDataManagerTest, PutDeviceIconInfoBatch_001, TestSize.Level1)
361 {
362 std::vector<DeviceIconInfo> deviceIconInfos;
363 DeviceIconInfo deviceIconInfo;
364 deviceIconInfo.SetProductId("productId");
365 deviceIconInfo.SetSubProductId("subId");
366 deviceIconInfo.SetImageType("imageType");
367 deviceIconInfo.SetSpecName("specName");
368 deviceIconInfos.emplace_back(deviceIconInfo);
369 int32_t result = ProfileDataManager::GetInstance().PutDeviceIconInfoBatch(deviceIconInfos);
370 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
371 }
372
373 /*
374 * @tc.name: PutDeviceIconInfoBatch_002
375 * @tc.desc: PutDeviceIconInfoBatch
376 * @tc.type: FUNC
377 * @tc.require:
378 */
379 HWTEST_F(ProfileDataManagerTest, PutDeviceIconInfoBatch_002, TestSize.Level1)
380 {
381 std::vector<DeviceIconInfo> deviceIconInfos;
382 int32_t result = ProfileDataManager::GetInstance().PutDeviceIconInfoBatch(deviceIconInfos);
383 EXPECT_EQ(result, DP_INVALID_PARAM);
384 }
385
386 /*
387 * @tc.name: PutDeviceIconInfo_001
388 * @tc.desc: PutDeviceIconInfo
389 * @tc.type: FUNC
390 * @tc.require:
391 */
392 HWTEST_F(ProfileDataManagerTest, PutDeviceIconInfo_001, TestSize.Level1)
393 {
394 DeviceIconInfo deviceIconInfo;
395 int32_t result = ProfileDataManager::GetInstance().PutDeviceIconInfo(deviceIconInfo);
396 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
397 }
398
399 /*
400 * @tc.name: PutDeviceIconInfo_002
401 * @tc.desc: PutDeviceIconInfo
402 * @tc.type: FUNC
403 * @tc.require:
404 */
405 HWTEST_F(ProfileDataManagerTest, PutDeviceIconInfo_002, TestSize.Level1)
406 {
407 DeviceIconInfo deviceIconInfo;
408 deviceIconInfo.SetSubProductId("subId");
409 deviceIconInfo.SetImageType("imageType");
410 deviceIconInfo.SetSpecName("1111");
411 int32_t result = ProfileDataManager::GetInstance().PutDeviceIconInfo(deviceIconInfo);
412 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
413 }
414
415 /*
416 * @tc.name: PutProductInfoBatch_001
417 * @tc.desc: PutProductInfoBatch
418 * @tc.type: FUNC
419 * @tc.require:
420 */
421 HWTEST_F(ProfileDataManagerTest, PutProductInfoBatch_001, TestSize.Level1)
422 {
423 std::vector<ProductInfo> productInfos;
424 int32_t result = ProfileDataManager::GetInstance().PutProductInfoBatch(productInfos);
425 EXPECT_EQ(result, DP_INVALID_PARAM);
426 }
427
428 /*
429 * @tc.name: PutProductInfoBatch_002
430 * @tc.desc: PutProductInfoBatch
431 * @tc.type: FUNC
432 * @tc.require:
433 */
434 HWTEST_F(ProfileDataManagerTest, PutProductInfoBatch_002, TestSize.Level1)
435 {
436 std::vector<ProductInfo> productInfos;
437 ProductInfo productInfo;
438 productInfos.emplace_back(productInfo);
439 int32_t result = ProfileDataManager::GetInstance().PutProductInfoBatch(productInfos);
440 EXPECT_EQ(result, DP_INVALID_PARAM);
441 }
442
443 /*
444 * @tc.name: PutProductInfo_001
445 * @tc.desc: PutProductInfo
446 * @tc.type: FUNC
447 * @tc.require:
448 */
449 HWTEST_F(ProfileDataManagerTest, PutProductInfo_001, TestSize.Level1)
450 {
451 ProductInfo productInfo;
452 int32_t result = ProfileDataManager::GetInstance().PutProductInfo(productInfo);
453 EXPECT_EQ(result, DP_INVALID_PARAM);
454 }
455
456 /*
457 * @tc.name: PutProductInfo_002
458 * @tc.desc: PutProductInfo
459 * @tc.type: FUNC
460 * @tc.require:
461 */
462 HWTEST_F(ProfileDataManagerTest, PutProductInfo_002, TestSize.Level1)
463 {
464 ProductInfo productInfo;
465 productInfo.SetProductId("111");
466 int32_t result = ProfileDataManager::GetInstance().PutProductInfo(productInfo);
467 EXPECT_EQ(result, DP_GET_RESULTSET_FAIL);
468 }
469 } // namespace DistributedDeviceProfile
470 } // namespace OHOS