1 /*
2 * Copyright (c) 2023 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 <iostream>
17
18 #include "udid.h"
19 #include "param_stub.h"
20 #include "sysparam_errno.h"
21 #include "securec.h"
22
23 using namespace std;
24 using namespace testing::ext;
25
26 namespace init_ut {
27 extern "C" {
28 int GetSha256Value(const char *input, char *udid, uint32_t udidSize);
29 void SetDevUdid();
30 int CalcDevUdid(char *udid, uint32_t size);
31 }
32
33 class UdidUnitTest : public testing::Test {
34 public:
SetUpTestCase(void)35 static void SetUpTestCase(void) {};
TearDownTestCase(void)36 static void TearDownTestCase(void) {};
SetUp()37 void SetUp() {};
TearDown()38 void TearDown() {};
39 };
40
HWTEST_F(UdidUnitTest, TestUDID_001, TestSize.Level1)41 HWTEST_F(UdidUnitTest, TestUDID_001, TestSize.Level1)
42 {
43 SetDevUdid();
44 }
45
HWTEST_F(UdidUnitTest, TestUDID_002, TestSize.Level1)46 HWTEST_F(UdidUnitTest, TestUDID_002, TestSize.Level1)
47 {
48 int ret = GetSha256Value(nullptr, nullptr, 0);
49 EXPECT_EQ(ret, EC_FAILURE);
50 }
51
HWTEST_F(UdidUnitTest, TestUDID_003, TestSize.Level1)52 HWTEST_F(UdidUnitTest, TestUDID_003, TestSize.Level1)
53 {
54 char udid[66] = {0};
55 int ret = CalcDevUdid(udid, 6);
56 EXPECT_EQ(ret, EC_FAILURE);
57 ret = CalcDevUdid(udid, 66);
58 EXPECT_EQ(ret, EC_SUCCESS);
59 }
60 } // namespace init_ut
61