parameter_func_test.c 21.6 KB
Newer Older
W
wenjun 已提交
1
/*
M
mamingshuai 已提交
2
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
W
wenjun 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <securec.h>
#include "hctest.h"
L
leiyuqian 已提交
18
#include "ohos_types.h"
W
wenjun 已提交
19 20 21
#include "parameter.h"
#include "parameter_utils.h"

L
leiyuqian 已提交
22 23
#define MAX_LEN 128
#define INVALID_LEN 2
W
wenjun 已提交
24 25 26 27 28 29
#define COMMON_ERROR (-1)
#define INVALID_PARAMETER (-9)

static const char* g_defSysParam = "data of sys param ***...";

/**
L
leiyuqian 已提交
30 31
 * @tc.desc      : register a test suite, this suite is used to test basic flow
 * and interface dependency
W
wenjun 已提交
32 33 34 35 36 37 38 39 40 41
 * @param        : subsystem name is utils
 * @param        : module name is parameter
 * @param        : test suit name is ParameterFuncTestSuite
 */
LITE_TEST_SUIT(utils, parameter, ParameterFuncTestSuite);

/**
 * @tc.setup     : setup for all testcases
 * @return       : setup result, TRUE is success, FALSE is fail
 */
42 43
static BOOL ParameterFuncTestSuiteSetUp(void)
{
W
wenjun 已提交
44 45 46 47 48 49 50
    return TRUE;
}

/**
 * @tc.teardown  : teardown for all testcases
 * @return       : teardown result, TRUE is success, FALSE is fail
 */
51 52
static BOOL ParameterFuncTestSuiteTearDown(void)
{
W
wenjun 已提交
53 54 55 56 57
    printf("+-------------------------------------------+\n");
    return TRUE;
}

