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 <cstddef>
18 #include <cstdint>
19 #include "securec.h"
20 #include "inner_api/wifi_msg.h"
21 #include "inner_api/wifi_device.h"
22 #include "wifi_logger.h"
23
24 using ::testing::_;
25 using ::testing::AtLeast;
26 using ::testing::DoAll;
27 using ::testing::Eq;
28 using ::testing::Ref;
29 using ::testing::Return;
30 using ::testing::SetArgReferee;
31 using ::testing::StrEq;
32 using ::testing::TypedEq;
33 using ::testing::ext::TestSize;
34 DEFINE_WIFILOG_LABEL("WifiInnerDeviceTest");
35
36 namespace OHOS {
37 namespace Wifi {
38 constexpr int NETWORKID = 0;
39 static std::string PROTECTNAME = "test1";
40 static std::string COUNTRYCODE = "86";
41 static std::shared_ptr<WifiDevice> devicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
42
43 class WifiInnerDeviceTest : public testing::Test {
44 public:
SetUpTestCase()45 static void SetUpTestCase() {}
TearDownTestCase()46 static void TearDownTestCase() {}
SetUp()47 virtual void SetUp() {}
TearDown()48 virtual void TearDown() {}
49 };
50
HWTEST_F(WifiInnerDeviceTest, InitWifiProtectTest, TestSize.Level1)51 HWTEST_F(WifiInnerDeviceTest, InitWifiProtectTest, TestSize.Level1)
52 {
53 WIFI_LOGE("InitWifiProtectTest enter!");
54 EXPECT_TRUE(devicePtr != nullptr);
55 ErrCode result = devicePtr->InitWifiProtect(WifiProtectType::WIFI_PROTECT_MULTICAST, PROTECTNAME);
56 WIFI_LOGE("InitWifiProtectTest result(0x%{public}x)", result);
57 EXPECT_GE(result, WIFI_OPT_SUCCESS);
58 }
59
HWTEST_F(WifiInnerDeviceTest, GetWifiProtectRefTest, TestSize.Level1)60 HWTEST_F(WifiInnerDeviceTest, GetWifiProtectRefTest, TestSize.Level1)
61 {
62 WIFI_LOGE("GetWifiProtectRefTest enter!");
63 EXPECT_TRUE(devicePtr != nullptr);
64 ErrCode result = devicePtr->GetWifiProtectRef(WifiProtectMode::WIFI_PROTECT_FULL, PROTECTNAME);
65 WIFI_LOGE("GetWifiProtectRefTest result(0x%{public}x)", result);
66 EXPECT_GE(result, WIFI_OPT_SUCCESS);
67 }
68
HWTEST_F(WifiInnerDeviceTest, PutWifiProtectRefTest, TestSize.Level1)69 HWTEST_F(WifiInnerDeviceTest, PutWifiProtectRefTest, TestSize.Level1)
70 {
71 WIFI_LOGE("PutWifiProtectRefTest enter!");
72 EXPECT_TRUE(devicePtr != nullptr);
73 ErrCode result = devicePtr->PutWifiProtectRef(PROTECTNAME);
74 WIFI_LOGE("PutWifiProtectRefTest result(0x%{public}x)", result);
75 EXPECT_GE(result, WIFI_OPT_SUCCESS);
76 }
77
HWTEST_F(WifiInnerDeviceTest, RemoveCandidateConfigTest, TestSize.Level1)78 HWTEST_F(WifiInnerDeviceTest, RemoveCandidateConfigTest, TestSize.Level1)
79 {
80 WIFI_LOGE("RemoveCandidateConfigTest enter!");
81 EXPECT_TRUE(devicePtr != nullptr);
82 ErrCode result = devicePtr->RemoveCandidateConfig(NETWORKID);
83 WIFI_LOGE("RemoveCandidateConfigTest result(0x%{public}x)", result);
84 EXPECT_GE(result, WIFI_OPT_SUCCESS);
85 }
86
HWTEST_F(WifiInnerDeviceTest, RemoveCandidateConfig2Test, TestSize.Level1)87 HWTEST_F(WifiInnerDeviceTest, RemoveCandidateConfig2Test, TestSize.Level1)
88 {
89 WIFI_LOGE("RemoveCandidateConfig2Test enter!");
90 EXPECT_TRUE(devicePtr != nullptr);
91 WifiDeviceConfig config;
92 ErrCode result = devicePtr->RemoveCandidateConfig(config);
93 WIFI_LOGE("RemoveCandidateConfig2Test result(0x%{public}x)", result);
94 EXPECT_GE(result, WIFI_OPT_SUCCESS);
95 }
96
HWTEST_F(WifiInnerDeviceTest, UpdateDeviceConfigTest, TestSize.Level1)97 HWTEST_F(WifiInnerDeviceTest, UpdateDeviceConfigTest, TestSize.Level1)
98 {
99 WIFI_LOGE("UpdateDeviceConfigTest enter!");
100 EXPECT_TRUE(devicePtr != nullptr);
101 WifiDeviceConfig config;
102 int ret;
103 ErrCode result = devicePtr->UpdateDeviceConfig(config, ret);
104 WIFI_LOGE("UpdateDeviceConfigTest result(0x%{public}x)", result);
105 EXPECT_GE(result, WIFI_OPT_SUCCESS);
106 }
107
HWTEST_F(WifiInnerDeviceTest, RemoveAllDeviceTest, TestSize.Level1)108 HWTEST_F(WifiInnerDeviceTest, RemoveAllDeviceTest, TestSize.Level1)
109 {
110 WIFI_LOGE("RemoveAllDeviceTest enter!");
111 EXPECT_TRUE(devicePtr != nullptr);
112 ErrCode result = devicePtr->RemoveAllDevice();
113 WIFI_LOGE("RemoveAllDeviceTest result(0x%{public}x)", result);
114 EXPECT_GE(result, WIFI_OPT_SUCCESS);
115 }
116
HWTEST_F(WifiInnerDeviceTest, EnableDeviceConfigTest, TestSize.Level1)117 HWTEST_F(WifiInnerDeviceTest, EnableDeviceConfigTest, TestSize.Level1)
118 {
119 WIFI_LOGE("EnableDeviceConfigTest enter!");
120 EXPECT_TRUE(devicePtr != nullptr);
121 ErrCode result = devicePtr->EnableDeviceConfig(NETWORKID, true);
122 WIFI_LOGE("EnableDeviceConfigTest result(0x%{public}x)", result);
123 EXPECT_GE(result, WIFI_OPT_SUCCESS);
124 }
125
HWTEST_F(WifiInnerDeviceTest, DisableDeviceConfigTest, TestSize.Level1)126 HWTEST_F(WifiInnerDeviceTest, DisableDeviceConfigTest, TestSize.Level1)
127 {
128 WIFI_LOGE("DisableDeviceConfigTest enter!");
129 EXPECT_TRUE(devicePtr != nullptr);
130 ErrCode result = devicePtr->DisableDeviceConfig(NETWORKID);
131 WIFI_LOGE("DisableDeviceConfigTest result(0x%{public}x)", result);
132 EXPECT_GE(result, WIFI_OPT_SUCCESS);
133 }
134
HWTEST_F(WifiInnerDeviceTest, IsConnectedTest, TestSize.Level1)135 HWTEST_F(WifiInnerDeviceTest, IsConnectedTest, TestSize.Level1)
136 {
137 WIFI_LOGE("IsConnectedTest enter!");
138 EXPECT_TRUE(devicePtr != nullptr);
139 bool isConnected = false;
140 ErrCode result = devicePtr->IsConnected(isConnected);
141 WIFI_LOGE("IsConnectedTest result(0x%{public}x)", result);
142 EXPECT_GE(result, WIFI_OPT_SUCCESS);
143 }
144
HWTEST_F(WifiInnerDeviceTest, ReConnectTest, TestSize.Level1)145 HWTEST_F(WifiInnerDeviceTest, ReConnectTest, TestSize.Level1)
146 {
147 WIFI_LOGE("ReConnectTest enter!");
148 EXPECT_TRUE(devicePtr != nullptr);
149 ErrCode result = devicePtr->ReConnect();
150 WIFI_LOGE("ReConnectTest result(0x%{public}x)", result);
151 EXPECT_GE(result, WIFI_OPT_SUCCESS);
152 }
153
HWTEST_F(WifiInnerDeviceTest, ReAssociateTest, TestSize.Level1)154 HWTEST_F(WifiInnerDeviceTest, ReAssociateTest, TestSize.Level1)
155 {
156 WIFI_LOGE("ReAssociateTest enter!");
157 EXPECT_TRUE(devicePtr != nullptr);
158 ErrCode result = devicePtr->ReAssociate();
159 WIFI_LOGE("ReAssociateTest result(0x%{public}x)", result);
160 EXPECT_GE(result, WIFI_OPT_SUCCESS);
161 }
162
HWTEST_F(WifiInnerDeviceTest, GetWifiStateTest, TestSize.Level1)163 HWTEST_F(WifiInnerDeviceTest, GetWifiStateTest, TestSize.Level1)
164 {
165 WIFI_LOGE("GetWifiStateTest enter!");
166 EXPECT_TRUE(devicePtr != nullptr);
167 int state;
168 ErrCode result = devicePtr->GetWifiState(state);
169 WIFI_LOGE("GetWifiStateTest result(0x%{public}x)", result);
170 EXPECT_GE(result, WIFI_OPT_SUCCESS);
171 }
172
HWTEST_F(WifiInnerDeviceTest, GetDisconnectedReasonTest, TestSize.Level1)173 HWTEST_F(WifiInnerDeviceTest, GetDisconnectedReasonTest, TestSize.Level1)
174 {
175 WIFI_LOGE("GetDisconnectedReasonTest enter!");
176 EXPECT_TRUE(devicePtr != nullptr);
177 DisconnectedReason reason;
178 ErrCode result = devicePtr->GetDisconnectedReason(reason);
179 WIFI_LOGE("GetDisconnectedReasonTest result(0x%{public}x)", result);
180 EXPECT_GE(result, WIFI_OPT_SUCCESS);
181 }
182
HWTEST_F(WifiInnerDeviceTest, GetIpv6InfoTest, TestSize.Level1)183 HWTEST_F(WifiInnerDeviceTest, GetIpv6InfoTest, TestSize.Level1)
184 {
185 WIFI_LOGE("GetIpv6InfoTest enter!");
186 EXPECT_TRUE(devicePtr != nullptr);
187 IpV6Info info;
188 ErrCode result = devicePtr->GetIpv6Info(info);
189 WIFI_LOGE("GetIpv6InfoTest result(0x%{public}x)", result);
190 EXPECT_GE(result, WIFI_OPT_SUCCESS);
191 }
192
HWTEST_F(WifiInnerDeviceTest, SetCountryCodeTest, TestSize.Level1)193 HWTEST_F(WifiInnerDeviceTest, SetCountryCodeTest, TestSize.Level1)
194 {
195 WIFI_LOGE("SetCountryCodeTest enter!");
196 EXPECT_TRUE(devicePtr != nullptr);
197 ErrCode result = devicePtr->SetCountryCode(COUNTRYCODE);
198 WIFI_LOGE("SetCountryCodeTest result(0x%{public}x)", result);
199 EXPECT_GE(result, WIFI_OPT_SUCCESS);
200 }
201
HWTEST_F(WifiInnerDeviceTest, GetCountryCodeTest, TestSize.Level1)202 HWTEST_F(WifiInnerDeviceTest, GetCountryCodeTest, TestSize.Level1)
203 {
204 WIFI_LOGE("GetCountryCodeTest enter!");
205 EXPECT_TRUE(devicePtr != nullptr);
206 std::string countryCode;
207 ErrCode result = devicePtr->GetCountryCode(countryCode);
208 WIFI_LOGE("GetCountryCodeTest result(0x%{public}x)", result);
209 EXPECT_GE(result, WIFI_OPT_SUCCESS);
210 }
211
HWTEST_F(WifiInnerDeviceTest, GetSupportedFeaturesTest, TestSize.Level1)212 HWTEST_F(WifiInnerDeviceTest, GetSupportedFeaturesTest, TestSize.Level1)
213 {
214 WIFI_LOGE("GetSupportedFeaturesTest enter!");
215 EXPECT_TRUE(devicePtr != nullptr);
216 long features;
217 ErrCode result = devicePtr->GetSupportedFeatures(features);
218 WIFI_LOGE("GetSupportedFeaturesTest result(0x%{public}x)", result);
219 EXPECT_GE(result, WIFI_OPT_SUCCESS);
220 }
221
HWTEST_F(WifiInnerDeviceTest, SetAppFrozenTest, TestSize.Level1)222 HWTEST_F(WifiInnerDeviceTest, SetAppFrozenTest, TestSize.Level1)
223 {
224 WIFI_LOGE("SetAppFrozenTest enter!");
225 EXPECT_TRUE(devicePtr != nullptr);
226 std::set<int> pidList;
227 pidList.insert(1011);
228 pidList.insert(1012);
229 ErrCode result = devicePtr->SetAppFrozen(pidList, true);
230 WIFI_LOGE("SetAppFrozenTest result(0x%{public}x)", result);
231 EXPECT_GE(result, WIFI_OPT_SUCCESS);
232 }
233
HWTEST_F(WifiInnerDeviceTest, ResetAllFrozenAppTest, TestSize.Level1)234 HWTEST_F(WifiInnerDeviceTest, ResetAllFrozenAppTest, TestSize.Level1)
235 {
236 WIFI_LOGE("ResetAllFrozenAppTest enter!");
237 EXPECT_TRUE(devicePtr != nullptr);
238 ErrCode result = devicePtr->ResetAllFrozenApp();
239 WIFI_LOGE("ResetAllFrozenAppTest result(0x%{public}x)", result);
240 EXPECT_GE(result, WIFI_OPT_SUCCESS);
241 }
242 } // namespace Wifi
243 } // namespace OHOS