1 /*
2 * Copyright (c) 2020-2021 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 <securec.h>
17 #include "hctest.h"
18 #include "ohos_types.h"
19 #include "parameter.h"
20 #include "parameter_utils.h"
21 #include "sysparam_errno.h"
22
23 #define MAX_LEN 128
24 #define INVALID_LEN 2
25 #define COMMON_ERROR (-1)
26 #define INVALID_PARAMETER (-9)
27
28 static const char* g_defSysParam = "data of sys param ***...";
29
30 /**
31 * @tc.desc : register a test suite, this suite is used to test basic flow
32 * and interface dependency
33 * @param : subsystem name is utils
34 * @param : module name is parameter
35 * @param : test suit name is ParameterFuncTestSuite
36 */
37 LITE_TEST_SUIT(utils, parameter, ParameterFuncTestSuite);
38
39 /**
40 * @tc.setup : setup for all testcases
41 * @return : setup result, TRUE is success, FALSE is fail
42 */
ParameterFuncTestSuiteSetUp(void)43 static BOOL ParameterFuncTestSuiteSetUp(void)
44 {
45 return TRUE;
46 }
47
48 /**
49 * @tc.teardown : teardown for all testcases
50 * @return : teardown result, TRUE is success, FALSE is fail
51 */
ParameterFuncTestSuiteTearDown(void)52 static BOOL ParameterFuncTestSuiteTearDown(void)
53 {
54 printf("+-------------------------------------------+\n");
55 return TRUE;
56 }
57
58 /**
59 * @tc.number : SUB_UTILS_PARAMETER_2500
60 * @tc.name : SetParameter parameter legal test
61 * @tc.desc : [C- SOFTWARE -0200]
62 */
63 LITE_TEST_CASE(ParameterFuncTestSuite,
64 testSetParameter001,
65 Function | MediumTest | Level1) {
66 int ret;
67
68 char key[] = "rw.sys.version_606";
69 char value[] = "OEM-10.1.0";
70 ret = SetParameter(key, value);
71 TEST_ASSERT_EQUAL_INT(0, ret);
72 };
73
74 /**
75 * @tc.number : SUB_UTILS_PARAMETER_2600
76 * @tc.name : SetParameter parameter legal test with Special characters
77 * @tc.desc : [C- SOFTWARE -0200]
78 */
79 LITE_TEST_CASE(ParameterFuncTestSuite,
80 testSetParameter002,
81 Function | MediumTest | Level1) {
82 int ret;
83
84 char key[] = "_._..__...___";
85 char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890";
86 ret = SetParameter(key, value);
87 TEST_ASSERT_EQUAL_INT(-9, ret);
88 };
89
90 /**
91 * @tc.number : SUB_UTILS_PARAMETER_2700
92 * @tc.name : SetParameter parameter legal test using key with only
93 * lowercase
94 * @tc.desc : [C- SOFTWARE -0200]
95 */
96 LITE_TEST_CASE(ParameterFuncTestSuite,
97 testSetParameter003,
98 Function | MediumTest | Level1) {
99 int ret;
100
101 char key[] = "keywithonlylowercase";
102 char value[] = "test key with only lowercase";
103 ret = SetParameter(key, value);
104 TEST_ASSERT_EQUAL_INT(0, ret);
105 };
106
107 /**
108 * @tc.number : SUB_UTILS_PARAMETER_2800
109 * @tc.name : SetParameter parameter legal test using key with only number
110 * @tc.desc : [C- SOFTWARE -0200]
111 */
112 LITE_TEST_CASE(ParameterFuncTestSuite,
113 testSetParameter004,
114 Function | MediumTest | Level1) {
115 int ret;
116
117 char key[] = "202006060602";
118 char value[] = "test key with only number";
119 ret = SetParameter(key, value);
120 TEST_ASSERT_EQUAL_INT(0, ret);
121 };
122
123 /**
124 * @tc.number : SUB_UTILS_PARAMETER_2900
125 * @tc.name : SetParameter parameter legal test using key and value with
126 * maximum length
127 * @tc.desc : [C- SOFTWARE -0200]
128 */
129 LITE_TEST_CASE(ParameterFuncTestSuite,
130 testSetParameter005,
131 Function | MediumTest | Level1) {
132 int ret;
133
134 char key1[] = "rw.sys.version.version.version";
135 char value1[] = "set with key = 31";
136 ret = SetParameter(key1, value1);
137 TEST_ASSERT_EQUAL_INT(0, ret);
138
139 char key2[] = "rw.sys.version.version";
140 char value2[] =
141 "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklm\
142 nopqrstuvwxyz1234567890abcdefghijklmnopqrstuvw";
143 ret = SetParameter(key2, value2);
144 TEST_ASSERT_EQUAL_INT(0, ret);
145 };
146
147 /**
148 * @tc.number : SUB_UTILS_PARAMETER_3000
149 * @tc.name : SetParameter parameter illegal test when key is nullptr and
150 * value is nullptr
151 * @tc.desc : [C- SOFTWARE -0200]
152 */
153 LITE_TEST_CASE(ParameterFuncTestSuite,
154 testSetParameter006,
155 Function | MediumTest | Level1) {
156 int ret;
157
158 char value[] = "test with null";
159 ret = SetParameter(NULL, value);
160 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
161 TEST_ASSERT_EQUAL_INT(1, 1);
162 }
163
164 char key[] = "rw.sys.version";
165 ret = SetParameter(key, NULL);
166 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
167 TEST_ASSERT_EQUAL_INT(1, 1);
168 }
169 };
170
171 /**
172 * @tc.number : SUB_UTILS_PARAMETER_3100
173 * @tc.name : SetParameter parameter illegal test when key is NULL and
174 * value is NULL
175 * @tc.desc : [C- SOFTWARE -0200]
176 */
177 LITE_TEST_CASE(ParameterFuncTestSuite,
178 testSetParameter007,
179 Function | MediumTest | Level1) {
180 int ret;
181
182 char value[] = "test with null";
183 ret = SetParameter("\0", value);
184 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
185 TEST_ASSERT_EQUAL_INT(1, 1);
186 }
187
188 char key[] = "rw.sys.version";
189 ret = SetParameter(key, "\0");
190 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
191 TEST_ASSERT_EQUAL_INT(1, 1);
192 }
193 };
194
195 /**
196 * @tc.number : SUB_UTILS_PARAMETER_3200
197 * @tc.name : SetParameter parameter illegal test when key len is 32 or
198 * more than 32 bytes
199 * @tc.desc : [C- SOFTWARE -0200]
200 */
201 LITE_TEST_CASE(ParameterFuncTestSuite,
202 testSetParameter008,
203 Function | MediumTest | Level1) {
204 int ret;
205
206 char key1[] = "rw.sys.version.version.version.v";
207 char value1[] = "set with key = 32";
208 ret = SetParameter(key1, value1);
209 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
210 TEST_ASSERT_EQUAL_INT(1, 1);
211 }
212
213 char key2[] = "rw.sys.version.version.version.version";
214 char value2[] = "set with key > 32";
215 ret = SetParameter(key2, value2);
216 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
217 TEST_ASSERT_EQUAL_INT(1, 1);
218 }
219 };
220
221 /**
222 * @tc.number : SUB_UTILS_PARAMETER_3300
223 * @tc.name : SetParameter parameter illegal test using key with uppercase
224 * @tc.desc : [C- SOFTWARE -0200]
225 */
226 LITE_TEST_CASE(ParameterFuncTestSuite,
227 testSetParameter009,
228 Function | MediumTest | Level1) {
229 int ret;
230
231 char key[] = "Rw.Sys.Version.Version";
232 char value[] = "set value with uppercase";
233 ret = SetParameter(key, value);
234 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
235 TEST_ASSERT_EQUAL_INT(1, 1);
236 }
237 };
238
239 /**
240 * @tc.number : SUB_UTILS_PARAMETER_3400
241 * @tc.name : SetParameter parameter illegal test using key with blank
242 * @tc.desc : [C- SOFTWARE -0200]
243 */
244 LITE_TEST_CASE(ParameterFuncTestSuite,
245 testSetParameter010,
246 Function | MediumTest | Level1) {
247 int ret;
248
249 char key[] = "rw sys version version";
250 char value[] = "set value with blank";
251 ret = SetParameter(key, value);
252 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
253 TEST_ASSERT_EQUAL_INT(1, 1);
254 }
255 };
256
257 /**
258 * @tc.number : SUB_UTILS_PARAMETER_3500
259 * @tc.name : SetParameter parameter illegal test using key with invalid
260 * special characters
261 * @tc.desc : [C- SOFTWARE -0200]
262 */
263 LITE_TEST_CASE(ParameterFuncTestSuite,
264 testSetParameter011,
265 Function | MediumTest | Level1) {
266 int ret;
267
268 char key[] = "rw+sys&version%version*";
269 char value[] = "set value with special characters";
270 ret = SetParameter(key, value);
271 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
272 TEST_ASSERT_EQUAL_INT(1, 1);
273 }
274 };
275
276 /**
277 * @tc.number : SUB_UTILS_PARAMETER_3600
278 * @tc.name : SetParameter parameter illegal test when value length is 128
279 * or more than 128 bytes
280 * @tc.desc : [C- SOFTWARE -0200]
281 */
282 LITE_TEST_CASE(ParameterFuncTestSuite,
283 testSetParameter012,
284 Function | MediumTest | Level1) {
285 int ret;
286
287 char key1[] = "rw.sys.version.version1";
288 char value1[] =
289 "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
290 abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrst";
291 ret = SetParameter(key1, value1);
292 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
293 TEST_ASSERT_EQUAL_INT(1, 1);
294 }
295
296 char key2[] = "rw.sys.version.version2";
297 char value2[] =
298 "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
299 abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890";
300 ret = SetParameter(key2, value2);
301 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
302 TEST_ASSERT_EQUAL_INT(1, 1);
303 }
304 };
305
306 /**
307 * @tc.number : SUB_UTILS_PARAMETER_3700
308 * @tc.name : SetParameter parameter legal test when value contains only
309 * blanks
310 * @tc.desc : [C- SOFTWARE -0200]
311 */
312 LITE_TEST_CASE(ParameterFuncTestSuite,
313 testSetParameter013,
314 Function | MediumTest | Level1) {
315 int ret;
316
317 char key[] = "key_for_blank_value";
318 char value[] = " ";
319 ret = SetParameter(key, value);
320 TEST_ASSERT_EQUAL_INT(0, ret);
321 };
322
323 /**
324 * @tc.number : SUB_UTILS_PARAMETER_3800
325 * @tc.name : GetParameter parameter legal test
326 * @tc.desc : [C- SOFTWARE -0200]
327 */
328 LITE_TEST_CASE(ParameterFuncTestSuite,
329 testGetParameter001,
330 Function | MediumTest | Level1) {
331 int ret;
332
333 char key[] = "rw.sys.version_606";
334 char rightVal[] = "OEM-10.1.0";
335 char value[MAX_LEN] = {0};
336 SetParameter(key, rightVal);
337 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
338 TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
339 TEST_ASSERT_EQUAL_STRING(rightVal, value);
340 };
341
342 /**
343 * @tc.number : SUB_UTILS_PARAMETER_3900
344 * @tc.name : GetParameter parameter legal test with Special characters
345 * @tc.desc : [C- SOFTWARE -0200]
346 */
347 LITE_TEST_CASE(ParameterFuncTestSuite,
348 testGetParameter002,
349 Function | MediumTest | Level1) {
350 int ret;
351
352 char key[] = "_._..__...___";
353 char rightVal[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890";
354 char value[MAX_LEN] = {0};
355 SetParameter(key, rightVal);
356 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
357 TEST_ASSERT_EQUAL_INT(strlen(g_defSysParam), ret);
358 TEST_ASSERT_EQUAL_STRING(g_defSysParam, value);
359 };
360
361 /**
362 * @tc.number : SUB_UTILS_PARAMETER_4000
363 * @tc.name : GetParameter parameter legal test using key with only
364 * lowercase
365 * @tc.desc : [C- SOFTWARE -0200]
366 */
367 LITE_TEST_CASE(ParameterFuncTestSuite,
368 testGetParameter003,
369 Function | MediumTest | Level1) {
370 int ret;
371
372 char key[] = "keywithonlylowercase";
373 char rightVal[] = "test key with only lowercase";
374 char value[MAX_LEN] = {0};
375 SetParameter(key, rightVal);
376 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
377 TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
378 TEST_ASSERT_EQUAL_STRING(rightVal, value);
379 };
380
381 /**
382 * @tc.number : SUB_UTILS_PARAMETER_4100
383 * @tc.name : GetParameter parameter legal test using key with only number
384 * @tc.desc : [C- SOFTWARE -0200]
385 */
386 LITE_TEST_CASE(ParameterFuncTestSuite,
387 testGetParameter004,
388 Function | MediumTest | Level1) {
389 int ret;
390
391 char key[] = "202006060602";
392 char rightVal[] = "test key with only number";
393 char value[MAX_LEN] = {0};
394 SetParameter(key, rightVal);
395 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
396 TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
397 TEST_ASSERT_EQUAL_STRING(rightVal, value);
398 };
399
400 /**
401 * @tc.number : SUB_UTILS_PARAMETER_4200
402 * @tc.name : GetParameter parameter legal test when defaut value point is
403 * nullptr
404 * @tc.desc : [C- SOFTWARE -0200]
405 */
406 LITE_TEST_CASE(ParameterFuncTestSuite,
407 testGetParameter005,
408 Function | MediumTest | Level1) {
409 int ret;
410
411 char key[] = "rw.sys.version_606";
412 char rightVal[] = "OEM-10.1.0";
413 char value[MAX_LEN] = {0};
414 SetParameter(key, rightVal);
415 ret = GetParameter(key, NULL, value, MAX_LEN);
416 TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
417 TEST_ASSERT_EQUAL_STRING(rightVal, value);
418 };
419
420 /**
421 * @tc.number : SUB_UTILS_PARAMETER_4300
422 * @tc.name : GetParameter parameter legal test when the key is not exist
423 * @tc.desc : [C- SOFTWARE -0200]
424 */
425 LITE_TEST_CASE(ParameterFuncTestSuite,
426 testGetParameter006,
427 Function | MediumTest | Level1) {
428 int ret;
429
430 char key[] = "none.exist.key";
431 char value[MAX_LEN] = {0};
432 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
433 TEST_ASSERT_EQUAL_INT(strlen(g_defSysParam), ret);
434 TEST_ASSERT_EQUAL_STRING(g_defSysParam, value);
435 };
436
437 /**
438 * @tc.number : SUB_UTILS_PARAMETER_4400
439 * @tc.name : GetParameter parameter legal test using key and value with
440 * maximum length
441 * @tc.desc : [C- SOFTWARE -0200]
442 */
443 LITE_TEST_CASE(ParameterFuncTestSuite,
444 testGetParameter007,
445 Function | MediumTest | Level1) {
446 int ret;
447
448 char key1[] = "rw.sys.version.version.version";
449 char rightVal1[] = "set with key = 31";
450 char value1[MAX_LEN] = {0};
451 SetParameter(key1, rightVal1);
452 ret = GetParameter(key1, g_defSysParam, value1, MAX_LEN);
453 TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret);
454 TEST_ASSERT_EQUAL_STRING(rightVal1, value1);
455
456 char key2[] = "rw.sys.version.version";
457 char rightVal2[] =
458 "abcdefghijklmnopqrstuvwxyz1234567890abcdefgh\
459 ijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvw";
460 char value2[MAX_LEN] = {0};
461 SetParameter(key2, rightVal2);
462 ret = GetParameter(key2, g_defSysParam, value2, MAX_LEN);
463 TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret);
464 TEST_ASSERT_EQUAL_STRING(rightVal2, value2);
465 };
466
467 /**
468 * @tc.number : SUB_UTILS_PARAMETER_4500
469 * @tc.name : GetParameter parameter illegal test with invalid value length
470 * @tc.desc : [C- SOFTWARE -0200]
471 */
472 LITE_TEST_CASE(ParameterFuncTestSuite,
473 testGetParameter008,
474 Function | MediumTest | Level1) {
475 int ret;
476
477 char key[] = "rw.sys.version_606";
478 char rightVal[] = "OEM-10.1.0";
479 char value[INVALID_LEN] = {0};
480 SetParameter(key, rightVal);
481 ret = GetParameter(key, g_defSysParam, value, INVALID_LEN);
482 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
483 TEST_ASSERT_EQUAL_INT(1, 1);
484 }
485 };
486
487 /**
488 * @tc.number : SUB_UTILS_PARAMETER_4600
489 * @tc.name : GetParameter parameter illegal test when value point is
490 * nullptr
491 * @tc.desc : [C- SOFTWARE -0200]
492 */
493 LITE_TEST_CASE(ParameterFuncTestSuite,
494 testGetParameter009,
495 Function | MediumTest | Level1) {
496 int ret;
497
498 char key[] = "rw.sys.version_606";
499 char rightVal[] = "OEM-10.1.0";
500 SetParameter(key, rightVal);
501 ret = GetParameter(key, g_defSysParam, NULL, MAX_LEN);
502 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
503 TEST_ASSERT_EQUAL_INT(1, 1);
504 }
505 };
506
507 /**
508 * @tc.number : SUB_UTILS_PARAMETER_4700
509 * @tc.name : GetParameter parameter illegal test when key is not exist and
510 * value len is invalid
511 * @tc.desc : [C- SOFTWARE -0200]
512 */
513 LITE_TEST_CASE(ParameterFuncTestSuite,
514 testGetParameter010,
515 Function | MediumTest | Level1) {
516 int ret;
517
518 char key[] = "none.exist.key";
519 char value[INVALID_LEN] = {0};
520 ret = GetParameter(key, g_defSysParam, value, INVALID_LEN);
521 TEST_ASSERT_EQUAL_INT(-9, ret);
522 };
523
524 /**
525 * @tc.number : SUB_UTILS_PARAMETER_4800
526 * @tc.name : GetParameter parameter illegal test when key is not exist and
527 * defaut value point is nullptr
528 * @tc.desc : [C- SOFTWARE -0200]
529 */
530 LITE_TEST_CASE(ParameterFuncTestSuite,
531 testGetParameter011,
532 Function | MediumTest | Level1) {
533 int ret;
534
535 char key[] = "none.exist.key";
536 char value[MAX_LEN] = {0};
537 ret = GetParameter(key, NULL, value, MAX_LEN);
538 TEST_ASSERT_EQUAL_INT(SYSPARAM_NOT_FOUND, ret);
539 };
540
541 /**
542 * @tc.number : SUB_UTILS_PARAMETER_4900
543 * @tc.name : GetParameter parameter illegal test when key len is 32 bytes
544 * @tc.desc : [C- SOFTWARE -0200]
545 */
546 LITE_TEST_CASE(ParameterFuncTestSuite,
547 testGetParameter012,
548 Function | MediumTest | Level1) {
549 int ret;
550
551 char key[] = "rw.sys.version.version.version.v";
552 char value[MAX_LEN] = {0};
553 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
554 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
555 TEST_ASSERT_EQUAL_INT(1, 1);
556 }
557 };
558
559 /**
560 * @tc.number : SUB_UTILS_PARAMETER_5000
561 * @tc.name : GetParameter parameter illegal test when key len is more than
562 * 32 bytes
563 * @tc.desc : [C- SOFTWARE -0200]
564 */
565 LITE_TEST_CASE(ParameterFuncTestSuite,
566 testGetParameter013,
567 Function | MediumTest | Level1) {
568 int ret;
569
570 char key[] = "rw.sys.version.version.version.version";
571 char value[MAX_LEN] = {0};
572 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
573 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
574 TEST_ASSERT_EQUAL_INT(1, 1);
575 }
576 };
577
578 /**
579 * @tc.number : SUB_UTILS_PARAMETER_5100
580 * @tc.name : GetParameter parameter illegal test when key is nullptr
581 * @tc.desc : [C- SOFTWARE -0200]
582 */
583 LITE_TEST_CASE(ParameterFuncTestSuite,
584 testGetParameter014,
585 Function | MediumTest | Level1) {
586 int ret;
587
588 char value[MAX_LEN] = {0};
589 ret = GetParameter(NULL, g_defSysParam, value, MAX_LEN);
590 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
591 TEST_ASSERT_EQUAL_INT(1, 1);
592 }
593 };
594
595 /**
596 * @tc.number : SUB_UTILS_PARAMETER_5200
597 * @tc.name : GetParameter parameter illegal test using key with uppercase
598 * @tc.desc : [C- SOFTWARE -0200]
599 */
600 LITE_TEST_CASE(ParameterFuncTestSuite,
601 testGetParameter015,
602 Function | MediumTest | Level1) {
603 int ret;
604
605 char key[] = "Rw.Sys.Version.Version";
606 char value[MAX_LEN] = {0};
607 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
608 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
609 TEST_ASSERT_EQUAL_INT(1, 1);
610 }
611 };
612
613 /**
614 * @tc.number : SUB_UTILS_PARAMETER_5300
615 * @tc.name : GetParameter parameter illegal test using key with blank
616 * @tc.desc : [C- SOFTWARE -0200]
617 */
618 LITE_TEST_CASE(ParameterFuncTestSuite,
619 testGetParameter016,
620 Function | MediumTest | Level1) {
621 int ret;
622
623 char key[] = "rw sys version version";
624 char value[MAX_LEN] = {0};
625 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
626 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
627 TEST_ASSERT_EQUAL_INT(1, 1);
628 }
629 };
630
631 /**
632 * @tc.number : SUB_UTILS_PARAMETER_5400
633 * @tc.name : GetParameter parameter illegal test using key with invalid
634 * special characters
635 * @tc.desc : [C- SOFTWARE -0200]
636 */
637 LITE_TEST_CASE(ParameterFuncTestSuite,
638 testGetParameter017,
639 Function | MediumTest | Level1) {
640 int ret;
641
642 char key[] = "rw+sys&version%version*";
643 char value[MAX_LEN] = {0};
644 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
645 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
646 TEST_ASSERT_EQUAL_INT(1, 1);
647 }
648 };
649
650 /**
651 * @tc.number : SUB_UTILS_PARAMETER_5500
652 * @tc.name : GetParameter parameter illegal test when key is NULL
653 * @tc.desc : [C- SOFTWARE -0200]
654 */
655 LITE_TEST_CASE(ParameterFuncTestSuite,
656 testGetParameter018,
657 Function | MediumTest | Level1) {
658 int ret;
659
660 char value[MAX_LEN] = {0};
661 ret = GetParameter("\0", g_defSysParam, value, MAX_LEN);
662 if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
663 TEST_ASSERT_EQUAL_INT(1, 1);
664 }
665 };
666
667 /**
668 * @tc.number : SUB_UTILS_PARAMETER_5600
669 * @tc.name : GetParameter parameter legal test when value contains only
670 * blanks
671 * @tc.desc : [C- SOFTWARE -0200]
672 */
673 LITE_TEST_CASE(ParameterFuncTestSuite,
674 testGetParameter019,
675 Function | MediumTest | Level1) {
676 int ret;
677
678 char key[] = "key_for_blank_value";
679 char rightVal[] = " ";
680 char value[MAX_LEN] = {0};
681 SetParameter(key, rightVal);
682 ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
683 TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
684 TEST_ASSERT_EQUAL_STRING(rightVal, value);
685 };
686
687 /**
688 * @tc.number : SUB_UTILS_PARAMETER_5700
689 * @tc.name : Update value of parameter legal test
690 * @tc.desc : [C- SOFTWARE -0200]
691 */
692 LITE_TEST_CASE(ParameterFuncTestSuite,
693 testGetParameter020,
694 Function | MediumTest | Level1) {
695 int ret;
696
697 char key[] = "rw.sys.version_606";
698 char rightVal1[] = "OEM-10.1.0";
699 char value1[MAX_LEN] = {0};
700 ret = SetParameter(key, rightVal1);
701 TEST_ASSERT_EQUAL_INT(0, ret);
702 ret = GetParameter(key, g_defSysParam, value1, MAX_LEN);
703 TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret);
704 TEST_ASSERT_EQUAL_STRING(rightVal1, value1);
705
706 char rightVal2[] = "update the value of OEM-10.1.0";
707 char value2[MAX_LEN] = {0};
708 ret = SetParameter(key, rightVal2);
709 TEST_ASSERT_EQUAL_INT(0, ret);
710 ret = GetParameter(key, g_defSysParam, value2, MAX_LEN);
711 TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret);
712 TEST_ASSERT_EQUAL_STRING(rightVal2, value2);
713 };
714
715 RUN_TEST_SUITE(ParameterFuncTestSuite);
716