1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include <hdf_log.h>
18 #include "../../../chip/hdi_service/wifi_ap_iface.h"
19 #include "wifi_hal_fn.h"
20
21 using namespace testing::ext;
22 using namespace OHOS::HDI::Wlan::Chip::V1_0;
23
24 namespace WifiApIfaceTest {
25 const std::string AP_IFNAME = "wlan1";
26 const std::string TEST_MAC = "000000";
27 class WifiApIfaceTest : public testing::Test {
28 public:
SetUpTestCase()29 static void SetUpTestCase() {}
TearDownTestCase()30 static void TearDownTestCase() {}
SetUp()31 void SetUp()
32 {
33 std::vector<std::string> instances = {AP_IFNAME};
34 ifaceTool = std::make_shared<IfaceTool>();
35 ifaceUtil = std::make_shared<IfaceUtil>(ifaceTool);
36 WifiHalFn fn;
37 InitWifiHalFuncTable(&fn);
38 wifiVendorHalTest = std::make_shared<WifiVendorHal>(ifaceTool, fn, true);
39 apIface = new (std::nothrow) WifiApIface(AP_IFNAME, instances, wifiVendorHalTest, ifaceUtil);
40 if (apIface == nullptr) {
41 HDF_LOGE("iface is null");
42 return;
43 }
44 }
TearDown()45 void TearDown()
46 {
47 wifiVendorHalTest.reset();
48 ifaceTool.reset();
49 ifaceUtil.reset();
50 }
51
52 public:
53 std::shared_ptr<WifiVendorHal> wifiVendorHalTest;
54 std::shared_ptr<IfaceTool> ifaceTool;
55 std::shared_ptr<IfaceUtil> ifaceUtil;
56 sptr<WifiApIface> apIface;
57 };
58
59 /**
60 * @tc.name: wifiApIfaceTest
61 * @tc.desc: wifiApIface
62 * @tc.type: FUNC
63 * @tc.require:
64 */
HWTEST_F(WifiApIfaceTest, wifiApIfaceTest001, TestSize.Level1)65 HWTEST_F(WifiApIfaceTest, wifiApIfaceTest001, TestSize.Level1)
66 {
67 HDF_LOGI("wifiApIfaceTest001 started");
68 if (apIface == nullptr) {
69 return;
70 }
71 apIface->Invalidate();
72 EXPECT_FALSE(apIface->IsValid());
73 EXPECT_TRUE(apIface->GetName() == AP_IFNAME);
74 apIface->RemoveInstance(AP_IFNAME);
75 IfaceType type;
76 EXPECT_TRUE(apIface->GetIfaceType(type) == HDF_SUCCESS);
77 EXPECT_TRUE(type == IfaceType::AP);
78 std::string name;
79 EXPECT_TRUE(apIface->GetIfaceName(name) == HDF_SUCCESS);
80 EXPECT_TRUE(name == AP_IFNAME);
81 }
82
83 /**
84 * @tc.name: GetIfaceCapTest
85 * @tc.desc: GetIfaceCap
86 * @tc.type: FUNC
87 * @tc.require:
88 */
HWTEST_F(WifiApIfaceTest, GetIfaceCapTest, TestSize.Level1)89 HWTEST_F(WifiApIfaceTest, GetIfaceCapTest, TestSize.Level1)
90 {
91 HDF_LOGI("GetIfaceCapTest started");
92 if (apIface == nullptr) {
93 HDF_LOGE("iface is null");
94 return;
95 }
96 uint32_t cap;
97 EXPECT_TRUE(apIface->GetIfaceCap(cap) == HDF_ERR_NOT_SUPPORT);
98 }
99
HWTEST_F(WifiApIfaceTest, StartScanTest, TestSize.Level1)100 HWTEST_F(WifiApIfaceTest, StartScanTest, TestSize.Level1)
101 {
102 HDF_LOGI("StartScanTest started");
103 if (apIface == nullptr) {
104 HDF_LOGE("iface is null");
105 return;
106 }
107 ScanParams scanParam;
108 scanParam.bssid = TEST_MAC;
109 EXPECT_TRUE(apIface->StartScan(scanParam) == HDF_ERR_NOT_SUPPORT);
110 }
111
HWTEST_F(WifiApIfaceTest, GetScanInfosTest, TestSize.Level1)112 HWTEST_F(WifiApIfaceTest, GetScanInfosTest, TestSize.Level1)
113 {
114 HDF_LOGI("GetScanInfosTest started");
115 if (apIface == nullptr) {
116 HDF_LOGE("iface is null");
117 return;
118 }
119 std::vector<ScanResultsInfo> scanResult;
120 EXPECT_TRUE(apIface->GetScanInfos(scanResult) == HDF_ERR_NOT_SUPPORT);
121 }
122
HWTEST_F(WifiApIfaceTest, StartPnoScanTest, TestSize.Level1)123 HWTEST_F(WifiApIfaceTest, StartPnoScanTest, TestSize.Level1)
124 {
125 HDF_LOGI("StartPnoScanTest started");
126 if (apIface == nullptr) {
127 HDF_LOGE("iface is null");
128 return;
129 }
130 PnoScanParams pnoParam;
131 pnoParam.min2gRssi = 1;
132 EXPECT_TRUE(apIface->StartPnoScan(pnoParam) == HDF_ERR_NOT_SUPPORT);
133 }
134
HWTEST_F(WifiApIfaceTest, StopPnoScanTest, TestSize.Level1)135 HWTEST_F(WifiApIfaceTest, StopPnoScanTest, TestSize.Level1)
136 {
137 HDF_LOGI("StopPnoScanTest started");
138 if (apIface == nullptr) {
139 HDF_LOGE("iface is null");
140 return;
141 }
142 EXPECT_TRUE(apIface->StopPnoScan() == HDF_ERR_NOT_SUPPORT);
143 }
144
HWTEST_F(WifiApIfaceTest, GetSignalPollInfoTest, TestSize.Level1)145 HWTEST_F(WifiApIfaceTest, GetSignalPollInfoTest, TestSize.Level1)
146 {
147 HDF_LOGI("GetSignalPollInfoTest started");
148 if (apIface == nullptr) {
149 HDF_LOGE("iface is null");
150 return;
151 }
152 SignalPollResult info;
153 EXPECT_TRUE(apIface->GetSignalPollInfo(info) == HDF_ERR_NOT_SUPPORT);
154 }
155
HWTEST_F(WifiApIfaceTest, SetDpiMarkRuleTest, TestSize.Level1)156 HWTEST_F(WifiApIfaceTest, SetDpiMarkRuleTest, TestSize.Level1)
157 {
158 HDF_LOGI("SetDpiMarkRuleTest started");
159 if (apIface == nullptr) {
160 HDF_LOGE("iface is null");
161 return;
162 }
163 EXPECT_TRUE(apIface->SetDpiMarkRule(0, 0, 0) == HDF_ERR_NOT_SUPPORT);
164 }
165
HWTEST_F(WifiApIfaceTest, EnablePowerModeTest, TestSize.Level1)166 HWTEST_F(WifiApIfaceTest, EnablePowerModeTest, TestSize.Level1)
167 {
168 HDF_LOGI("EnablePowerModeTest started");
169 if (apIface == nullptr) {
170 HDF_LOGE("iface is null");
171 return;
172 }
173 EXPECT_TRUE(apIface->EnablePowerMode(0) == HDF_ERR_NOT_SUPPORT);
174 }
175
HWTEST_F(WifiApIfaceTest, GetSupportFreqsTest, TestSize.Level1)176 HWTEST_F(WifiApIfaceTest, GetSupportFreqsTest, TestSize.Level1)
177 {
178 HDF_LOGI("GetSupportFreqsTest started");
179 if (apIface == nullptr) {
180 HDF_LOGE("iface is null");
181 return;
182 }
183 std::vector<uint32_t> freqs;
184 EXPECT_TRUE(apIface->GetSupportFreqs(0, freqs) == HDF_SUCCESS);
185 EXPECT_TRUE(apIface->SetMacAddress(TEST_MAC) == HDF_SUCCESS);
186 EXPECT_TRUE(apIface->SetCountryCode("cn") == HDF_SUCCESS);
187 EXPECT_TRUE(apIface->SetPowerMode(0) == HDF_SUCCESS);
188 int32_t mode;
189 EXPECT_TRUE(apIface->GetPowerMode(mode) == HDF_SUCCESS);
190 }
191
HWTEST_F(WifiApIfaceTest, RegisterChipIfaceCallBackTest, TestSize.Level1)192 HWTEST_F(WifiApIfaceTest, RegisterChipIfaceCallBackTest, TestSize.Level1)
193 {
194 HDF_LOGI("RegisterChipIfaceCallBackTest started");
195 if (apIface == nullptr) {
196 HDF_LOGE("iface is null");
197 return;
198 }
199 sptr<IChipIfaceCallback> ifaceCallback;
200 EXPECT_TRUE(apIface->RegisterChipIfaceCallBack(ifaceCallback) == HDF_ERR_NOT_SUPPORT);
201 EXPECT_TRUE(apIface->UnRegisterChipIfaceCallBack(ifaceCallback) == HDF_ERR_NOT_SUPPORT);
202 }
203 }