• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <memory>
17 #include <sys/types.h>
18 
19 #include "gtest/gtest.h"
20 
21 #include "base/json/json_util.h"
22 #include "base/utils/utils.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS::Ace {
28 namespace {
29 const std::string TEST_STRING = "Ace Unittest";
30 const std::string TEST_KEY = "JsonObjectTypeTest";
31 const std::string TEST_FALSE_KEY = "FalseKey";
32 } // namespace
33 
34 class JsonUtilTest : public testing::Test {};
35 
36 /**
37  * @tc.name: JsonUtilTest001
38  * @tc.desc: Check json util function for bool type value
39  * @tc.type: FUNC
40  */
41 HWTEST_F(JsonUtilTest, JsonUtilTest001, TestSize.Level1)
42 {
43     /**
44      * @tc.steps: step1. construct the test string with bool value.
45      */
46     std::string testJson = "true";
47 
48     /**
49      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsBool and GetBool.
50      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
51      */
52     std::unique_ptr<JsonValue> boolValue = JsonUtil::ParseJsonString(testJson);
53     ASSERT_TRUE(boolValue);
54     EXPECT_TRUE(boolValue->IsValid());
55     EXPECT_FALSE(boolValue->IsNull());
56     EXPECT_TRUE(boolValue->IsBool());
57     EXPECT_TRUE(boolValue->GetBool());
58 }
59 
60 /**
61  * @tc.name: JsonUtilTest002
62  * @tc.desc: Check json util function for bool type value
63  * @tc.type: FUNC
64  */
65 HWTEST_F(JsonUtilTest, JsonUtilTest002, TestSize.Level1)
66 {
67     /**
68      * @tc.steps: step1. construct the test string with bool value.
69      */
70     std::string testJson = "false";
71 
72     /**
73      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsBool and GetBool.
74      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
75      */
76     std::unique_ptr<JsonValue> boolValue = JsonUtil::ParseJsonString(testJson);
77     ASSERT_TRUE(boolValue);
78     EXPECT_TRUE(boolValue->IsValid());
79     EXPECT_FALSE(boolValue->IsNull());
80     EXPECT_TRUE(boolValue->IsBool());
81     EXPECT_FALSE(boolValue->GetBool());
82 }
83 
84 /**
85  * @tc.name: JsonUtilTest003
86  * @tc.desc: Check json util function for signed integer
87  * @tc.type: FUNC
88  */
89 HWTEST_F(JsonUtilTest, JsonUtilTest003, TestSize.Level1)
90 {
91     /**
92      * @tc.steps: step1. construct the test string with signed integer.
93      */
94     std::string testJson = "-1";
95     int32_t intNum = -1;
96     double doubleNum = -1;
97 
98     /**
99      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsNumber, GetInt, GetUInt and GetDouble.
100      * @@tc.expected: step2. get the JsonValue unsuccessfully and the results are 0
101      */
102     std::unique_ptr<JsonValue> intValue = JsonUtil::ParseJsonString(testJson);
103     ASSERT_TRUE(intValue);
104     EXPECT_TRUE(intValue->IsValid());
105     EXPECT_FALSE(intValue->IsNull());
106     EXPECT_TRUE(intValue->IsNumber());
107     EXPECT_TRUE(intValue->GetInt() == intNum);
108     EXPECT_FALSE(intValue->GetUInt() == -1);
109     EXPECT_TRUE(NearEqual(intValue->GetDouble(), doubleNum));
110 }
111 
112 /**
113  * @tc.name: JsonUtilTest004
114  * @tc.desc: Check json util function for unsigned integer
115  * @tc.type: FUNC
116  */
117 HWTEST_F(JsonUtilTest, JsonUtilTest004, TestSize.Level1)
118 {
119     /**
120      * @tc.steps: step1. construct the test string with unsigned integer.
121      */
122     std::string testJson = "1";
123     int32_t intNum = 1;
124     uint32_t uintNum = 1;
125     double doubleNum = 1;
126 
127     /**
128      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsNumber, GetInt, GetUInt and GetDouble.
129      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
130      */
131     std::unique_ptr<JsonValue> uintValue = JsonUtil::ParseJsonString(testJson);
132     ASSERT_TRUE(uintValue);
133     EXPECT_TRUE(uintValue->IsValid());
134     EXPECT_FALSE(uintValue->IsNull());
135     EXPECT_TRUE(uintValue->IsNumber());
136     EXPECT_TRUE(uintValue->GetInt() == intNum);
137     EXPECT_TRUE(uintValue->GetUInt() == uintNum);
138     EXPECT_TRUE(NearEqual(uintValue->GetDouble(), doubleNum));
139 }
140 
141 /**
142  * @tc.name: JsonUtilTest005
143  * @tc.desc: Check json util function for decimal number
144  * @tc.type: FUNC
145  */
146 HWTEST_F(JsonUtilTest, JsonUtilTest005, TestSize.Level1)
147 {
148     /**
149      * @tc.steps: step1. construct the test string with decimal number.
150      */
151     std::string testJson = "6.66";
152     int32_t intNum = 6;
153     uint32_t uintNum = 6;
154     double doubleNum = 6.66;
155 
156     /**
157      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsNumber, GetInt, GetUInt and GetDouble.
158      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
159      */
160     std::unique_ptr<JsonValue> doubleValue = JsonUtil::ParseJsonString(testJson);
161     ASSERT_TRUE(doubleValue);
162     EXPECT_TRUE(doubleValue->IsValid());
163     EXPECT_FALSE(doubleValue->IsNull());
164     EXPECT_TRUE(doubleValue->IsNumber());
165     EXPECT_TRUE(doubleValue->GetInt() == intNum);
166     EXPECT_TRUE(doubleValue->GetUInt() == uintNum);
167     EXPECT_TRUE(NearEqual(doubleValue->GetDouble(), doubleNum));
168 }
169 
170 /**
171  * @tc.name: JsonUtilTest006
172  * @tc.desc: Check json util function for string
173  * @tc.type: FUNC
174  */
175 HWTEST_F(JsonUtilTest, JsonUtilTest006, TestSize.Level1)
176 {
177     /**
178      * @tc.steps: step1. construct the test string with string.
179      */
180     std::string testJson = "\"Ace Unittest\"";
181 
182     /**
183      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsString and GetString.
184      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
185      */
186     std::unique_ptr<JsonValue> stringValue = JsonUtil::ParseJsonString(testJson);
187     ASSERT_TRUE(stringValue);
188     EXPECT_TRUE(stringValue->IsValid());
189     EXPECT_FALSE(stringValue->IsNull());
190     EXPECT_TRUE(stringValue->IsString());
191     EXPECT_TRUE(stringValue->GetString() == TEST_STRING);
192 }
193 
194 /**
195  * @tc.name: JsonUtilTest007
196  * @tc.desc: Check json util function for empty string
197  * @tc.type: FUNC
198  */
199 HWTEST_F(JsonUtilTest, JsonUtilTest007, TestSize.Level1)
200 {
201     /**
202      * @tc.steps: step1. construct the test string with empty string.
203      */
204     std::string testJson = "\"\"";
205 
206     /**
207      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsString and GetString.
208      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
209      */
210     std::unique_ptr<JsonValue> emptyStringValue = JsonUtil::ParseJsonString(testJson);
211     ASSERT_TRUE(emptyStringValue);
212     EXPECT_TRUE(emptyStringValue->IsValid());
213     EXPECT_FALSE(emptyStringValue->IsNull());
214     EXPECT_TRUE(emptyStringValue->IsString());
215     EXPECT_TRUE(emptyStringValue->GetString().empty());
216 }
217 
218 /**
219  * @tc.name: JsonUtilTest008
220  * @tc.desc: Check json util function for JsonObject
221  * @tc.type: FUNC
222  */
223 HWTEST_F(JsonUtilTest, JsonUtilTest008, TestSize.Level1)
224 {
225     /**
226      * @tc.steps: step1. construct the test string with JsonObject.
227      */
228     std::string testJson = R"({"JsonObjectTypeTest": "Ace Unittest"})";
229 
230     /**
231      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsObject, Contains and GetValue.
232      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
233      */
234     std::unique_ptr<JsonValue> objectValue = JsonUtil::ParseJsonString(testJson);
235     ASSERT_TRUE(objectValue);
236     EXPECT_TRUE(objectValue->IsValid());
237     EXPECT_FALSE(objectValue->IsNull());
238     EXPECT_TRUE(objectValue->IsObject());
239     EXPECT_TRUE(objectValue->Contains(TEST_KEY));
240     EXPECT_FALSE(objectValue->Contains(TEST_FALSE_KEY));
241     EXPECT_TRUE(objectValue->GetValue(TEST_KEY)->GetString() == TEST_STRING);
242     EXPECT_TRUE(objectValue->GetValue(TEST_FALSE_KEY)->GetString().empty());
243 }
244 
245 /**
246  * @tc.name: JsonUtilTest009
247  * @tc.desc: Check json util function for incorrect JsonObject
248  * @tc.type: FUNC
249  */
250 HWTEST_F(JsonUtilTest, JsonUtilTest009, TestSize.Level1)
251 {
252     /**
253      * @tc.steps: step1. construct the test string with incorrect JsonObject.
254      */
255     std::string testJson = R"({"JsonObjectTypeTest": ""})";
256 
257     /**
258      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsObject, Contains and GetValue.
259      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
260      */
261     std::unique_ptr<JsonValue> objectValue = JsonUtil::ParseJsonString(testJson);
262     ASSERT_TRUE(objectValue);
263     EXPECT_TRUE(objectValue->IsValid());
264     EXPECT_FALSE(objectValue->IsNull());
265     EXPECT_TRUE(objectValue->IsObject());
266     EXPECT_TRUE(objectValue->Contains(TEST_KEY));
267     EXPECT_TRUE(objectValue->GetValue(TEST_KEY)->GetString().empty());
268 }
269 
270 /**
271  * @tc.name: JsonUtilTest010
272  * @tc.desc: Check json util function for array
273  * @tc.type: FUNC
274  */
275 HWTEST_F(JsonUtilTest, JsonUtilTest010, TestSize.Level1)
276 {
277     /**
278      * @tc.steps: step1. construct the test string with array.
279      */
280     std::string testJson = "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]";
281     int32_t testArraySize = 10;
282     int32_t testArrayIndex = 5;
283     int32_t testArrayValue = 5;
284 
285     /**
286      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsArray, GetArraySize and GetArrayItem.
287      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
288      */
289     std::unique_ptr<JsonValue> arrayValue = JsonUtil::ParseJsonString(testJson);
290     ASSERT_TRUE(arrayValue);
291     EXPECT_TRUE(arrayValue->IsValid());
292     EXPECT_FALSE(arrayValue->IsNull());
293     EXPECT_TRUE(arrayValue->IsArray());
294     EXPECT_TRUE(arrayValue->GetArraySize() == testArraySize);
295     EXPECT_TRUE(arrayValue->GetArrayItem(testArrayIndex)->GetInt() == testArrayValue);
296 }
297 
298 /**
299  * @tc.name: JsonUtilTest011
300  * @tc.desc: Check json util function for empty array
301  * @tc.type: FUNC
302  */
303 HWTEST_F(JsonUtilTest, JsonUtilTest011, TestSize.Level1)
304 {
305     /**
306      * @tc.steps: step1. construct the test string with empty array.
307      */
308     std::string testJson = "[]";
309 
310     /**
311      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull, IsArray, GetArraySize and GetArrayItem.
312      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
313      */
314     std::unique_ptr<JsonValue> arrayValue = JsonUtil::ParseJsonString(testJson);
315     ASSERT_TRUE(arrayValue);
316     EXPECT_TRUE(arrayValue->IsValid());
317     EXPECT_FALSE(arrayValue->IsNull());
318     EXPECT_TRUE(arrayValue->IsArray());
319     EXPECT_TRUE(arrayValue->GetArraySize() == 0);
320 }
321 
322 /**
323  * @tc.name: JsonUtilTest012
324  * @tc.desc: Check json util function for empty test string
325  * @tc.type: FUNC
326  */
327 HWTEST_F(JsonUtilTest, JsonUtilTest012, TestSize.Level1)
328 {
329     /**
330      * @tc.steps: step1. construct the empty test string.
331      */
332     std::string testJson;
333 
334     /**
335      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull.
336      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
337      */
338     std::unique_ptr<JsonValue> emptyValue = JsonUtil::ParseJsonString(testJson);
339     ASSERT_TRUE(emptyValue);
340     EXPECT_FALSE(emptyValue->IsValid());
341     EXPECT_TRUE(emptyValue->IsNull());
342 }
343 
344 /**
345  * @tc.name: JsonUtilTest013
346  * @tc.desc: Check json util function for illegal type value
347  * @tc.type: FUNC
348  */
349 HWTEST_F(JsonUtilTest, JsonUtilTest013, TestSize.Level1)
350 {
351     /**
352      * @tc.steps: step1. construct the test string with illegal type value.
353      */
354     std::string testJson = "{Ace Unittest}";
355 
356     /**
357      * @tc.steps: step2. get JsonValue and check results of IsValid, IsNull.
358      * @tc.expected: step2. get the JsonValue successfully and the results are correct.
359      */
360     std::unique_ptr<JsonValue> illegalValue = JsonUtil::ParseJsonString(testJson);
361     ASSERT_TRUE(illegalValue);
362     EXPECT_FALSE(illegalValue->IsValid());
363     EXPECT_TRUE(illegalValue->IsNull());
364 }
365 
366 /**
367  * @tc.name: JsonUtilTest014
368  * @tc.desc: Check json util function Put(const char* key, const char* value) for nullptr key or value
369  * @tc.type: FUNC
370  */
371 HWTEST_F(JsonUtilTest, JsonUtilTest014, TestSize.Level1)
372 {
373     /**
374      * @tc.steps: step1. construct the nullptr key.
375      */
376     const char* key = nullptr;
377     const char* value = nullptr;
378     JsonValue jsonValue;
379     /**
380      * @tc.steps: step2. get results
381      * @tc.expected: step2.  the results are correct.
382      */
383     bool ret = jsonValue.Put(key, value);
384     EXPECT_FALSE(ret);
385 
386     /**
387      * @tc.steps: step3. construct the nullptr value.
388      */
389     char c = '5';
390     const char* key2 = &c;
391     const char* value2 = nullptr;
392     /**
393      * @tc.steps: step4. get results
394      * @tc.expected: step4.  the results are correct.
395      */
396     bool ret2 = jsonValue.Put(key2, value2);
397     EXPECT_FALSE(ret2);
398 
399     /**
400      * @tc.steps: step5. construct value not null
401      */
402     char c2 = 'v';
403     const char* value3 = &c2;
404     bool ret3 = jsonValue.Put(key2, value3);
405     EXPECT_TRUE(ret3);
406     bool ret4 = jsonValue.Put(key, value3);
407     EXPECT_FALSE(ret4);
408 }
409 
410 /**
411  * @tc.name: JsonUtilTest015
412  * @tc.desc: Check json util function Put(const char* key, bool value) for nullptr key
413  * @tc.type: FUNC
414  */
415 HWTEST_F(JsonUtilTest, JsonUtilTest015, TestSize.Level1)
416 {
417     /**
418      * @tc.steps: step1. construct the nullptr key.
419      */
420     const char* key = nullptr;
421     bool value = true;
422     JsonValue jsonValue;
423     /**
424      * @tc.steps: step2. get  results
425      * @tc.expected: step2.  the results are correct.
426      */
427     bool ret = jsonValue.Put(key, value);
428     EXPECT_FALSE(ret);
429 }
430 
431 /**
432  * @tc.name: JsonUtilTest016
433  * @tc.desc: Check json util function Put(const char* key, const std::unique_ptr<JsonValue>& value)
434  * for nullptr key or nullptr value
435  * @tc.type: FUNC
436  */
437 HWTEST_F(JsonUtilTest, JsonUtilTest016, TestSize.Level1)
438 {
439     /**
440      * @tc.steps: step1. construct the nullptr key.
441      */
442     const char* key = nullptr;
443     const std::unique_ptr<JsonValue>& value = nullptr;
444     JsonValue jsonValue;
445     /**
446      * @tc.steps: step2. get  results
447      * @tc.expected: step2.  the results are correct.
448      */
449     bool ret = jsonValue.Put(key, value);
450     EXPECT_FALSE(ret);
451 
452     /**
453      * @tc.steps: step1. construct the nullptr value.
454      */
455     char c = '5';
456     const char* key2 = &c;
457     const std::unique_ptr<JsonValue>& value2 = nullptr;
458     /**
459      * @tc.steps: step2. get  results
460      * @tc.expected: step2.  the results are correct.
461      */
462     bool ret2 = jsonValue.Put(key2, value2);
463     EXPECT_FALSE(ret2);
464 
465     /**
466      * @tc.steps: step3. construct the value not null
467      */
468     char valueStr = '5';
469     const char* valueTemp = &valueStr;
470     bool ret3 = jsonValue.Put(key2, valueTemp);
471     EXPECT_TRUE(ret3);
472     bool ret4 = jsonValue.Put(key, valueTemp);
473     EXPECT_FALSE(ret4);
474 }
475 
476 /**
477  * @tc.name: JsonUtilTest017
478  * @tc.desc: Check json util function Put(const char* key, size_t value) for nullptr key
479  * @tc.type: FUNC
480  */
481 HWTEST_F(JsonUtilTest, JsonUtilTest017, TestSize.Level1)
482 {
483     /**
484      * @tc.steps: step1. construct the nullptr key.
485      */
486     const char* key = nullptr;
487     size_t value = 8;
488     JsonValue jsonValue;
489     /**
490      * @tc.steps: step2. get  results
491      * @tc.expected: step2.  the results are correct.
492      */
493     bool ret = jsonValue.Put(key, value);
494     EXPECT_FALSE(ret);
495 
496     /**
497      * @tc.steps: step1. construct the nullptr value.
498      */
499     char c = '5';
500     const char* key2 = &c;
501     /**
502      * @tc.steps: step2. get  results
503      * @tc.expected: step2.  the results are correct.
504      */
505     bool ret2 = jsonValue.Put(key2, value);
506     EXPECT_TRUE(ret2);
507 }
508 
509 /**
510  * @tc.name: JsonUtilTest018
511  * @tc.desc: Check json util function Put(const char* key, int32_t value) for nullptr key
512  * @tc.type: FUNC
513  */
514 HWTEST_F(JsonUtilTest, JsonUtilTest018, TestSize.Level1)
515 {
516     /**
517      * @tc.steps: step1. construct the nullptr key.
518      */
519     const char* key = nullptr;
520     int32_t value = 8;
521     JsonValue jsonValue;
522     /**
523      * @tc.steps: step2. get  results
524      * @tc.expected: step2.  the results are correct.
525      */
526     bool ret = jsonValue.Put(key, value);
527     EXPECT_FALSE(ret);
528 }
529 
530 /**
531  * @tc.name: JsonUtilTest019
532  * @tc.desc: Check json util function Put(const char* key, double value) for nullptr key
533  * @tc.type: FUNC
534  */
535 HWTEST_F(JsonUtilTest, JsonUtilTest019, TestSize.Level1)
536 {
537     /**
538      * @tc.steps: step1. construct the nullptr key.
539      */
540     const char* key = nullptr;
541     double value = 8;
542     JsonValue jsonValue;
543     /**
544      * @tc.steps: step2. get  results
545      * @tc.expected: step2.  the results are correct.
546      */
547     bool ret = jsonValue.Put(key, value);
548     EXPECT_FALSE(ret);
549 }
550 
551 /**
552  * @tc.name: JsonUtilTest020
553  * @tc.desc: Check json util function Replace(const char* key, double value) for nullptr key
554  * @tc.type: FUNC
555  */
556 HWTEST_F(JsonUtilTest, JsonUtilTest020, TestSize.Level1)
557 {
558     /**
559      * @tc.steps: step1. construct the nullptr key.
560      */
561     const char* key = nullptr;
562     double value = 8.0;
563     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
564 
565     /**
566      * @tc.steps: step2. get  results
567      * @tc.expected: step2.  the results are correct.
568      */
569     bool ret = jsonValue->Replace(key, value);
570     EXPECT_FALSE(ret);
571 
572     /**
573      * @tc.steps: step3. construct key(not exist) and value
574      * @tc.expected: step3. true
575      */
576     key = "aaa";
577     bool ret3 = jsonValue->Replace(key, value);
578     EXPECT_FALSE(ret3);
579 
580     /**
581      * @tc.steps: step4. construct key(exist) and value
582      * @tc.expected: step3. true
583      */
584     double valueTmp = 8.0;
585     key = "aaa";
586     bool putRet = jsonValue->Put(key, valueTmp);
587     EXPECT_TRUE(putRet);
588     bool ret4 = jsonValue->Replace(key, value);
589     EXPECT_TRUE(ret4);
590 }
591 
592 /**
593  * @tc.name: JsonUtilTest021
594  * @tc.desc: Check json util function Replace(const char* key, bool value) for nullptr key
595  * @tc.type: FUNC
596  */
597 HWTEST_F(JsonUtilTest, JsonUtilTest021, TestSize.Level1)
598 {
599     /**
600      * @tc.steps: step1. construct the nullptr key.
601      */
602     const char* key = nullptr;
603     bool value = true;
604     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
605     /**
606      * @tc.steps: step2. get  results
607      * @tc.expected: step2.  the results are correct.
608      */
609     bool ret = jsonValue->Replace(key, value);
610     EXPECT_FALSE(ret);
611 
612     /**
613      * @tc.steps: step3. construct key(not exist) and value
614      * @tc.expected: step3. true
615      */
616     key = "aaa";
617     bool ret3 = jsonValue->Replace(key, value);
618     EXPECT_FALSE(ret3);
619 
620     /**
621      * @tc.steps: step4. construct key(exist) and value
622      * @tc.expected: step3. true
623      */
624     jsonValue->Put(key, false);
625     bool ret4 = jsonValue->Replace(key, value);
626     EXPECT_TRUE(ret4);
627 }
628 
629 /**
630  * @tc.name: JsonUtilTest022
631  * @tc.desc: Check json util function Replace(const char* key, const char* value) for nullptr key
632  * @tc.type: FUNC
633  */
634 HWTEST_F(JsonUtilTest, JsonUtilTest022, TestSize.Level1)
635 {
636     /**
637      * @tc.steps: step1. construct the nullptr key.
638      */
639     const char* key = nullptr;
640     const char* value = nullptr;
641     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
642     /**
643      * @tc.steps: step2. get  results
644      * @tc.expected: step2.  the results are correct.
645      */
646     bool ret = jsonValue->Replace(key, value);
647     EXPECT_FALSE(ret);
648 
649     /**
650      * @tc.steps: step3. construct the nullptr value.
651      */
652     char c = '5';
653     const char* value2 = &c;
654     const char* key2 = nullptr;
655     /**
656      * @tc.steps: step4. get  results
657      * @tc.expected: step4.  the results are correct.
658      */
659     bool ret2 = jsonValue->Replace(key2, value2);
660     EXPECT_FALSE(ret2);
661 
662     /**
663      * @tc.steps: step5. repalce key(not exist) and value
664      * @tc.expected: step5. repalce fail
665      */
666     const char* key3 = "aaa";
667     bool ret3 = jsonValue->Replace(key3, value2);
668     EXPECT_FALSE(ret3);
669     bool putRet = jsonValue->Put(key3, value2);
670     EXPECT_TRUE(putRet);
671     bool ret4 = jsonValue->Replace(key3, value2);
672     EXPECT_TRUE(ret4);
673 }
674 
675 /**
676  * @tc.name: JsonUtilTest023
677  * @tc.desc: Check json util function Replace(const char* key, int32_t value) for nullptr key
678  * @tc.type: FUNC
679  */
680 HWTEST_F(JsonUtilTest, JsonUtilTest023, TestSize.Level1)
681 {
682     /**
683      * @tc.steps: step1. construct the nullptr key.
684      */
685     const char* key = nullptr;
686     int32_t value = 5;
687     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
688     /**
689      * @tc.steps: step2. get  results
690      * @tc.expected: step2.  the results are correct.
691      */
692     bool ret = jsonValue->Replace(key, value);
693     EXPECT_FALSE(ret);
694 
695     /**
696      * @tc.steps: step3. repalce key(not exist) and value
697      * @tc.expected: step3. repalce fail
698      */
699     const char* key3 = "aaa";
700     bool ret3 = jsonValue->Replace(key3, value);
701     EXPECT_FALSE(ret3);
702     bool putRet = jsonValue->Put(key3, value);
703     EXPECT_TRUE(putRet);
704     std::string objStr = jsonValue->ToString();
705     EXPECT_TRUE(objStr.find("\"aaa\":5") != std::string::npos);
706     bool ret4 = jsonValue->Replace(key3, value);
707     EXPECT_TRUE(ret4);
708 }
709 
710 /**
711  * @tc.name: JsonUtilTest024
712  * @tc.desc: Check json util Replace(const char* key, const std::unique_ptr<JsonValue>& value) for nullptr key
713  * @tc.type: FUNC
714  */
715 HWTEST_F(JsonUtilTest, JsonUtilTest024, TestSize.Level1)
716 {
717     /**
718      * @tc.steps: step1. construct the nullptr key.
719      */
720     const char* key = nullptr;
721     const std::unique_ptr<JsonValue>& value = nullptr;
722     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
723     /**
724      * @tc.steps: step2. get  results
725      * @tc.expected: step2.  the results are correct.
726      */
727     bool ret = jsonValue->Replace(key, value);
728     EXPECT_FALSE(ret);
729     std::unique_ptr<JsonValue> valueTmp = JsonUtil::Create(false);
730     bool ret2 = jsonValue->Replace(key, valueTmp);
731     EXPECT_FALSE(ret2);
732 
733     /**
734      * @tc.steps: step3. construct key(not exist) and value
735      * @tc.expected: step3. true
736      */
737     key = "aaa";
738     bool ret3 = jsonValue->Replace(key, valueTmp);
739     EXPECT_FALSE(ret3);
740 
741     /**
742      * @tc.steps: step4. construct key(exist) and value
743      * @tc.expected: step3. true
744      */
745     jsonValue->Put(key, valueTmp);
746     bool ret4 = jsonValue->Replace(key, valueTmp);
747     EXPECT_TRUE(ret4);
748 }
749 
750 /**
751  * @tc.name: JsonUtilTest025
752  * @tc.desc: Check json util bool Delete(const char* key) for nullptr key
753  * @tc.type: FUNC
754  */
755 HWTEST_F(JsonUtilTest, JsonUtilTest025, TestSize.Level1)
756 {
757     /**
758      * @tc.steps: step1. construct the nullptr key.
759      */
760     const char* key = nullptr;
761     JsonValue jsonValue;
762     /**
763      * @tc.steps: step2. get  results
764      * @tc.expected: step2.  the results are correct.
765      */
766     bool ret = jsonValue.Delete(key);
767     EXPECT_FALSE(ret);
768 }
769 
770 /**
771  * @tc.name: JsonUtilTest026
772  * @tc.desc: Check json util int64_t GetInt64()
773  * @tc.type: FUNC
774  */
775 HWTEST_F(JsonUtilTest, JsonUtilTest026, TestSize.Level1)
776 {
777     /**
778      * @tc.steps: step1. construct the nullptr object_.
779      */
780     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
781     /**
782      * @tc.steps: step2. get  results
783      * @tc.expected: step2.  the results are correct.
784      */
785     int64_t ret = jsonValue->GetInt64();
786     ASSERT_EQ(ret, 0);
787 
788     /**
789      * @tc.steps: step3. get key(not exist)
790      * @tc.expected: step3. reture defalut value 0
791      */
792     const std::string key = "key-aaa";
793     int64_t ret3 = jsonValue->GetInt64(key, 0);
794     ASSERT_EQ(ret3, 0);
795 
796     /**
797      * @tc.steps: step4. get key(exist) but value not a number
798      * @tc.expected: step4. reture defalut value 0
799      */
800     const char* keyPut = "key-aaa";
801     const char* value = "value-bbb";
802     jsonValue->Put(keyPut, value);
803     int64_t ret4 = jsonValue->GetInt64(key, 0);
804     ASSERT_EQ(ret4, 0);
805 
806     /**
807      * @tc.steps: step5. get key(exist) and value is a number
808      * @tc.expected: step5. reture value
809      */
810     keyPut = "key-number";
811     jsonValue->Put(keyPut, 100);
812     int64_t ret5 = jsonValue->GetInt64(keyPut, 0);
813     ASSERT_EQ(ret5, 100);
814 }
815 
816 /**
817  * @tc.name: JsonUtilTest027
818  * @tc.desc: Check json util std::unique_ptr<JsonValue> GetNext() for nullptr object_
819  * @tc.type: FUNC
820  */
821 HWTEST_F(JsonUtilTest, JsonUtilTest027, TestSize.Level1)
822 {
823     /**
824      * @tc.steps: step1. construct the nullptr object_.
825      */
826     JsonValue jsonValue(nullptr);
827     /**
828      * @tc.steps: step2. get  results
829      * @tc.expected: step2.  the results are correct.
830      */
831     std::unique_ptr<JsonValue> ret = jsonValue.GetNext();
832     EXPECT_TRUE(ret->IsNull());
833 }
834 
835 /**
836  * @tc.name: JsonUtilTest028
837  * @tc.desc: Check json util std::unique_ptr<JsonValue> GetChild() for nullptr object_
838  * @tc.type: FUNC
839  */
840 HWTEST_F(JsonUtilTest, JsonUtilTest028, TestSize.Level1)
841 {
842     /**
843      * @tc.steps: step1. construct the nullptr object_.
844      */
845     JsonValue jsonValue(nullptr);
846     /**
847      * @tc.steps: step2. get  results
848      * @tc.expected: step2.  the results are correct.
849      */
850     std::unique_ptr<JsonValue> ret = jsonValue.GetChild();
851     EXPECT_TRUE(ret->IsNull());
852 }
853 
854 /**
855  * @tc.name: JsonUtilTest029
856  * @tc.desc: Check json util bool Replace(const char* key, double value) for nullptr key
857  * @tc.type: FUNC
858  */
859 HWTEST_F(JsonUtilTest, JsonUtilTest029, TestSize.Level1)
860 {
861     /**
862      * @tc.steps: step1. construct the nullptr key.
863      */
864     const char* key = nullptr;
865     double value = 5;
866     JsonValue jsonValue;
867     /**
868      * @tc.steps: step2. get  results
869      * @tc.expected: step2.  the results are correct.
870      */
871     bool ret = jsonValue.Replace(key, value);
872     EXPECT_FALSE(ret);
873 }
874 
875 /**
876  * @tc.name: JsonUtilTest030
877  * @tc.desc: Check json util bool Replace(const char* key, bool value) for nullptr key
878  * @tc.type: FUNC
879  */
880 HWTEST_F(JsonUtilTest, JsonUtilTest030, TestSize.Level1)
881 {
882     /**
883      * @tc.steps: step1. construct the nullptr key.
884      */
885     const char* key = nullptr;
886     bool value = true;
887     JsonValue jsonValue;
888     /**
889      * @tc.steps: step2. get  results
890      * @tc.expected: step2.  the results are correct.
891      */
892     bool ret = jsonValue.Replace(key, value);
893     EXPECT_FALSE(ret);
894 }
895 
896 /**
897  * @tc.name: JsonUtilTest031
898  * @tc.desc: Check json util bool Replace(const char* key, const char* value) for nullptr key or nullptr value
899  * @tc.type: FUNC
900  */
901 HWTEST_F(JsonUtilTest, JsonUtilTest031, TestSize.Level1)
902 {
903     /**
904      * @tc.steps: step1. construct the nullptr value.
905      */
906     const char* key = nullptr;
907     const char* value = nullptr;
908     JsonValue jsonValue;
909     /**
910      * @tc.steps: step2. get  results
911      * @tc.expected: step2.  the results are correct.
912      */
913     bool ret = jsonValue.Replace(key, value);
914     EXPECT_FALSE(ret);
915 
916     /**
917      * @tc.steps: step3. construct the nullptr key.
918      */
919     const char* key2 = nullptr;
920     char c = '5';
921     const char* value2 = &c;
922     /**
923      * @tc.steps: step4. get  results
924      * @tc.expected: step4.  the results are correct.
925      */
926     bool ret2 = jsonValue.Replace(key2, value2);
927     EXPECT_FALSE(ret2);
928 }
929 
930 /**
931  * @tc.name: JsonUtilTest032
932  * @tc.desc: Check json util bool Replace(const char* key, int32_t value) for nullptr key
933  * @tc.type: FUNC
934  */
935 HWTEST_F(JsonUtilTest, JsonUtilTest032, TestSize.Level1)
936 {
937     /**
938      * @tc.steps: step1. construct the nullptr key.
939      */
940     const char* key = nullptr;
941     int32_t value = 5;
942     JsonValue jsonValue;
943     /**
944      * @tc.steps: step2. get  results
945      * @tc.expected: step2.  the results are correct.
946      */
947     bool ret = jsonValue.Replace(key, value);
948     EXPECT_FALSE(ret);
949 }
950 
951 /**
952  * @tc.name: JsonUtilTest033
953  * @tc.desc: Check json util func bool PutFixedAttr  with const char* value
954  * @tc.type: FUNC
955  */
956 HWTEST_F(JsonUtilTest, JsonUtilTest033, TestSize.Level1)
957 {
958     /**
959      * @tc.steps: step1. construct the filter object, add filter attr, construct the jsonValue object.
960      */
961     NG::InspectorFilter filter;
962     JsonValue jsonValue;
963     const std::string attr = "color";
964     filter.AddFilterAttr(attr);
965     /**
966      * @tc.steps: step2. get  results
967      * @tc.expected: step2.  the results are correct.
968      */
969     bool ret = jsonValue.PutFixedAttr("editable", "EditMode.None", filter, NG::FIXED_ATTR_EDITABLE);
970     EXPECT_FALSE(ret);
971 }
972 
973 /**
974  * @tc.name: JsonUtilTest034
975  * @tc.desc: Check json util bool PutExtAttr
976  * @tc.type: FUNC
977  */
978 HWTEST_F(JsonUtilTest, JsonUtilTest034, TestSize.Level1)
979 {
980     /**
981      * @tc.steps: step1. construct the filter object, add filter attr, construct the jsonValue object.
982      */
983     NG::InspectorFilter filter;
984     JsonValue jsonValue;
985     const std::string attr = "color";
986     filter.AddFilterAttr(attr);
987     /**
988      * @tc.steps: step2. get  results
989      * @tc.expected: step2.  the results are correct.
990      */
991     bool ret = jsonValue.PutExtAttr("editable", "EditMode.None", filter);
992     EXPECT_FALSE(ret);
993 }
994 
995 /**
996  * @tc.name: JsonUtilTest035
997  * @tc.desc: Check json util func bool PutFixedAttr with const std::unique_ptr<JsonValue>& value
998  * @tc.type: FUNC
999  */
1000 HWTEST_F(JsonUtilTest, JsonUtilTest035, TestSize.Level1)
1001 {
1002     /**
1003      * @tc.steps: step1. construct the filter object, add filter attr, construct the empty jsonValue object
1004      */
1005     NG::InspectorFilter filter;
1006     JsonValue jsonValue;
1007     JsonValue jsonValueTemp;
1008     const std::unique_ptr<JsonValue> value = std::make_unique<JsonValue>(jsonValueTemp);
1009     /**
1010      * @tc.steps: step2. get  results
1011      * @tc.expected: step2.  the results are correct.
1012      */
1013     bool ret = jsonValue.PutFixedAttr("editable", value, filter, NG::FIXED_ATTR_EDITABLE);
1014     EXPECT_FALSE(ret);
1015 
1016     /**
1017      * @tc.steps: step3. set the value to jsonValueTemp, construct the jsonValue object.
1018      * @tc.expected: step3.  the results are correct.
1019      */
1020     std::string testJson = "true";
1021     std::unique_ptr<JsonValue> boolValue = JsonUtil::ParseJsonString(testJson);
1022     bool ret2 = jsonValue.PutFixedAttr("editable", boolValue, filter, NG::FIXED_ATTR_EDITABLE);
1023     EXPECT_TRUE(ret2);
1024 
1025     /**
1026      * @tc.steps: step4. construct the filter object, add filter attr, construct the jsonValue object.
1027      */
1028     const std::string attr = "color";
1029     filter.AddFilterAttr(attr);
1030     /**
1031      * @tc.steps: step5. get  results
1032      * @tc.expected: step5.  the results are correct.
1033      */
1034     bool ret3 = jsonValue.PutFixedAttr("editable", value, filter, NG::FIXED_ATTR_EDITABLE);
1035     EXPECT_FALSE(ret3);
1036 }
1037 
1038 /**
1039  * @tc.name: JsonUtilTest036
1040  * @tc.desc: Check json util func bool PutExtAttr with size_t value/int32_t value/double value/bool value/int64_t
1041  * @tc.type: FUNC
1042  */
1043 HWTEST_F(JsonUtilTest, JsonUtilTest036, TestSize.Level1)
1044 {
1045     /**
1046      * @tc.steps: step1. construct the filter object, add filter attr, construct the jsonValue object.
1047      */
1048     NG::InspectorFilter filter;
1049     JsonValue jsonValue;
1050     size_t value = 5;
1051     int32_t value2 = 5;
1052     double value3 = 5.0;
1053     int64_t value4 = 5;
1054     bool value5 = true;
1055     bool ret = jsonValue.PutExtAttr("editable", value, filter);
1056     bool ret2 = jsonValue.PutExtAttr("editable", value2, filter);
1057     bool ret3 = jsonValue.PutExtAttr("editable", value3, filter);
1058     bool ret4 = jsonValue.PutExtAttr("editable", value4, filter);
1059     bool ret5 = jsonValue.PutExtAttr("editable", value5, filter);
1060     EXPECT_TRUE(ret);
1061     EXPECT_TRUE(ret2);
1062     EXPECT_TRUE(ret3);
1063     EXPECT_TRUE(ret4);
1064     EXPECT_TRUE(ret5);
1065     /**
1066      * @tc.steps: step2. make filterExt not empty
1067      */
1068     const std::string attr = "color";
1069     filter.AddFilterAttr(attr);
1070     /**
1071      * @tc.steps: step2. get  results
1072      * @tc.expected: step2.  the results are correct.
1073      */
1074     bool ret6 = jsonValue.PutExtAttr("editable", value, filter);
1075     bool ret7 = jsonValue.PutExtAttr("editable", value2, filter);
1076     bool ret8 = jsonValue.PutExtAttr("editable", value3, filter);
1077     bool ret9 = jsonValue.PutExtAttr("editable", value4, filter);
1078     bool ret10 = jsonValue.PutExtAttr("editable", value5, filter);
1079     EXPECT_FALSE(ret6);
1080     EXPECT_FALSE(ret7);
1081     EXPECT_FALSE(ret8);
1082     EXPECT_FALSE(ret9);
1083     EXPECT_FALSE(ret10);
1084 }
1085 
1086 /**
1087  * @tc.name: JsonUtilTest037
1088  * @tc.desc: Check json util func bool PutFixedAttr with size_t value/int32_t value/double value/bool value/int64_t
1089  * value
1090  * @tc.type: FUNC
1091  */
1092 HWTEST_F(JsonUtilTest, JsonUtilTest037, TestSize.Level1)
1093 {
1094     /**
1095      * @tc.steps: step1. construct the filter object, add filter attr, construct the empty jsonValue object
1096      */
1097     NG::InspectorFilter filter;
1098     JsonValue jsonValue;
1099     size_t value = 5;
1100     int32_t value2 = 5;
1101     double value3 = 5.0;
1102     int64_t value4 = 5;
1103     bool value5 = true;
1104     /**
1105      * @tc.steps: step2. get  results
1106      * @tc.expected: step2.  the results are correct.
1107      */
1108     bool ret = jsonValue.PutFixedAttr("editable", value, filter, NG::FIXED_ATTR_EDITABLE);
1109     bool ret2 = jsonValue.PutFixedAttr("editable", value2, filter, NG::FIXED_ATTR_EDITABLE);
1110     bool ret3 = jsonValue.PutFixedAttr("editable", value3, filter, NG::FIXED_ATTR_EDITABLE);
1111     bool ret4 = jsonValue.PutFixedAttr("editable", value4, filter, NG::FIXED_ATTR_EDITABLE);
1112     bool ret5 = jsonValue.PutFixedAttr("editable", value5, filter, NG::FIXED_ATTR_EDITABLE);
1113     EXPECT_TRUE(ret);
1114     EXPECT_TRUE(ret2);
1115     EXPECT_TRUE(ret3);
1116     EXPECT_TRUE(ret4);
1117     EXPECT_TRUE(ret5);
1118 
1119     /**
1120      * @tc.steps: step3. construct the filter object, add filter attr
1121      */
1122     const std::string attr = "color";
1123     filter.AddFilterAttr(attr);
1124     /**
1125      * @tc.steps: step4. get  results
1126      * @tc.expected: step4.  the results are correct.
1127      */
1128     bool ret6 = jsonValue.PutFixedAttr("editable", value, filter, NG::FIXED_ATTR_EDITABLE);
1129     bool ret7 = jsonValue.PutFixedAttr("editable", value2, filter, NG::FIXED_ATTR_EDITABLE);
1130     bool ret8 = jsonValue.PutFixedAttr("editable", value3, filter, NG::FIXED_ATTR_EDITABLE);
1131     bool ret9 = jsonValue.PutFixedAttr("editable", value4, filter, NG::FIXED_ATTR_EDITABLE);
1132     bool ret10 = jsonValue.PutFixedAttr("editable", value5, filter, NG::FIXED_ATTR_EDITABLE);
1133     EXPECT_FALSE(ret6);
1134     EXPECT_FALSE(ret7);
1135     EXPECT_FALSE(ret8);
1136     EXPECT_FALSE(ret9);
1137     EXPECT_FALSE(ret10);
1138 }
1139 
1140 /**
1141  * @tc.name: JsonUtilTest038
1142  * @tc.desc: Check json util func bool PutExtAttr with const std::unique_ptr<JsonValue>& value
1143  * @tc.type: FUNC
1144  */
1145 HWTEST_F(JsonUtilTest, JsonUtilTest038, TestSize.Level1)
1146 {
1147     /**
1148      * @tc.steps: step1. construct the filter object, add filter attr, construct the empty jsonValue object
1149      */
1150     NG::InspectorFilter filter;
1151     JsonValue jsonValue;
1152     JsonValue jsonValueTemp;
1153     const std::unique_ptr<JsonValue> value = std::make_unique<JsonValue>(jsonValueTemp);
1154     /**
1155      * @tc.steps: step2. get  results
1156      * @tc.expected: step2.  the results are correct.
1157      */
1158     bool ret = jsonValue.PutExtAttr("editable", value, filter);
1159     EXPECT_FALSE(ret);
1160 
1161     /**
1162      * @tc.steps: step3. set the value to jsonValueTemp, construct the jsonValue object.
1163      * @tc.expected: step3.  the results are correct.
1164      */
1165     std::string testJson = "true";
1166     std::unique_ptr<JsonValue> boolValue = JsonUtil::ParseJsonString(testJson);
1167     bool ret2 = jsonValue.PutExtAttr("editable", boolValue, filter);
1168     EXPECT_TRUE(ret2);
1169 
1170     /**
1171      * @tc.steps: step4. construct the filter object, add filter attr, construct the jsonValue object.
1172      */
1173     const std::string attr = "color";
1174     filter.AddFilterAttr(attr);
1175     /**
1176      * @tc.steps: step5. get  results
1177      * @tc.expected: step5.  the results are correct.
1178      */
1179     bool ret3 = jsonValue.PutExtAttr("editable", value, filter);
1180     EXPECT_FALSE(ret3);
1181 }
1182 
1183 /**
1184  * @tc.name: JsonUtilTest039
1185  * @tc.desc: Check json util bool bool PutRef(const char* key, std::unique_ptr<JsonValue>&& value)
1186  * @tc.type: FUNC
1187  */
1188 HWTEST_F(JsonUtilTest, JsonUtilTest039, TestSize.Level1)
1189 {
1190     /**
1191      * @tc.steps: step1. construct the nullptr key
1192      */
1193     JsonValue jsonValue;
1194     const char* key = nullptr;
1195     std::unique_ptr<JsonValue> value = std::make_unique<JsonValue>();
1196     /**
1197      * @tc.steps: step2. get  results
1198      * @tc.expected: step2.  the results are correct.
1199      */
1200     bool ret = jsonValue.PutRef(key, std::move(value));
1201     EXPECT_FALSE(ret);
1202 
1203     /**
1204      * @tc.steps: step3. construct the nullptr value
1205      */
1206     char a = 'a';
1207     const char* key2 = &a;
1208     std::unique_ptr<JsonValue> value2;
1209     /**
1210      * @tc.steps: step4. get  results
1211      * @tc.expected: step4.  the results are correct.
1212      */
1213     bool ret2 = jsonValue.PutRef(key2, std::move(value2));
1214     bool ret3 = jsonValue.PutRef(std::move(value2));
1215     EXPECT_FALSE(ret2);
1216     EXPECT_FALSE(ret3);
1217 }
1218 
1219 /**
1220  * @tc.name: JsonUtilTest040
1221  * @tc.desc: Check json util int64_t GetUInt/GetInt/GetString
1222  * @tc.type: FUNC
1223  */
1224 HWTEST_F(JsonUtilTest, JsonUtilTest040, TestSize.Level1)
1225 {
1226     /**
1227      * @tc.steps: step1. construct jsonValue
1228      */
1229     std::unique_ptr<JsonValue> jsonValue = JsonUtil::Create(false);
1230 
1231     /**
1232      * @tc.steps: step2. get key(not exist)
1233      * @tc.expected: step2. reture defalut value 0
1234      */
1235     const std::string key = "key-aaa";
1236     int64_t ret3 = jsonValue->GetUInt(key, 0);
1237     ASSERT_EQ(ret3, 0);
1238 
1239     /**
1240      * @tc.steps: step3. get key(exist) but value not a number
1241      * @tc.expected: step3. reture defalut value 0
1242      */
1243     const char* keyPut = "key-aaa";
1244     const char* value = "value-bbb";
1245     jsonValue->Put(keyPut, value);
1246     int64_t ret4 = jsonValue->GetUInt(key, 0);
1247     int64_t ret42 = jsonValue->GetInt(key, 0);
1248     ASSERT_EQ(ret4, 0);
1249     ASSERT_EQ(ret42, 0);
1250 
1251     /**
1252      * @tc.steps: step5. get key(exist) and value is a number
1253      * @tc.expected: step5. reture value
1254      */
1255     keyPut = "key-number";
1256     jsonValue->Put(keyPut, 100);
1257     int64_t ret5 = jsonValue->GetUInt(keyPut, 0);
1258     ASSERT_EQ(ret5, 100);
1259     std::string ret52 = jsonValue->GetString(keyPut, "default");
1260     ASSERT_EQ(ret52, "default");
1261 }
1262 
1263 /**
1264  * @tc.name: JsonUtilTest041
1265  * @tc.desc: Check json util Put(const std::unique_ptr<JsonValue>& value)/ReleaseJsonObject
1266  * @tc.type: FUNC
1267  */
1268 HWTEST_F(JsonUtilTest, JsonUtilTest041, TestSize.Level1)
1269 {
1270     std::unique_ptr<JsonValue> value = nullptr;
1271     JsonValue jsonValue;
1272     ASSERT_FALSE(jsonValue.Put(value));
1273 
1274     // ReleaseJsonObject() isRoot_ false
1275     JsonObject* ret = jsonValue.ReleaseJsonObject();
1276     ASSERT_TRUE(ret == nullptr);
1277     // PutRef() isRoot_ true
1278     char keyChar = 'k';
1279     char* keyPtr = &keyChar;
1280     std::unique_ptr<JsonValue> value2 = JsonUtil::Create(true);
1281     bool ret2 = jsonValue.PutRef(keyPtr, std::move(value2));
1282     ASSERT_TRUE(ret2);
1283     bool ret3 = jsonValue.PutRef(std::move(value2));
1284     ASSERT_TRUE(ret3);
1285 }
1286 } // namespace OHOS::Ace
1287