/**
M
mamingshuai 已提交
58 59
 * @tc.number    : SUB_UTILS_PARAMETER_2500
 * @tc.name      : SetParameter parameter legal test
W
wenjun 已提交
60 61
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
62 63 64
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter001,
               Function | MediumTest | Level1) {
W
wenjun 已提交
65 66 67
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
68
    char value[] = "OEM-10.1.0";
W
wenjun 已提交
69 70 71 72 73
    ret = SetParameter(key, value);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
74 75
 * @tc.number    : SUB_UTILS_PARAMETER_2600
 * @tc.name      : SetParameter parameter legal test with Special characters
W
wenjun 已提交
76 77
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
78 79 80
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter002,
               Function | MediumTest | Level1) {
W
wenjun 已提交
81 82 83 84 85 86 87 88 89
    int ret;

    char key[] = "_._..__...___";
    char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890";
    ret = SetParameter(key, value);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
90
 * @tc.number    : SUB_UTILS_PARAMETER_2700
L
leiyuqian 已提交
91 92
 * @tc.name      : SetParameter parameter legal test using key with only
 * lowercase
W
wenjun 已提交
93 94
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
95 96 97
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter003,
               Function | MediumTest | Level1) {
W
wenjun 已提交
98 99 100 101 102 103 104 105 106
    int ret;

    char key[] = "keywithonlylowercase";
    char value[] = "test key with only lowercase";
    ret = SetParameter(key, value);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
107 108
 * @tc.number    : SUB_UTILS_PARAMETER_2800
 * @tc.name      : SetParameter parameter legal test using key with only number
W
wenjun 已提交
109 110
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
111 112 113
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter004,
               Function | MediumTest | Level1) {
W
wenjun 已提交
114 115 116 117 118 119 120 121 122
    int ret;

    char key[] = "202006060602";
    char value[] = "test key with only number";
    ret = SetParameter(key, value);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
123
 * @tc.number    : SUB_UTILS_PARAMETER_2900
L
leiyuqian 已提交
124 125
 * @tc.name      : SetParameter parameter legal test using key and value with
 * maximum length
W
wenjun 已提交
126 127
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
128 129 130
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter005,
               Function | MediumTest | Level1) {
W
wenjun 已提交
131 132 133 134 135 136 137 138
    int ret;

    char key1[] = "rw.sys.version.version.version.";
    char value1[] = "set with key = 31";
    ret = SetParameter(key1, value1);
    TEST_ASSERT_EQUAL_INT(0, ret);

    char key2[] = "rw.sys.version.version";
L
leiyuqian 已提交
139 140
    char value2[] =
        "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
W
wenjun 已提交
141 142 143 144 145 146
abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs";
    ret = SetParameter(key2, value2);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
147
 * @tc.number    : SUB_UTILS_PARAMETER_3000
L
leiyuqian 已提交
148 149
 * @tc.name      : SetParameter parameter illegal test when key is nullptr and
 * value is nullptr
W
wenjun 已提交
150 151
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
152 153 154
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter006,
               Function | MediumTest | Level1) {
W
wenjun 已提交
155 156 157 158
    int ret;

    char value[] = "test with null";
    ret = SetParameter(NULL, value);
L
leiyuqian 已提交
159
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
160 161 162 163 164
        TEST_ASSERT_EQUAL_INT(1, 1);
    }

    char key[] = "rw.sys.version";
    ret = SetParameter(key, NULL);
L
leiyuqian 已提交
165
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
166 167 168 169 170
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
171
 * @tc.number    : SUB_UTILS_PARAMETER_3100
L
leiyuqian 已提交
172 173
 * @tc.name      : SetParameter parameter illegal test when key is NULL and
 * value is NULL
W
wenjun 已提交
174 175
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
176 177 178
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter007,
               Function | MediumTest | Level1) {
W
wenjun 已提交
179 180 181 182
    int ret;

    char value[] = "test with null";
    ret = SetParameter("\0", value);
L
leiyuqian 已提交
183
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
184 185 186 187 188
        TEST_ASSERT_EQUAL_INT(1, 1);
    }

    char key[] = "rw.sys.version";
    ret = SetParameter(key, "\0");
L
leiyuqian 已提交
189
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
190 191 192 193 194
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
195
 * @tc.number    : SUB_UTILS_PARAMETER_3200
L
leiyuqian 已提交
196 197
 * @tc.name      : SetParameter parameter illegal test when key len is 32 or
 * more than 32 bytes
W
wenjun 已提交
198 199
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
200 201 202
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter008,
               Function | MediumTest | Level1) {
W
wenjun 已提交
203 204 205 206 207
    int ret;

    char key1[] = "rw.sys.version.version.version.v";
    char value1[] = "set with key = 32";
    ret = SetParameter(key1, value1);
L
leiyuqian 已提交
208
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
209 210 211 212 213 214
        TEST_ASSERT_EQUAL_INT(1, 1);
    }

    char key2[] = "rw.sys.version.version.version.version";
    char value2[] = "set with key > 32";
    ret = SetParameter(key2, value2);
L
leiyuqian 已提交
215
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
216 217 218 219 220
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
221 222
 * @tc.number    : SUB_UTILS_PARAMETER_3300
 * @tc.name      : SetParameter parameter illegal test using key with uppercase
W
wenjun 已提交
223 224
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
225 226 227
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter009,
               Function | MediumTest | Level1) {
W
wenjun 已提交
228 229 230 231 232
    int ret;

    char key[] = "Rw.Sys.Version.Version";
    char value[] = "set value with uppercase";
    ret = SetParameter(key, value);
L
leiyuqian 已提交
233
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
234 235 236 237 238
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
239 240
 * @tc.number    : SUB_UTILS_PARAMETER_3400
 * @tc.name      : SetParameter parameter illegal test using key with blank
W
wenjun 已提交
241 242
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
243 244 245
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter010,
               Function | MediumTest | Level1) {
W
wenjun 已提交
246 247 248 249 250
    int ret;

    char key[] = "rw sys version version";
    char value[] = "set value with blank";
    ret = SetParameter(key, value);
L
leiyuqian 已提交
251
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
252 253 254 255 256
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
257
 * @tc.number    : SUB_UTILS_PARAMETER_3500
L
leiyuqian 已提交
258 259
 * @tc.name      : SetParameter parameter illegal test using key with invalid
 * special characters
W
wenjun 已提交
260 261
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
262 263 264
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter011,
               Function | MediumTest | Level1) {
W
wenjun 已提交
265 266 267 268 269
    int ret;

    char key[] = "rw+sys&version%version*";
    char value[] = "set value with special characters";
    ret = SetParameter(key, value);
L
leiyuqian 已提交
270
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
271 272 273 274 275
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
276
 * @tc.number    : SUB_UTILS_PARAMETER_3600
L
leiyuqian 已提交
277 278
 * @tc.name      : SetParameter parameter illegal test when value length is 128
 * or more than 128 bytes
W
wenjun 已提交
279 280
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
281 282 283
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter012,
               Function | MediumTest | Level1) {
W
wenjun 已提交
284 285 286
    int ret;

    char key1[] = "rw.sys.version.version1";
L
leiyuqian 已提交
287 288
    char value1[] =
        "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
W
wenjun 已提交
289 290
abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrst";
    ret = SetParameter(key1, value1);
L
leiyuqian 已提交
291
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
292 293 294 295
        TEST_ASSERT_EQUAL_INT(1, 1);
    }

    char key2[] = "rw.sys.version.version2";
L
leiyuqian 已提交
296 297
    char value2[] =
        "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
W
wenjun 已提交
298 299
abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890";
    ret = SetParameter(key2, value2);
L
leiyuqian 已提交
300
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
301 302 303 304 305
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
306
 * @tc.number    : SUB_UTILS_PARAMETER_3700
L
leiyuqian 已提交
307 308
 * @tc.name      : SetParameter parameter legal test when value contains only
 * blanks
W
wenjun 已提交
309 310
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
311 312 313
LITE_TEST_CASE(ParameterFuncTestSuite,
               testSetParameter013,
               Function | MediumTest | Level1) {
W
wenjun 已提交
314 315 316 317 318 319 320 321 322
    int ret;

    char key[] = "key_for_blank_value";
    char value[] = "                         ";
    ret = SetParameter(key, value);
    TEST_ASSERT_EQUAL_INT(0, ret);
};

/**
M
mamingshuai 已提交
323 324
 * @tc.number    : SUB_UTILS_PARAMETER_3800
 * @tc.name      : GetParameter parameter legal test
W
wenjun 已提交
325 326
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
327 328 329
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter001,
               Function | MediumTest | Level1) {
W
wenjun 已提交
330 331 332
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
333
    char rightVal[] = "OEM-10.1.0";
W
wenjun 已提交
334 335 336 337
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
338
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
339 340 341
};

/**
M
mamingshuai 已提交
342 343
 * @tc.number    : SUB_UTILS_PARAMETER_3900
 * @tc.name      : GetParameter parameter legal test with Special characters
W
wenjun 已提交
344 345
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
346 347 348
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter002,
               Function | MediumTest | Level1) {
W
wenjun 已提交
349 350 351 352 353 354 355 356
    int ret;

    char key[] = "_._..__...___";
    char rightVal[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890";
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
357
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
358 359 360
};

/**
M
mamingshuai 已提交
361
 * @tc.number    : SUB_UTILS_PARAMETER_4000
L
leiyuqian 已提交
362 363
 * @tc.name      : GetParameter parameter legal test using key with only
 * lowercase
W
wenjun 已提交
364 365
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
366 367 368
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter003,
               Function | MediumTest | Level1) {
W
wenjun 已提交
369 370 371 372 373 374 375 376
    int ret;

    char key[] = "keywithonlylowercase";
    char rightVal[] = "test key with only lowercase";
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
377
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
378 379 380
};

/**
M
mamingshuai 已提交
381 382
 * @tc.number    : SUB_UTILS_PARAMETER_4100
 * @tc.name      : GetParameter parameter legal test using key with only number
W
wenjun 已提交
383 384
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
385 386 387
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter004,
               Function | MediumTest | Level1) {
W
wenjun 已提交
388 389 390 391 392 393 394 395
    int ret;

    char key[] = "202006060602";
    char rightVal[] = "test key with only number";
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
396
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
397 398 399
};

/**
M
mamingshuai 已提交
400
 * @tc.number    : SUB_UTILS_PARAMETER_4200
L
leiyuqian 已提交
401 402
 * @tc.name      : GetParameter parameter legal test when defaut value point is
 * nullptr
W
wenjun 已提交
403 404
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
405 406 407
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter005,
               Function | MediumTest | Level1) {
W
wenjun 已提交
408 409 410
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
411
    char rightVal[] = "OEM-10.1.0";
W
wenjun 已提交
412 413 414 415
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, NULL, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
416
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
417 418 419
};

/**
M
mamingshuai 已提交
420 421
 * @tc.number    : SUB_UTILS_PARAMETER_4300
 * @tc.name      : GetParameter parameter legal test when the key is not exist
W
wenjun 已提交
422 423
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
424 425 426
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter006,
               Function | MediumTest | Level1) {
W
wenjun 已提交
427 428 429 430 431 432
    int ret;

    char key[] = "none.exist.key";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(g_defSysParam), ret);
M
mamingshuai 已提交
433
    TEST_ASSERT_EQUAL_STRING(g_defSysParam, value);
W
wenjun 已提交
434 435 436
};

/**
M
mamingshuai 已提交
437
 * @tc.number    : SUB_UTILS_PARAMETER_4400
L
leiyuqian 已提交
438 439
 * @tc.name      : GetParameter parameter legal test using key and value with
 * maximum length
W
wenjun 已提交
440 441
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
442 443 444
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter007,
               Function | MediumTest | Level1) {
W
wenjun 已提交
445 446 447 448 449 450 451 452
    int ret;

    char key1[] = "rw.sys.version.version.version.";
    char rightVal1[] = "set with key = 31";
    char value1[MAX_LEN] = {0};
    SetParameter(key1, rightVal1);
    ret = GetParameter(key1, g_defSysParam, value1, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret);
M
mamingshuai 已提交
453
    TEST_ASSERT_EQUAL_STRING(rightVal1, value1);
W
wenjun 已提交
454 455

    char key2[] = "rw.sys.version.version";
L
leiyuqian 已提交
456 457
    char rightVal2[] =
        "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\
W
wenjun 已提交
458 459 460 461 462
abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs";
    char value2[MAX_LEN] = {0};
    SetParameter(key2, rightVal2);
    ret = GetParameter(key2, g_defSysParam, value2, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret);
M
mamingshuai 已提交
463
    TEST_ASSERT_EQUAL_STRING(rightVal2, value2);
W
wenjun 已提交
464 465 466
};

/**
M
mamingshuai 已提交
467 468
 * @tc.number    : SUB_UTILS_PARAMETER_4500
 * @tc.name      : GetParameter parameter illegal test with invalid value length
W
wenjun 已提交
469 470
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
471 472 473
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter008,
               Function | MediumTest | Level1) {
W
wenjun 已提交
474 475 476
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
477
    char rightVal[] = "OEM-10.1.0";
W
wenjun 已提交
478 479 480
    char value[INVALID_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, INVALID_LEN);
L
leiyuqian 已提交
481
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
482 483 484 485 486
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
487
 * @tc.number    : SUB_UTILS_PARAMETER_4600
L
leiyuqian 已提交
488 489
 * @tc.name      : GetParameter parameter illegal test when value point is
 * nullptr
W
wenjun 已提交
490 491
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
492 493 494
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter009,
               Function | MediumTest | Level1) {
W
wenjun 已提交
495 496 497
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
498
    char rightVal[] = "OEM-10.1.0";
W
wenjun 已提交
499 500
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, NULL, MAX_LEN);
L
leiyuqian 已提交
501
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
502 503 504 505 506
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
507
 * @tc.number    : SUB_UTILS_PARAMETER_4700
L
leiyuqian 已提交
508 509
 * @tc.name      : GetParameter parameter illegal test when key is not exist and
 * value len is invalid
W
wenjun 已提交
510 511
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
512 513 514
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter010,
               Function | MediumTest | Level1) {
W
wenjun 已提交
515 516 517 518 519 520 521 522 523
    int ret;

    char key[] = "none.exist.key";
    char value[INVALID_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, INVALID_LEN);
    TEST_ASSERT_EQUAL_INT(-1, ret);
};

/**
M
mamingshuai 已提交
524
 * @tc.number    : SUB_UTILS_PARAMETER_4800
L
leiyuqian 已提交
525 526
 * @tc.name      : GetParameter parameter illegal test when key is not exist and
 * defaut value point is nullptr
W
wenjun 已提交
527 528
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
529 530 531
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter011,
               Function | MediumTest | Level1) {
W
wenjun 已提交
532 533 534 535 536 537 538 539 540
    int ret;

    char key[] = "none.exist.key";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, NULL, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(-1, ret);
};

/**
M
mamingshuai 已提交
541 542
 * @tc.number    : SUB_UTILS_PARAMETER_4900
 * @tc.name      : GetParameter parameter illegal test when key len is 32 bytes
W
wenjun 已提交
543 544
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
545 546 547
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter012,
               Function | MediumTest | Level1) {
W
wenjun 已提交
548 549 550 551 552
    int ret;

    char key[] = "rw.sys.version.version.version.v";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
553
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
554 555 556 557 558
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
559
 * @tc.number    : SUB_UTILS_PARAMETER_5000
L
leiyuqian 已提交
560 561
 * @tc.name      : GetParameter parameter illegal test when key len is more than
 * 32 bytes
W
wenjun 已提交
562 563
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
564 565 566
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter013,
               Function | MediumTest | Level1) {
W
wenjun 已提交
567 568 569 570 571
    int ret;

    char key[] = "rw.sys.version.version.version.version";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
572
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
573 574 575 576 577
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
578 579
 * @tc.number    : SUB_UTILS_PARAMETER_5100
 * @tc.name      : GetParameter parameter illegal test when key is nullptr
W
wenjun 已提交
580 581
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
582 583 584
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter014,
               Function | MediumTest | Level1) {
W
wenjun 已提交
585 586 587 588
    int ret;

    char value[MAX_LEN] = {0};
    ret = GetParameter(NULL, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
589
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
590 591 592 593 594
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
595 596
 * @tc.number    : SUB_UTILS_PARAMETER_5200
 * @tc.name      : GetParameter parameter illegal test using key with uppercase
W
wenjun 已提交
597 598
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
599 600 601
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter015,
               Function | MediumTest | Level1) {
W
wenjun 已提交
602 603 604 605 606
    int ret;

    char key[] = "Rw.Sys.Version.Version";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
607
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
608 609 610 611 612
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
613 614
 * @tc.number    : SUB_UTILS_PARAMETER_5300
 * @tc.name      : GetParameter parameter illegal test using key with blank
W
wenjun 已提交
615 616
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
617 618 619
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter016,
               Function | MediumTest | Level1) {
W
wenjun 已提交
620 621 622 623 624
    int ret;

    char key[] = "rw sys version version";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
625
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
626 627 628 629 630
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
631
 * @tc.number    : SUB_UTILS_PARAMETER_5400
L
leiyuqian 已提交
632 633
 * @tc.name      : GetParameter parameter illegal test using key with invalid
 * special characters
W
wenjun 已提交
634 635
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
636 637 638
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter017,
               Function | MediumTest | Level1) {
W
wenjun 已提交
639 640 641 642 643
    int ret;

    char key[] = "rw+sys&version%version*";
    char value[MAX_LEN] = {0};
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
644
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
645 646 647 648 649
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
650 651
 * @tc.number    : SUB_UTILS_PARAMETER_5500
 * @tc.name      : GetParameter parameter illegal test when key is NULL
W
wenjun 已提交
652 653
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
654 655 656
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter018,
               Function | MediumTest | Level1) {
W
wenjun 已提交
657 658 659 660
    int ret;

    char value[MAX_LEN] = {0};
    ret = GetParameter("\0", g_defSysParam, value, MAX_LEN);
L
leiyuqian 已提交
661
    if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) {
W
wenjun 已提交
662 663 664 665 666
        TEST_ASSERT_EQUAL_INT(1, 1);
    }
};

/**
M
mamingshuai 已提交
667
 * @tc.number    : SUB_UTILS_PARAMETER_5600
L
leiyuqian 已提交
668 669
 * @tc.name      : GetParameter parameter legal test when value contains only
 * blanks
W
wenjun 已提交
670 671
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
672 673 674
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter019,
               Function | MediumTest | Level1) {
W
wenjun 已提交
675 676 677 678 679 680 681 682
    int ret;

    char key[] = "key_for_blank_value";
    char rightVal[] = "                         ";
    char value[MAX_LEN] = {0};
    SetParameter(key, rightVal);
    ret = GetParameter(key, g_defSysParam, value, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret);
M
mamingshuai 已提交
683
    TEST_ASSERT_EQUAL_STRING(rightVal, value);
W
wenjun 已提交
684 685 686
};

/**
M
mamingshuai 已提交
687
 * @tc.number    : SUB_UTILS_PARAMETER_5700
W
wenjun 已提交
688 689 690
 * @tc.name      : Update value of parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
L
leiyuqian 已提交
691 692 693
LITE_TEST_CASE(ParameterFuncTestSuite,
               testGetParameter020,
               Function | MediumTest | Level1) {
W
wenjun 已提交
694 695 696
    int ret;

    char key[] = "rw.sys.version_606";
M
mamingshuai 已提交
697
    char rightVal1[] = "OEM-10.1.0";
W
wenjun 已提交
698 699 700 701 702
    char value1[MAX_LEN] = {0};
    ret = SetParameter(key, rightVal1);
    TEST_ASSERT_EQUAL_INT(0, ret);
    ret = GetParameter(key, g_defSysParam, value1, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret);
M
mamingshuai 已提交
703
    TEST_ASSERT_EQUAL_STRING(rightVal1, value1);
W
wenjun 已提交
704

M
mamingshuai 已提交
705
    char rightVal2[] = "update the value of OEM-10.1.0";
W
wenjun 已提交
706 707 708 709 710
    char value2[MAX_LEN] = {0};
    ret = SetParameter(key, rightVal2);
    TEST_ASSERT_EQUAL_INT(0, ret);
    ret = GetParameter(key, g_defSysParam, value2, MAX_LEN);
    TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret);
M
mamingshuai 已提交
711
    TEST_ASSERT_EQUAL_STRING(rightVal2, value2);
W
wenjun 已提交
712 713 714
};

RUN_TEST_SUITE(ParameterFuncTestSuite);