1 /*
2 * Copyright (c) 2024 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 <dlfcn.h>
18 #include <fstream>
19
20 #include "static_capability_loader.h"
21 #include "config_policy_utils.h"
22 #include "content_sensor_manager_utils.h"
23 #include "distributed_device_profile_constants.h"
24 #include "distributed_device_profile_enums.h"
25 #include "distributed_device_profile_errors.h"
26 #include "i_static_capability_collector.h"
27 #include "profile_utils.h"
28
29 namespace OHOS {
30 namespace DistributedDeviceProfile {
31 using namespace testing::ext;
32 using namespace std;
33 namespace {
34 const std::string TAG = "StaticCapabilityLoaderTest";
35 }
36
37 class StaticCapabilityLoaderTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp();
42 void TearDown();
43 };
44
SetUpTestCase()45 void StaticCapabilityLoaderTest::SetUpTestCase()
46 {
47 }
48
TearDownTestCase()49 void StaticCapabilityLoaderTest::TearDownTestCase()
50 {
51 }
52
SetUp()53 void StaticCapabilityLoaderTest::SetUp()
54 {
55 }
56
TearDown()57 void StaticCapabilityLoaderTest::TearDown()
58 {
59 }
60
61 /*
62 * @tc.name: Init_001
63 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
64 * @tc.type: FUNC
65 */
66 HWTEST_F(StaticCapabilityLoaderTest, Init_001, TestSize.Level1)
67 {
68 int32_t ret = OHOS::DistributedDeviceProfile::
69 StaticCapabilityLoader::GetInstance().Init();
70 EXPECT_EQ(ret, DP_SUCCESS);
71 }
72
73 #ifndef DEVICE_PROFILE_STATIC_DISABLE
74 /*
75 * @tc.name: LoadStaticCapability_001
76 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
77 * @tc.type: FUNC
78 */
79 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticCapability_001, TestSize.Level1)
80 {
81 std::string staticCapability = EMPTY_STRING;
82 int32_t ret = OHOS::DistributedDeviceProfile::
83 StaticCapabilityLoader::GetInstance().LoadStaticCapability(staticCapability);
84 EXPECT_EQ(ret, DP_SUCCESS);
85 }
86 #endif // DEVICE_PROFILE_STATIC_DISABLE
87
88 /*
89 * @tc.name: LoadJsonFile_001
90 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
91 * @tc.type: FUNC
92 */
93 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_001, TestSize.Level1)
94 {
95 std::string filePath = "";
96 std::string fileContent;
97 int32_t ret = OHOS::DistributedDeviceProfile::
98 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
99 EXPECT_EQ(ret, DP_INVALID_PARAM);
100 }
101
102 /*
103 * @tc.name: LoadJsonFile_002
104 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
105 * @tc.type: FUNC
106 */
107 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_002, TestSize.Level1)
108 {
109 std::string filePath(MAX_STRING_LEN + 1, 'a');
110 std::string fileContent;
111 int32_t ret = OHOS::DistributedDeviceProfile::
112 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
113 EXPECT_EQ(ret, DP_INVALID_PARAM);
114 }
115
116 /*
117 * @tc.name: LoadJsonFile_003
118 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
119 * @tc.type: FUNC
120 */
121 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_003, TestSize.Level1)
122 {
123 std::string filePath = "/invalid/path";
124 std::string fileContent;
125 int32_t ret = OHOS::DistributedDeviceProfile::
126 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
127 EXPECT_EQ(ret, DP_LOAD_JSON_FILE_FAIL);
128 }
129
130 /*
131 * @tc.name: LoadJsonFile_004
132 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
133 * @tc.type: FUNC
134 */
135 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_004, TestSize.Level1)
136 {
137 std::string filePath(PATH_MAX + 1, 'a');
138 std::string fileContent;
139 int32_t ret = OHOS::DistributedDeviceProfile::
140 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
141 EXPECT_EQ(ret, DP_INVALID_PARAM);
142 }
143
144 /*
145 * @tc.name: LoadJsonFile_005
146 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
147 * @tc.type: FUNC
148 */
149 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_005, TestSize.Level1)
150 {
151 std::string filePath(PATH_MAX + 1, 'a');
152 std::string fileContent;
153 int32_t ret = OHOS::DistributedDeviceProfile::
154 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
155 EXPECT_EQ(ret, DP_INVALID_PARAM);
156 }
157
158 /*
159 * @tc.name: LoadJsonFile_006
160 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
161 * @tc.type: FUNC
162 */
163 HWTEST_F(StaticCapabilityLoaderTest, LoadJsonFile_006, TestSize.Level1)
164 {
165 std::string filePath = "/system/lib64/libpasteboard_framework.z.so";
166 std::string fileContent;
167 int32_t ret = OHOS::DistributedDeviceProfile::
168 StaticCapabilityLoader::GetInstance().LoadJsonFile(filePath, fileContent);
169 EXPECT_EQ(ret, DP_LOAD_JSON_FILE_FAIL);
170 }
171
172 /*
173 * @tc.name: GetStaticCapability_001
174 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
175 * @tc.type: FUNC
176 */
177 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapability_001, TestSize.Level1)
178 {
179 cJSON *staticCapabilityJson = cJSON_CreateObject();
180 std::string staticCapability = EMPTY_STRING;
181 int32_t ret = OHOS::DistributedDeviceProfile::
182 StaticCapabilityLoader::GetInstance().GetStaticCapability(staticCapabilityJson, staticCapability);
183 EXPECT_EQ(ret, DP_PARSE_STATIC_CAP_FAIL);
184 cJSON_Delete(staticCapabilityJson);
185 }
186
187 /*
188 * @tc.name: GetStaticCapability_002
189 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
190 * @tc.type: FUNC
191 */
192 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapability_002, TestSize.Level1)
193 {
194 cJSON *staticCapabilityJson = cJSON_CreateObject();
195 cJSON_AddItemToObject(staticCapabilityJson, STATIC_CAPABILITY_ATTRIBUTE.c_str(), cJSON_CreateArray());
196 std::string staticCapability = EMPTY_STRING;
197 int32_t ret = OHOS::DistributedDeviceProfile::
198 StaticCapabilityLoader::GetInstance().GetStaticCapability(staticCapabilityJson, staticCapability);
199 EXPECT_EQ(ret, DP_PARSE_STATIC_CAP_FAIL);
200 cJSON_Delete(staticCapabilityJson);
201 }
202
203 /*
204 * @tc.name: GetStaticCapability_003
205 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
206 * @tc.type: FUNC
207 */
208 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapability_003, TestSize.Level1)
209 {
210 cJSON *staticCapabilityJson = cJSON_CreateObject();
211 cJSON *staticCapabilities = cJSON_CreateArray();
212 cJSON_AddItemToObject(staticCapabilityJson, STATIC_CAPABILITY_ATTRIBUTE.c_str(), staticCapabilities);
213 std::string staticCapability = EMPTY_STRING;
214 int32_t ret = OHOS::DistributedDeviceProfile::
215 StaticCapabilityLoader::GetInstance().GetStaticCapability(staticCapabilityJson, staticCapability);
216 EXPECT_EQ(ret, DP_PARSE_STATIC_CAP_FAIL);
217 cJSON_Delete(staticCapabilityJson);
218 }
219
220 /*
221 * @tc.name: GetStaticInfo_001
222 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
223 * @tc.type: FUNC
224 */
225 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfo_001, TestSize.Level1)
226 {
227 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
228 cJSON *staticInfoJson = cJSON_CreateObject();
229 std::string staticVersion = EMPTY_STRING;
230 std::string staticCapability = EMPTY_STRING;
231 int32_t ret = OHOS::DistributedDeviceProfile::
232 StaticCapabilityLoader::GetInstance().GetStaticInfo(staticInfoJson, staticCapability,
233 staticVersion, charProfiles);
234 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
235 cJSON_Delete(staticInfoJson);
236 }
237
238 /*
239 * @tc.name: GetStaticInfo_002
240 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
241 * @tc.type: FUNC
242 */
243 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfo_002, TestSize.Level1)
244 {
245 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
246 cJSON *staticInfoJson = cJSON_CreateObject();
247 cJSON_AddItemToObject(staticInfoJson, "test", cJSON_CreateString("test"));
248 std::string staticVersion = EMPTY_STRING;
249 std::string staticCapability = EMPTY_STRING;
250 int32_t ret = OHOS::DistributedDeviceProfile::
251 StaticCapabilityLoader::GetInstance().GetStaticInfo(staticInfoJson, staticCapability,
252 staticVersion, charProfiles);
253 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
254 cJSON_Delete(staticInfoJson);
255 }
256
257 /*
258 * @tc.name: GetStaticInfo_003
259 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
260 * @tc.type: FUNC
261 */
262 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfo_003, TestSize.Level1)
263 {
264 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
265 cJSON *staticInfoJson = cJSON_CreateObject();
266 cJSON_AddItemToObject(staticInfoJson, "test", cJSON_CreateString("test"));
267 cJSON_AddItemToObject(staticInfoJson, "test2", cJSON_CreateString("test2"));
268 std::string staticVersion = EMPTY_STRING;
269 std::string staticCapability = EMPTY_STRING;
270 int32_t ret = OHOS::DistributedDeviceProfile::
271 StaticCapabilityLoader::GetInstance().GetStaticInfo(staticInfoJson, staticCapability,
272 staticVersion, charProfiles);
273 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
274 cJSON_Delete(staticInfoJson);
275 }
276
277 /*
278 * @tc.name: GetStaticInfoByVersion_001
279 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
280 * @tc.type: FUNC
281 */
282 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoByVersion_001, TestSize.Level1)
283 {
284 std::string deviceId = "";
285 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
286 cJSON *staticInfoJson = cJSON_CreateObject();
287 std::string staticVersion = "1.0";
288 std::string staticCapability = EMPTY_STRING;
289 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
290 GetInstance().GetStaticInfoByVersion(deviceId, staticCapability,
291 staticInfoJson, staticVersion, charProfiles);
292 EXPECT_EQ(ret, DP_INVALID_PARAM);
293 cJSON_Delete(staticInfoJson);
294 }
295
296 /*
297 * @tc.name: GetStaticInfoByVersion_002
298 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
299 * @tc.type: FUNC
300 */
301 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoByVersion_002, TestSize.Level1)
302 {
303 std::string deviceId = "123456";
304 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
305 cJSON *staticInfoJson = nullptr;
306 std::string staticVersion = "1.0";
307 std::string staticCapability = EMPTY_STRING;
308 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
309 GetInstance().GetStaticInfoByVersion(deviceId, staticCapability,
310 staticInfoJson, staticVersion, charProfiles);
311 EXPECT_EQ(ret, DP_INVALID_PARAM);
312 }
313
314 /*
315 * @tc.name: GetStaticInfoByVersion_003
316 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
317 * @tc.type: FUNC
318 */
319 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoByVersion_003, TestSize.Level1)
320 {
321 std::string deviceId = "123456";
322 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
323 cJSON *staticInfoJson = cJSON_CreateObject();
324 std::string staticVersion = "";
325 std::string staticCapability = EMPTY_STRING;
326 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
327 GetInstance().GetStaticInfoByVersion(deviceId, staticCapability,
328 staticInfoJson, staticVersion, charProfiles);
329 EXPECT_EQ(ret, DP_INVALID_PARAM);
330 cJSON_Delete(staticInfoJson);
331 }
332
333 /*
334 * @tc.name: GetStaticInfoByVersion_004
335 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
336 * @tc.type: FUNC
337 */
338 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoByVersion_004, TestSize.Level1)
339 {
340 std::string deviceId = "123456";
341 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
342 cJSON *staticInfoJson = cJSON_CreateObject();
343 std::string staticVersion = "1.0";
344 std::string staticCapability = EMPTY_STRING;
345 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
346 GetInstance().GetStaticInfoByVersion(deviceId, staticCapability,
347 staticInfoJson, staticVersion, charProfiles);
348 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
349 cJSON_free(staticInfoJson);
350 }
351
352 /*
353 * @tc.name: GetLatestStaticInfoJson_001
354 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
355 * @tc.type: FUNC
356 */
357 HWTEST_F(StaticCapabilityLoaderTest, GetLatestStaticInfoJson_001, TestSize.Level1)
358 {
359 const cJSON *staticInfoJson = nullptr;
360 cJSON *ret = OHOS::DistributedDeviceProfile::
361 StaticCapabilityLoader::GetInstance().GetLatestStaticInfoJson(staticInfoJson);
362 EXPECT_EQ(ret, nullptr);
363 }
364
365 /*
366 * @tc.name: GetLatestStaticInfoJson_002
367 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
368 * @tc.type: FUNC
369 */
370 HWTEST_F(StaticCapabilityLoaderTest, GetLatestStaticInfoJson_002, TestSize.Level1)
371 {
372 cJSON *staticInfoJson = cJSON_CreateObject();
373 cJSON *ret = OHOS::DistributedDeviceProfile::
374 StaticCapabilityLoader::GetInstance().GetLatestStaticInfoJson(staticInfoJson);
375 EXPECT_EQ(ret, nullptr);
376 cJSON_Delete(staticInfoJson);
377 }
378
379 /*
380 * @tc.name: GetStaticInfoJsonByVersion_001
381 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
382 * @tc.type: FUNC
383 */
384 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoJsonByVersion_001, TestSize.Level1)
385 {
386 cJSON *staticInfoJson = cJSON_CreateObject();
387 std::string staticVersion = "1.0";
388 cJSON *ret = OHOS::DistributedDeviceProfile::
389 StaticCapabilityLoader::GetInstance().GetStaticInfoJsonByVersion(staticInfoJson, staticVersion);
390 EXPECT_EQ(ret, nullptr);
391 cJSON_Delete(staticInfoJson);
392 }
393
394 /*
395 * @tc.name: GetStaticInfoJsonByVersion_002
396 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
397 * @tc.type: FUNC
398 */
399 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoJsonByVersion_002, TestSize.Level1)
400 {
401 cJSON *staticInfoJson = cJSON_CreateObject();
402 std::string staticVersion = "";
403 cJSON *ret = OHOS::DistributedDeviceProfile::
404 StaticCapabilityLoader::GetInstance().GetStaticInfoJsonByVersion(staticInfoJson, staticVersion);
405 EXPECT_EQ(ret, nullptr);
406 cJSON_Delete(staticInfoJson);
407 }
408
409 /*
410 * @tc.name: GetStaticInfoJsonByVersion_003
411 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
412 * @tc.type: FUNC
413 */
414 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoJsonByVersion_003, TestSize.Level1)
415 {
416 cJSON *staticInfoJson = cJSON_CreateObject();
417 std::string staticVersion = "1.0";
418 cJSON_AddItemToObject(staticInfoJson, "StaticInfo", cJSON_CreateArray());
419 cJSON *ret = OHOS::DistributedDeviceProfile::
420 StaticCapabilityLoader::GetInstance().GetStaticInfoJsonByVersion(staticInfoJson, staticVersion);
421 EXPECT_EQ(ret, nullptr);
422 cJSON_Delete(staticInfoJson);
423 }
424
425 /*
426 * @tc.name: GetStaticInfoJsonByVersion_004
427 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
428 * @tc.type: FUNC
429 */
430 HWTEST_F(StaticCapabilityLoaderTest, GetStaticInfoJsonByVersion_004, TestSize.Level1)
431 {
432 cJSON *staticInfoJson = cJSON_CreateObject();
433 std::string staticVersion = "1.0";
434 cJSON *staticInfos = cJSON_CreateArray();
435 cJSON_AddItemToObject(staticInfoJson, "StaticInfo", staticInfos);
436 cJSON *ret = OHOS::DistributedDeviceProfile::
437 StaticCapabilityLoader::GetInstance().GetStaticInfoJsonByVersion(staticInfoJson, staticVersion);
438 EXPECT_EQ(ret, nullptr);
439 cJSON_Delete(staticInfoJson);
440 }
441
442 /*
443 * @tc.name: GetStaticVersion_001
444 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
445 * @tc.type: FUNC
446 */
447 HWTEST_F(StaticCapabilityLoaderTest, GetStaticVersion_001, TestSize.Level1)
448 {
449 cJSON *lastStaticJson = nullptr;
450 std::string staticVersion = EMPTY_STRING;
451 int32_t ret = OHOS::DistributedDeviceProfile::
452 StaticCapabilityLoader::GetInstance().GetStaticVersion(lastStaticJson, staticVersion);
453 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
454 }
455
456 /*
457 * @tc.name: GetStaticVersion_002
458 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
459 * @tc.type: FUNC
460 */
461 HWTEST_F(StaticCapabilityLoaderTest, GetStaticVersion_002, TestSize.Level1)
462 {
463 cJSON *lastStaticJson = cJSON_CreateObject();
464 cJSON *dpVersionJson = cJSON_CreateString("1.0");
465 cJSON_AddItemToObject(lastStaticJson, "dpVersion", dpVersionJson);
466 std::string staticVersion = EMPTY_STRING;
467 int32_t ret = OHOS::DistributedDeviceProfile::
468 StaticCapabilityLoader::GetInstance().GetStaticVersion(lastStaticJson, staticVersion);
469 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
470 cJSON_Delete(lastStaticJson);
471 }
472
473 /*
474 * @tc.name: GenerateStaticProfiles_001
475 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
476 * @tc.type: FUNC
477 */
478 HWTEST_F(StaticCapabilityLoaderTest, GenerateStaticProfiles_001, TestSize.Level1)
479 {
480 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
481 cJSON *staticInfoJson = cJSON_CreateObject();
482 std::string staticCapability = EMPTY_STRING;
483 int32_t ret = OHOS::DistributedDeviceProfile::
484 StaticCapabilityLoader::GetInstance().GenerateStaticProfiles("", staticCapability,
485 staticInfoJson, charProfiles);
486 EXPECT_EQ(ret, DP_INVALID_PARAM);
487 cJSON_Delete(staticInfoJson);
488 }
489
490 /*
491 * @tc.name: GenerateStaticProfiles_002
492 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
493 * @tc.type: FUNC
494 */
495 HWTEST_F(StaticCapabilityLoaderTest, GenerateStaticProfiles_002, TestSize.Level1)
496 {
497 std::string deviceId = "deviceId";
498 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
499 cJSON *staticInfoJson = cJSON_CreateObject();
500 std::string longDeviceId(MAX_STRING_LEN + 1, 'a');
501 std::string staticCapability = EMPTY_STRING;
502 int32_t ret = OHOS::DistributedDeviceProfile::
503 StaticCapabilityLoader::GetInstance().GenerateStaticProfiles(longDeviceId, staticCapability,
504 staticInfoJson, charProfiles);
505 EXPECT_EQ(ret, DP_INVALID_PARAM);
506 cJSON_Delete(staticInfoJson);
507 }
508
509 /*
510 * @tc.name: GenerateStaticProfiles_003
511 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
512 * @tc.type: FUNC
513 */
514 HWTEST_F(StaticCapabilityLoaderTest, GenerateStaticProfiles_003, TestSize.Level1)
515 {
516 std::string deviceId = "deviceId";
517 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
518 std::string staticCapability = EMPTY_STRING;
519 int32_t ret = OHOS::DistributedDeviceProfile::
520 StaticCapabilityLoader::GetInstance().GenerateStaticProfiles(deviceId, staticCapability,
521 nullptr, charProfiles);
522 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
523 }
524
525 /*
526 * @tc.name: GenerateStaticProfiles_004
527 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
528 * @tc.type: FUNC
529 */
530 HWTEST_F(StaticCapabilityLoaderTest, GenerateStaticProfiles_004, TestSize.Level1)
531 {
532 std::string deviceId = "deviceId";
533 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
534 cJSON *staticInfoJson = cJSON_CreateObject();
535 std::string staticCapability = EMPTY_STRING;
536 cJSON_AddItemToObject(staticInfoJson, ABILITY_KEY.c_str(), cJSON_CreateString("not an array"));
537 int32_t ret = OHOS::DistributedDeviceProfile::
538 StaticCapabilityLoader::GetInstance().GenerateStaticProfiles(deviceId, staticCapability,
539 staticInfoJson, charProfiles);
540 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
541 cJSON_Delete(staticInfoJson);
542 }
543
544 /*
545 * @tc.name: LoadStaticInfo_001
546 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
547 * @tc.type: FUNC
548 */
549 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticInfo_001, TestSize.Level1)
550 {
551 std::string staticCapability = EMPTY_STRING;
552 std::string staticVersion = "";
553 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
554 int32_t ret = OHOS::DistributedDeviceProfile::
555 StaticCapabilityLoader::GetInstance().LoadStaticInfo(staticCapability, staticVersion, charProfiles);
556 EXPECT_EQ(ret, DP_INVALID_PARAM);
557 }
558
559 /*
560 * @tc.name: LoadStaticInfo_002
561 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
562 * @tc.type: FUNC
563 */
564 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticInfo_002, TestSize.Level1)
565 {
566 std::string staticCapability(MAX_STRING_LEN + 1, 'a');
567 std::string staticVersion = "";
568 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
569 int32_t ret = OHOS::DistributedDeviceProfile::
570 StaticCapabilityLoader::GetInstance().LoadStaticInfo(staticCapability, staticVersion, charProfiles);
571 EXPECT_EQ(ret, DP_INVALID_PARAM);
572 }
573
574 #ifndef DEVICE_PROFILE_STATIC_DISABLE
575 /*
576 * @tc.name: LoadStaticInfo_003
577 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
578 * @tc.type: FUNC
579 */
580 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticInfo_003, TestSize.Level1)
581 {
582 std::string staticCapability = "11";
583 std::string staticVersion = "";
584 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
585 int32_t ret = OHOS::DistributedDeviceProfile::
586 StaticCapabilityLoader::GetInstance().LoadStaticInfo(staticCapability, staticVersion, charProfiles);
587 EXPECT_EQ(ret, DP_SUCCESS);
588 }
589
590 /*
591 * @tc.name: LoadStaticInfo_004
592 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
593 * @tc.type: FUNC
594 */
595 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticInfo_004, TestSize.Level1)
596 {
597 std::string staticCapability = "11";
598 std::string staticVersion = "";
599 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
600 int32_t ret = OHOS::DistributedDeviceProfile::
601 StaticCapabilityLoader::GetInstance().LoadStaticInfo(staticCapability, staticVersion, charProfiles);
602 EXPECT_EQ(ret, DP_SUCCESS);
603 }
604 #endif // DEVICE_PROFILE_STATIC_DISABLE
605
606 /*
607 * @tc.name: LoadStaticProfiles_001
608 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
609 * @tc.type: FUNC
610 */
611 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticProfiles_001, TestSize.Level1)
612 {
613 std::string deviceId = "";
614 std::string staticCapability = "staticCapability";
615 std::string staticVersion = "staticVersion";
616 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
617 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
618 GetInstance().LoadStaticProfiles(deviceId, staticCapability, staticVersion, charProfiles);
619 EXPECT_EQ(ret, DP_INVALID_PARAM);
620 }
621
622 /*
623 * @tc.name: LoadStaticProfiles_002
624 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
625 * @tc.type: FUNC
626 */
627 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticProfiles_002, TestSize.Level1)
628 {
629 std::string deviceId = "deviceId";
630 std::string staticCapability = EMPTY_STRING;
631 std::string staticVersion = "staticVersion";
632 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
633 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
634 GetInstance().LoadStaticProfiles(deviceId, staticCapability, staticVersion, charProfiles);
635 EXPECT_EQ(ret, DP_INVALID_PARAM);
636 }
637
638 /*
639 * @tc.name: LoadStaticProfiles_003
640 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
641 * @tc.type: FUNC
642 */
643 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticProfiles_003, TestSize.Level1)
644 {
645 std::string deviceId = "deviceId";
646 std::string staticCapability = "staticCapability";
647 std::string staticVersion = "";
648 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
649 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
650 GetInstance().LoadStaticProfiles(deviceId, staticCapability, staticVersion, charProfiles);
651 EXPECT_EQ(ret, DP_INVALID_PARAM);
652 }
653
654 #ifndef DEVICE_PROFILE_STATIC_DISABLE
655 /*
656 * @tc.name: LoadStaticProfiles_004
657 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
658 * @tc.type: FUNC
659 */
660 HWTEST_F(StaticCapabilityLoaderTest, LoadStaticProfiles_004, TestSize.Level1)
661 {
662 std::string deviceId = "deviceId";
663 std::string staticCapability = "staticCapability";
664 std::string staticVersion = "staticVersion";
665 std::unordered_map<std::string, CharacteristicProfile> charProfiles;
666 int32_t ret = OHOS::DistributedDeviceProfile::StaticCapabilityLoader::
667 GetInstance().LoadStaticProfiles(deviceId, staticCapability, staticVersion, charProfiles);
668 EXPECT_EQ(ret, DP_GET_STATIC_INFO_FAIL);
669 }
670 #endif // DEVICE_PROFILE_STATIC_DISABLE
671
672 /*
673 * @tc.name: InitStaticCapability_001
674 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
675 * @tc.type: FUNC
676 */
677 HWTEST_F(StaticCapabilityLoaderTest, InitStaticCapability_001, TestSize.Level1)
678 {
679 int32_t size = 2;
680 std::string staticCapability = EMPTY_STRING;
681 OHOS::DistributedDeviceProfile::
682 StaticCapabilityLoader::GetInstance().InitStaticCapability(size, staticCapability);
683 EXPECT_EQ(staticCapability, "00");
684 }
685
686 /*
687 * @tc.name: SetStaticCapability_001
688 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
689 * @tc.type: FUNC
690 */
691 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapability_001, TestSize.Level1)
692 {
693 const cJSON *staticCapabilityItems = cJSON_CreateString("NotJsonArray");
694 std::string staticCapability = EMPTY_STRING;
695 OHOS::DistributedDeviceProfile::
696 StaticCapabilityLoader::GetInstance().SetStaticCapability(staticCapabilityItems, staticCapability);
697 EXPECT_EQ(staticCapability, "");
698 }
699
700 /*
701 * @tc.name: SetStaticCapability_002
702 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
703 * @tc.type: FUNC
704 */
705 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapability_002, TestSize.Level1)
706 {
707 cJSON *staticCapabilityItems = cJSON_CreateArray();
708 cJSON *item = cJSON_CreateString("NotObject");
709 std::string staticCapability = EMPTY_STRING;
710 cJSON_AddItemToArray(staticCapabilityItems, item);
711 OHOS::DistributedDeviceProfile::
712 StaticCapabilityLoader::GetInstance().SetStaticCapability(staticCapabilityItems, staticCapability);
713 EXPECT_EQ(staticCapability, "");
714 cJSON_Delete(staticCapabilityItems);
715 }
716
717 /*
718 * @tc.name: SetStaticCapabilityFlag_001
719 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
720 * @tc.type: FUNC
721 */
722 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapabilityFlag_001, TestSize.Level1)
723 {
724 std::string handlerName = "";
725 std::string handlerLoc = "loc";
726 std::string staticCapability = EMPTY_STRING;
727 OHOS::DistributedDeviceProfile::
728 StaticCapabilityLoader::GetInstance().SetStaticCapabilityFlag(handlerName, handlerLoc, staticCapability);
729 EXPECT_EQ(staticCapability, "");
730 }
731
732 /*
733 * @tc.name: SetStaticCapabilityFlag_002
734 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
735 * @tc.type: FUNC
736 */
737 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapabilityFlag_002, TestSize.Level1)
738 {
739 std::string handlerName(MAX_STRING_LEN + 1, 'a');
740 std::string handlerLoc = "loc";
741 std::string staticCapability = EMPTY_STRING;
742 OHOS::DistributedDeviceProfile::
743 StaticCapabilityLoader::GetInstance().SetStaticCapabilityFlag(handlerName, handlerLoc, staticCapability);
744 EXPECT_EQ(staticCapability, "");
745 }
746
747 /*
748 * @tc.name: SetStaticCapabilityFlag_003
749 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
750 * @tc.type: FUNC
751 */
752 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapabilityFlag_003, TestSize.Level1)
753 {
754 std::string handlerName = "name";
755 std::string handlerLoc = "";
756 std::string staticCapability = EMPTY_STRING;
757 OHOS::DistributedDeviceProfile::
758 StaticCapabilityLoader::GetInstance().SetStaticCapabilityFlag(handlerName, handlerLoc, staticCapability);
759 EXPECT_EQ(staticCapability, "");
760 }
761
762 /*
763 * @tc.name: SetStaticCapabilityFlag_004
764 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
765 * @tc.type: FUNC
766 */
767 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapabilityFlag_004, TestSize.Level1)
768 {
769 std::string handlerName = "name";
770 std::string handlerLoc(MAX_STRING_LEN + 1, 'a');
771 std::string staticCapability = EMPTY_STRING;
772 OHOS::DistributedDeviceProfile::
773 StaticCapabilityLoader::GetInstance().SetStaticCapabilityFlag(handlerName, handlerLoc, staticCapability);
774 EXPECT_EQ(staticCapability, "");
775 }
776
777 /*
778 * @tc.name: SetStaticCapabilityFlag_005
779 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
780 * @tc.type: FUNC
781 */
782 HWTEST_F(StaticCapabilityLoaderTest, SetStaticCapabilityFlag_005, TestSize.Level1)
783 {
784 std::string handlerName = "name";
785 std::string handlerLoc = "handlerLoc";
786 std::string staticCapability = EMPTY_STRING;
787 OHOS::DistributedDeviceProfile::
788 StaticCapabilityLoader::GetInstance().SetStaticCapabilityFlag(handlerName, handlerLoc, staticCapability);
789 EXPECT_EQ(staticCapability, "");
790 }
791
792 /*
793 * @tc.name: GetStaticCapabilityValue_001
794 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
795 * @tc.type: FUNC
796 */
797 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapabilityValue_001, TestSize.Level1)
798 {
799 std::string handlerLoc = "libpasteboard_adapter.z.so";
800 bool ret = OHOS::DistributedDeviceProfile::
801 StaticCapabilityLoader::GetInstance().GetStaticCapabilityValue(handlerLoc);
802 EXPECT_EQ(ret, true);
803 }
804
805 /*
806 * @tc.name: GetStaticCapabilityValue_002
807 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
808 * @tc.type: FUNC
809 */
810 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapabilityValue_002, TestSize.Level1)
811 {
812 std::string handlerLoc = "libdistributed_sdk.z.so";
813 bool ret = OHOS::DistributedDeviceProfile::
814 StaticCapabilityLoader::GetInstance().GetStaticCapabilityValue(handlerLoc);
815 EXPECT_EQ(ret, true);
816 }
817
818 /*
819 * @tc.name: GetStaticCapabilityValue_003
820 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
821 * @tc.type: FUNC
822 */
823 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapabilityValue_003, TestSize.Level1)
824 {
825 std::string handlerLoc = "aaa.z.so";
826 bool ret = OHOS::DistributedDeviceProfile::
827 StaticCapabilityLoader::GetInstance().GetStaticCapabilityValue(handlerLoc);
828 EXPECT_EQ(ret, false);
829 }
830
831 /*
832 * @tc.name: GetStaticCapabilityValue_004
833 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
834 * @tc.type: FUNC
835 */
836 HWTEST_F(StaticCapabilityLoaderTest, GetStaticCapabilityValue_004, TestSize.Level1)
837 {
838 std::string handlerLoc = "libsoftbus_adapter.z.so";
839 bool ret = OHOS::DistributedDeviceProfile::
840 StaticCapabilityLoader::GetInstance().GetStaticCapabilityValue(handlerLoc);
841 EXPECT_EQ(ret, false);
842 }
843
844 /*
845 * @tc.name: UnInit_001
846 * @tc.desc: Normal testCase of StaticCapabilityLoaderTest
847 * @tc.type: FUNC
848 */
849 HWTEST_F(StaticCapabilityLoaderTest, UnInit_001, TestSize.Level1)
850 {
851 int32_t ret = OHOS::DistributedDeviceProfile::
852 StaticCapabilityLoader::GetInstance().UnInit();
853 EXPECT_EQ(ret, DP_SUCCESS);
854 }
855 } // namespace DistributedDeviceProfile
856 } // namespace OHOS
857