• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
16 #include <gmock/gmock.h>
17 #include "securec.h"
18 #include "wifi_hal_common_func.h"
19 
20 using ::testing::_;
21 using ::testing::AtLeast;
22 using ::testing::Eq;
23 using ::testing::ext::TestSize;
24 
25 namespace OHOS {
26 namespace Wifi {
27 
28 constexpr int MAC_LEN = 17;
29 constexpr int LENTH = 6;
30 class WifiHalCommonTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {}
TearDownTestCase()33     static void TearDownTestCase() {}
SetUp()34     virtual void SetUp() {}
TearDown()35     virtual void TearDown() {}
36 };
37 
38 HWTEST_F(WifiHalCommonTest, ConvertMacToStrFail1, TestSize.Level1)
39 {
40     unsigned char *mac = NULL;
41     int macSize = LENTH;
42     char macStr[MAC_LEN + 1] = "00:00:00:00:00:00";
43     int strLen = MAC_LEN + 1;
44     EXPECT_EQ(ConvertMacToStr(mac, macSize, macStr, strLen), -1);
45 }
46 
47 HWTEST_F(WifiHalCommonTest, ConvertMacToStrFail2, TestSize.Level1)
48 {
49     char *macStr = NULL;
50     int macSize = LENTH;
51     unsigned char mac[LENTH] = "ABCDE";
52     int strLen = MAC_LEN + 1;
53     EXPECT_EQ(ConvertMacToStr(mac, macSize, macStr, strLen), -1);
54 }
55 
56 HWTEST_F(WifiHalCommonTest, ConvertMacToStrFail3, TestSize.Level1)
57 {
58     unsigned char mac[LENTH] = "ABCDE";
59     int macSize = 7;
60     char macStr[MAC_LEN + 1] = "00:00:00:00:00:00";
61     int strLen = MAC_LEN + 1;
62     EXPECT_EQ(ConvertMacToStr(mac, macSize, macStr, strLen), -1);
63 }
64 
65 HWTEST_F(WifiHalCommonTest, ConvertMacToStrFail4, TestSize.Level1)
66 {
67     unsigned char mac[LENTH] = "ABCDE";
68     int macSize = LENTH;
69     char macStr[MAC_LEN + 1] = "00:00:00:00:00:00";
70     int strLen = MAC_LEN;
71     EXPECT_EQ(ConvertMacToStr(mac, macSize, macStr, strLen), -1);
72 }
73 
74 HWTEST_F(WifiHalCommonTest, ConvertMacToStrSuccess, TestSize.Level1)
75 {
76     unsigned char mac[LENTH] = "ABCDE";
77     int macSize = LENTH;
78     char macStr[MAC_LEN + 1] = "00:00:00:00:00:00";
79     int strLen = MAC_LEN + 1;
80     EXPECT_EQ(ConvertMacToStr(mac, macSize, macStr, strLen), 0);
81 }
82 
83 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail1, TestSize.Level1)
84 {
85     unsigned char *mac = NULL;
86     int macSize = LENTH;
87     EXPECT_EQ(ConvertMacToArray("00:00:00:00:00:00", mac, macSize), -1);
88 }
89 
90 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail2, TestSize.Level1)
91 {
92     unsigned char mac[LENTH] = "ABCDE";
93     const char *macStr = NULL;
94     int macSize = LENTH;
95     EXPECT_EQ(ConvertMacToArray(macStr, mac, macSize), -1);
96 }
97 
98 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail3, TestSize.Level1)
99 {
100     unsigned char mac[LENTH] = "ABCDE";
101     int macSize = 7;
102     EXPECT_EQ(ConvertMacToArray("AA:BB:CC:DD:EE:FF", mac, macSize), -1);
103 }
104 
105 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail4, TestSize.Level1)
106 {
107     unsigned char mac[LENTH] = "ABCDE";
108     int macSize = LENTH;
109     EXPECT_EQ(ConvertMacToArray("AA:BB:CC:DD:EE", mac, macSize), -1);
110 }
111 
112 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail5, TestSize.Level1)
113 {
114     unsigned char mac[LENTH] = "ABCDE";
115     int macSize = LENTH;
116     EXPECT_EQ(ConvertMacToArray("AA:!!:CC:DD:EE:FF", mac, macSize), -1);
117 }
118 
119 HWTEST_F(WifiHalCommonTest, ConvertMacToArrayFail6, TestSize.Level1)
120 {
121     unsigned char mac[LENTH] = "ABCDE";
122     int macSize = LENTH;
123     EXPECT_EQ(ConvertMacToArray("AA,BB:CC:DD:EE:FF", mac, macSize), -1);
124 }
125 
126 HWTEST_F(WifiHalCommonTest, ConvertMacToArraySuccess, TestSize.Level1)
127 {
128     unsigned char mac[LENTH] = "ABCDE";
129     int macSize = LENTH;
130     EXPECT_EQ(ConvertMacToArray("AA:BB:CC:DD:EE:FF", mac, macSize), 0);
131 }
132 
133 HWTEST_F(WifiHalCommonTest, CheckMacIsValidFail1, TestSize.Level1)
134 {
135     char *macStr = NULL;
136     EXPECT_EQ(CheckMacIsValid(macStr), -1);
137 }
138 
139 HWTEST_F(WifiHalCommonTest, CheckMacIsValidFail2, TestSize.Level1)
140 {
141     EXPECT_EQ(CheckMacIsValid("00:00:00:00:00"), -1);
142 }
143 
144 HWTEST_F(WifiHalCommonTest, CheckMacIsValidFail3, TestSize.Level1)
145 {
146     EXPECT_EQ(CheckMacIsValid("00:!!:00:00:00:00"), -1);
147 }
148 
149 HWTEST_F(WifiHalCommonTest, CheckMacIsValidFail4, TestSize.Level1)
150 {
151     EXPECT_EQ(CheckMacIsValid("00,00:00:00:00:00"), -1);
152 }
153 
154 HWTEST_F(WifiHalCommonTest, CheckMacIsValidSuccess, TestSize.Level1)
155 {
156     EXPECT_EQ(CheckMacIsValid("00:00:00:00:00:00"), 0);
157 }
158 
159 HWTEST_F(WifiHalCommonTest, DataAnonymizeFail, TestSize.Level1)
160 {
161     char output[MAC_LEN] = "AA,bb:CC:DD:EE:F";
162     EXPECT_EQ(DataAnonymize(NULL, 5, output, 5), 1);
163     EXPECT_EQ(DataAnonymize("ABCDEF", 5, NULL, 0), 1);
164     EXPECT_EQ(DataAnonymize("ABCDEF", 6, output, 5), 1);
165     EXPECT_EQ(DataAnonymize("AA", 2, output, 2), 0);
166     EXPECT_EQ(DataAnonymize("AA,bb:CC", 8, output, 8), 0);
167     EXPECT_EQ(DataAnonymize("AA,bb:CC:DD:EE:FF", 17, output, 17), 0);
168 }
169 } // namespace Wifi
170 } // namespace OHOS
171 
172