1 /* 2 * Copyright (C) 2021 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 "wifi_hal_chip_interface_test.h" 16 #include "securec.h" 17 #include "wifi_hal_chip_interface.h" 18 #include "wifi_hal_vendor_interface.h" 19 20 using namespace testing::ext; 21 22 namespace OHOS { 23 namespace Wifi { 24 HWTEST_F(WifiHalChipInterfaceTest, GetWifiChipTest, TestSize.Level1) 25 { 26 uint8_t id = 0; 27 WifiChip chip; 28 EXPECT_TRUE(GetWifiChip(id, NULL) == WIFI_HAL_SUCCESS); 29 EXPECT_TRUE(GetWifiChip(id, &chip) == WIFI_HAL_SUCCESS); 30 } 31 32 HWTEST_F(WifiHalChipInterfaceTest, GetWifiChipIdsTest, TestSize.Level1) 33 { 34 EXPECT_TRUE(GetWifiChipIds(NULL, NULL) == WIFI_HAL_SUCCESS); 35 uint8_t ids[32] = {0}; 36 int size = 32; 37 EXPECT_TRUE(GetWifiChipIds(ids, &size) == WIFI_HAL_SUCCESS); 38 } 39 40 HWTEST_F(WifiHalChipInterfaceTest, GetChipIdTest, TestSize.Level1) 41 { 42 EXPECT_TRUE(GetChipId(NULL) == WIFI_HAL_SUCCESS); 43 int32_t id = 0; 44 EXPECT_TRUE(GetChipId(&id) == WIFI_HAL_SUCCESS); 45 } 46 47 HWTEST_F(WifiHalChipInterfaceTest, CreateRemoveIfaceTest, TestSize.Level1) 48 { 49 EXPECT_TRUE(CreateIface(0, NULL) == WIFI_HAL_FAILED); 50 WifiIface iface; 51 ASSERT_TRUE(memset_s(&iface, sizeof(iface), 0, sizeof(iface)) == EOK); 52 EXPECT_TRUE(CreateIface(0, &iface) == WIFI_HAL_SUCCESS); 53 EXPECT_TRUE(iface.type == 0); 54 // test RemoveIface 55 EXPECT_TRUE(RemoveIface(NULL) == WIFI_HAL_FAILED); 56 } 57 58 HWTEST_F(WifiHalChipInterfaceTest, GetIfaceNamesTest, TestSize.Level1) 59 { 60 EXPECT_TRUE(GetIfaceNames(0, NULL, 0) == WIFI_HAL_SUCCESS); 61 char ifaces[128] = {0}; 62 int size = 128; 63 EXPECT_TRUE(GetIfaceNames(0, ifaces, size) == WIFI_HAL_SUCCESS); 64 } 65 66 HWTEST_F(WifiHalChipInterfaceTest, GetCapabilitiesTest, TestSize.Level1) 67 { 68 EXPECT_TRUE(GetCapabilities(NULL) == WIFI_HAL_SUCCESS); 69 uint32_t capability = 0; 70 EXPECT_TRUE(GetCapabilities(&capability) == WIFI_HAL_SUCCESS); 71 } 72 73 HWTEST_F(WifiHalChipInterfaceTest, GetSupportedComboModesTest, TestSize.Level1) 74 { 75 EXPECT_TRUE(GetSupportedComboModes(NULL, NULL) == WIFI_HAL_FAILED); 76 int32_t modes[32] = {0}; 77 int size = 32; 78 WifiErrorNo ret = GetSupportedComboModes(modes, &size); 79 EXPECT_TRUE(ret == WIFI_HAL_SUCCESS || ret == WIFI_HAL_NOT_SUPPORT); 80 } 81 82 HWTEST_F(WifiHalChipInterfaceTest, ConfigComboModesTest, TestSize.Level1) 83 { 84 EXPECT_TRUE(ConfigComboModes(0) == WIFI_HAL_NOT_SUPPORT); 85 } 86 87 HWTEST_F(WifiHalChipInterfaceTest, GetComboModesTest, TestSize.Level1) 88 { 89 EXPECT_TRUE(GetComboModes(NULL) == WIFI_HAL_FAILED); 90 int mode = 0; 91 EXPECT_TRUE(GetComboModes(&mode) == WIFI_HAL_NOT_SUPPORT); 92 } 93 94 HWTEST_F(WifiHalChipInterfaceTest, RequestFirmwareDebugDumpTest, TestSize.Level1) 95 { 96 EXPECT_TRUE(RequestFirmwareDebugDump(NULL, NULL) == WIFI_HAL_FAILED); 97 unsigned char bytes[32] = {0}; 98 int size = 32; 99 EXPECT_TRUE(RequestFirmwareDebugDump(bytes, &size) == WIFI_HAL_NOT_SUPPORT); 100 } 101 /** 102 * @tc.name: GetIsChipSupportDbdcTest 103 * @tc.desc: GetIsChipSupportDbdc() 104 * @tc.type: FUNC 105 * @tc.require: issue 106 */ 107 HWTEST_F(WifiHalChipInterfaceTest, GetIsChipSupportDbdcTest, TestSize.Level1) 108 { 109 int support = 0; 110 EXPECT_TRUE(GetIsChipSupportDbdc(NULL) == WIFI_HAL_FAILED); 111 EXPECT_TRUE(GetIsChipSupportDbdc(&support) == WIFI_HAL_SUCCESS); 112 } 113 /** 114 * @tc.name: GetIsChipSupportCsaTest 115 * @tc.desc: GetIsChipSupportCsa() 116 * @tc.type: FUNC 117 * @tc.require: issue 118 */ 119 HWTEST_F(WifiHalChipInterfaceTest, GetIsChipSupportCsaTest, TestSize.Level1) 120 { 121 int support = 0; 122 EXPECT_TRUE(GetIsChipSupportCsa(NULL) == WIFI_HAL_FAILED); 123 EXPECT_TRUE(GetIsChipSupportCsa(&support) == WIFI_HAL_SUCCESS); 124 } 125 /** 126 * @tc.name: GetIsChipSupportRadarDetectTest 127 * @tc.desc: GetIsChipSupportRadarDetect() 128 * @tc.type: FUNC 129 * @tc.require: issue 130 */ 131 HWTEST_F(WifiHalChipInterfaceTest, GetIsChipSupportRadarDetectTest, TestSize.Level1) 132 { 133 int support = 0; 134 EXPECT_TRUE(GetIsChipSupportRadarDetect(NULL) == WIFI_HAL_FAILED); 135 EXPECT_TRUE(GetIsChipSupportRadarDetect(&support) == WIFI_HAL_SUCCESS); 136 } 137 /** 138 * @tc.name: GetIsChipSupportDfsChannelTest 139 * @tc.desc: GetIsChipSupportDfsChannel() 140 * @tc.type: FUNC 141 * @tc.require: issue 142 */ 143 HWTEST_F(WifiHalChipInterfaceTest, GetIsChipSupportDfsChannelTest, TestSize.Level1) 144 { 145 int support = 0; 146 EXPECT_TRUE(GetIsChipSupportDfsChannel(NULL) == WIFI_HAL_FAILED); 147 EXPECT_TRUE(GetIsChipSupportDfsChannel(&support) == WIFI_HAL_SUCCESS); 148 } 149 /** 150 * @tc.name: GetIsChipSupportIndoorChannelTest 151 * @tc.desc: GetIsChipSupportIndoorChannel() 152 * @tc.type: FUNC 153 * @tc.require: issue 154 */ 155 HWTEST_F(WifiHalChipInterfaceTest, GetIsChipSupportIndoorChannelTest, TestSize.Level1) 156 { 157 int support = 0; 158 EXPECT_TRUE(GetIsChipSupportIndoorChannel(NULL) == WIFI_HAL_FAILED); 159 EXPECT_TRUE(GetIsChipSupportIndoorChannel(&support) == WIFI_HAL_SUCCESS); 160 } 161 /** 162 * @tc.name: GetIfaceTest 163 * @tc.desc: GetIface() 164 * @tc.type: FUNC 165 * @tc.require: issue 166 */ 167 HWTEST_F(WifiHalChipInterfaceTest, GetIfaceTest, TestSize.Level1) 168 { 169 char ifname[] = "wlan0"; 170 EXPECT_TRUE(GetIface(NULL, NULL) == WIFI_HAL_FAILED); 171 EXPECT_TRUE(GetIface(ifname, NULL) == WIFI_HAL_FAILED); 172 } 173 /** 174 * @tc.name: ConvertErrorCodeTest 175 * @tc.desc: ConvertErrorCode() 176 * @tc.type: FUNC 177 * @tc.require: issue 178 */ 179 HWTEST_F(WifiHalChipInterfaceTest, ConvertErrorCodeTest, TestSize.Level1) 180 { 181 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_SUCCESS), WIFI_HAL_SUCCESS); 182 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_UNKNOWN), WIFI_HAL_VENDOR_UNKNOWN); 183 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_UNINITIALIZED), WIFI_HAL_VENDOR_UNINITIALIZED); 184 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_NOT_SUPPORTED), WIFI_HAL_NOT_SUPPORT); 185 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_NOT_AVAILABLE), WIFI_HAL_VENDOR_NOT_AVAILABLE); 186 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_INVALID_ARGS), WIFI_HAL_VENDOR_INVALID_ARGS); 187 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_INVALID_REQUEST_ID), 188 WIFI_HAL_VENDOR_INVALID_REQUEST_ID); 189 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_TIMED_OUT), WIFI_HAL_VENDOR_TIMED_OUT); 190 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_TOO_MANY_REQUESTS), WIFI_HAL_VENDOR_TOO_MANY_REQUESTS); 191 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_OUT_OF_MEMORY), WIFI_HAL_VENDOR_OUT_OF_MEMORY); 192 EXPECT_EQ(ConvertErrorCode(HalVendorError::HAL_VENDOR_ERROR_BUSY), WIFI_HAL_VENDOR_BUSY); 193 } 194 /** 195 * @tc.name: InitDefaultHalVendorFuncTest 196 * @tc.desc: InitDefaultHalVendorFunc() 197 * @tc.type: FUNC 198 * @tc.require: issue 199 */ 200 HWTEST_F(WifiHalChipInterfaceTest, InitDefaultHalVendorFuncTest, TestSize.Level1) 201 { 202 EXPECT_TRUE(InitDefaultHalVendorFunc(NULL) == HAL_VENDOR_ERROR_UNKNOWN); 203 } 204 } // namespace Wifi 205 } // namespace OHOS