• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "hc_dev_info_test.h"
17 
18 #include <hctest.h>
19 #include <parameter.h>
20 #include <pthread.h>
21 #include <securec.h>
22 #include <stdlib.h>
23 
24 #include "print_log.h"
25 #include "test_timer.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define MAX_INPUT_UDID_LEN 200
32 
33 enum {
34     INPUT_UDID_LEN = 65,
35     TEST_UDID_TIMES = 20,
36 };
37 
TestGetDevUdid(char * udid,int len)38 static void TestGetDevUdid(char *udid, int len)
39 {
40     int res;
41     int zeroCount = 0;
42     res = memset_s(udid, MAX_INPUT_UDID_LEN, 0, MAX_INPUT_UDID_LEN);
43     TEST_ASSERT_EQUAL(0, res);
44 
45     RUN_AND_PRINT_ELAPSED_TIME(res, GetDevUdid(udid, len));
46     TEST_ASSERT_EQUAL(0, res);
47 
48     for (int i = 0; i < len; ++i) {
49         if (udid[i] == 0) {
50             ++zeroCount;
51         }
52     }
53     TEST_ASSERT_NOT_EQUAL_MESSAGE(len, zeroCount, "invalid all zero udid");
54 }
55 
TestHcGetUdid(void)56 void TestHcGetUdid(void)
57 {
58     int res;
59     char udid[MAX_INPUT_UDID_LEN] = {0};
60     int udidLen;
61     LOGI("check rand size udid");
62     for (int i = 0; i < TEST_UDID_TIMES; ++i) {
63         udidLen = rand() % (MAX_INPUT_UDID_LEN - INPUT_UDID_LEN) + INPUT_UDID_LEN;
64         LOGI("rand udidLen = %d", udidLen);
65         res = memset_s(udid, sizeof(udid), 0, sizeof(udid));
66         TEST_ASSERT_EQUAL(0, res);
67         TestGetDevUdid(udid, udidLen);
68         LOGI("udid = \"%s\"", udid);
69     }
70 
71     LOGI("check min size udid");
72     res = memset_s(udid, sizeof(udid), 0, sizeof(udid));
73     TEST_ASSERT_EQUAL(0, res);
74     TestGetDevUdid(udid, INPUT_UDID_LEN);
75     LOGI("udid = \"%s\"", udid);
76 
77     LOGI("check max size udid");
78     res = memset_s(udid, sizeof(udid), 0, sizeof(udid));
79     TEST_ASSERT_EQUAL(0, res);
80     TestGetDevUdid(udid, MAX_INPUT_UDID_LEN);
81     LOGI("udid = \"%s\"", udid);
82 }
83 
84 #ifdef __cplusplus
85 }
86 #endif
87