• 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_wpa_common.h"
19 #include "wifi_wpa_common_test.h"
20 
21 using ::testing::_;
22 using ::testing::AtLeast;
23 using ::testing::Eq;
24 using ::testing::ext::TestSize;
25 
26 namespace OHOS {
27 namespace Wifi {
28 class WifiWpaCommonTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {}
TearDownTestCase()31     static void TearDownTestCase() {}
SetUp()32     virtual void SetUp()
33     {
34         g_wpaInterface = &wpaInterface;
35     }
TearDown()36     virtual void TearDown() {}
37     WifiWpaInterface wpaInterface;
38 };
39 
40 HWTEST_F(WifiWpaCommonTest, Hex2DecTest, TestSize.Level1)
41 {
42     char str[] = "0z1259";
43     char src[] = "0a1259";
44     char srf[] = "0xaAfF29";
45     char stc[] = "A1s62";
46     TrimQuotationMark(nullptr, 'A');
47     TrimQuotationMark(stc, 'A');
48     EXPECT_EQ(Hex2Dec(nullptr), 0);
49     EXPECT_EQ(Hex2Dec(str), 0);
50     EXPECT_EQ(Hex2Dec(src), 0);
51     EXPECT_TRUE(Hex2Dec(srf));
52 }
53 
54 HWTEST_F(WifiWpaCommonTest, InitWpaCtrlTest, TestSize.Level1)
55 {
56     WpaCtrl *pCtrl = nullptr;
57     char str[] = "A1s62";
58     EXPECT_TRUE(InitWpaCtrl(pCtrl, str) == -1);
59 }
60 
61 HWTEST_F(WifiWpaCommonTest, ReleaseWpaCtrlTest, TestSize.Level1)
62 {
63     WpaCtrl pCtrl;
64     char str[] = "A1s62";
65     InitWpaCtrl(&pCtrl, str);
66     ReleaseWpaCtrl(&pCtrl);
67     EXPECT_NE(str, "A1s62");
68 }
69 
70 HWTEST_F(WifiWpaCommonTest, WpaCliCmdTest_01, TestSize.Level1)
71 {
72     const size_t bufLen = 10;
73     const char cmd[bufLen] = "string";
74     char buf[bufLen] = "string";
75     int result = WpaCliCmd(cmd, buf, bufLen);
76     EXPECT_EQ(result, -1);
77 }
78 
79 HWTEST_F(WifiWpaCommonTest, WpaCliCmdTest_02, TestSize.Level1)
80 {
81     const size_t bufLen = 10;
82     int ten = 10;
83     const char cmd[bufLen] = "ENABLE";
84     char buf[bufLen] = "string";
85     int result = WpaCliCmd(cmd, buf, bufLen);
86     EXPECT_NE(result, ten);
87 }
88 
89 HWTEST_F(WifiWpaCommonTest, GetStrKeyValTest_01, TestSize.Level1)
90 {
91     const int len = 10;
92     char src[len];
93     const char split[len] = "string";
94     WpaKeyValue out;
95     GetStrKeyVal(src, split, &out);
96     EXPECT_NE(split, "string");
97 }
98 
99 HWTEST_F(WifiWpaCommonTest, GetStrKeyValTest_02, TestSize.Level1)
100 {
101     const int len = 10;
102     char src[len] = "string";
103     const char split[len] = "in";
104     WpaKeyValue out;
105     GetStrKeyVal(src, split, &out);
106     EXPECT_NE(src, "string");
107 }
108 
109 HWTEST_F(WifiWpaCommonTest, Hex2DecTest_01, TestSize.Level1)
110 {
111     const char *str = "0x123456";
112     int result = Hex2Dec(str);
113     EXPECT_NE(result, 0);
114 }
115 
116 HWTEST_F(WifiWpaCommonTest, TrimQuotationMarkTest, TestSize.Level1)
117 {
118     const int len = 10;
119     char str[len] = "string";
120     char c = 'A';
121     TrimQuotationMark(str, c);
122     EXPECT_NE(str, "string");
123 }
124 
125 HWTEST_F(WifiWpaCommonTest, Hex2numTest_01, TestSize.Level1)
126 {
127     char c = '1';
128     const char hex = '1';
129     int result = Hex2num(c);
130     EXPECT_NE(result, -1);
131 
132     result = Hex2byte(&hex);
133     EXPECT_EQ(result, -1);
134 }
135 
136 HWTEST_F(WifiWpaCommonTest, Hex2numTest_02, TestSize.Level1)
137 {
138     char c = 'a';
139     const char hex = 'a';
140     int result = Hex2num(c);
141     EXPECT_NE(result, -1);
142 
143     result = Hex2byte(&hex);
144     EXPECT_EQ(result, -1);
145 }
146 
147 HWTEST_F(WifiWpaCommonTest, Hex2numTest_03, TestSize.Level1)
148 {
149     char c = 'A';
150     const char hex = 'A';
151     int result = Hex2num(c);
152     EXPECT_NE(result, -1);
153 
154     result = Hex2byte(&hex);
155     EXPECT_EQ(result, -1);
156 }
157 
158 HWTEST_F(WifiWpaCommonTest, Hex2numTest_04, TestSize.Level1)
159 {
160     char c = '*';
161     const char hex = '*';
162     int result = Hex2num(c);
163     EXPECT_EQ(result, -1);
164 
165     result = Hex2byte(&hex);
166     EXPECT_EQ(result, -1);
167 }
168 
169 HWTEST_F(WifiWpaCommonTest, DealSymbolTest_01, TestSize.Level1)
170 {
171     const int len = 10;
172     u8 buf[len];
173     const char *pos = "!";
174     size_t size = 1;
175     DealSymbol(buf, &pos, &size);
176     EXPECT_NE(pos, "x");
177 }
178 
179 HWTEST_F(WifiWpaCommonTest, DealSymbolTest_02, TestSize.Level1)
180 {
181     const int len = 10;
182     u8 buf[len];
183     const char *pos = "x";
184     size_t size = 1;
185     DealSymbol(buf, &pos, &size);
186     EXPECT_NE(pos, "x");
187 }
188 
189 HWTEST_F(WifiWpaCommonTest, DealSymbolTest_03, TestSize.Level1)
190 {
191     const int len = 10;
192     u8 buf[len];
193     const char *pos = "e";
194     size_t size = 1;
195     DealSymbol(buf, &pos, &size);
196     EXPECT_NE(size, 1);
197 }
198 
199 } // namespace Wifi
200 } // namespace OHOS
201 
202