!3343 【TDD】wifi仓新增用例

Merge pull request !3343 from xionglei/master
This commit is contained in:
openharmony_ci 2024-11-20 02:26:15 +00:00 committed by Gitee
commit 0164f0f35f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 1106 additions and 1 deletions

View File

@ -33,6 +33,7 @@ group("unittest") {
"wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_selfcure_unittest",
"wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_unittest",
"wifi_standard/wifi_framework/wifi_manage/wifi_sta_new:wifi_sta_new_unittest",
"wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage:wifi_sub_manage_unittest",
"wifi_standard/wifi_framework/wifi_toolkit/unittest:toolkit_unittest",
"wifi_standard/wifi_hal/unittest:wifi_hal_unittest",
"wifi_utils/unittest:utils_unittest",

View File

@ -204,6 +204,7 @@ public:
virtual void MergeWifiCloneConfig(std::string &cloneData) = 0;
virtual bool GetScanAlwaysState(int instId) = 0;
virtual bool GetSupportHwPnoFlag(int instId = 0) = 0;
virtual int SetAcceptUnvalidated(int networkId) = 0;
};
class WifiSettings : public MockWifiSettings {
@ -376,6 +377,7 @@ public:
MOCK_METHOD1(MergeWifiCloneConfig, void(std::string &cloneData));
MOCK_METHOD1(GetScanAlwaysState, bool(int instId));
MOCK_METHOD1(GetSupportHwPnoFlag, bool(int instId));
MOCK_METHOD1(SetAcceptUnvalidated, int(int networkId));
};
} // namespace Wifi
} // namespace OHOS

View File

@ -54,6 +54,9 @@ public:
virtual void DealStoreScanInfoEvent(std::vector<InterScanInfo> &results, int instId = 0) = 0;
virtual void PushServiceCloseMsg(WifiCloseServiceCode code, int instId = 0);
virtual void AutoStartEnhanceService(void) = 0;
#ifdef FEATURE_HPF_SUPPORT
virtual void InstallPacketFilterProgram(int event = 0, int instId = 0) = 0;
#endif
};
class WifiManager : public MockWifiManager {
@ -70,6 +73,9 @@ public:
MOCK_METHOD2(DealStoreScanInfoEvent, void(std::vector<InterScanInfo> &results, int));
MOCK_METHOD2(PushServiceCloseMsg, void(WifiCloseServiceCode, int));
MOCK_METHOD0(AutoStartEnhanceService, void());
#ifdef FEATURE_HPF_SUPPORT
MOCK_METHOD2(InstallPacketFilterProgram, void(int event, int instId));
#endif
std::unique_ptr<WifiStaManager>& GetWifiStaManager();
std::unique_ptr<WifiScanManager>& GetWifiScanManager();
std::unique_ptr<WifiTogglerManager>& GetWifiTogglerManager();

View File

@ -0,0 +1,183 @@
# Copyright (C) 2024-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/communication/wifi/wifi/wifi.gni")
module_output_path = "wifi/wifi_sub_manage_unittest"
defines = []
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [ "$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage" ]
}
ohos_unittest("wifi_sub_manage_unittest") {
module_out_path = module_output_path
sources = [
"$WIFI_ROOT_DIR/frameworks/native/src/wifi_p2p_msg.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit/app_network_speed_limit_service.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit/speed_limit_configs_writer.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_app_state_aware.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_auth_center.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code/wifi_country_code_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code/wifi_country_code_policy.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_datashare_utils.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_internal_event_dispatcher.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_agent.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_net_observer.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_netlink.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_notification_util.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_permission_helper.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_permission_utils.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_protect.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_protect_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_system_ability_listerner.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_system_timer.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_clientmode_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_service_scheduler.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure/ip_qos_monitor.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_common_service_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_hotspot_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_location_mode_observer.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_p2p_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_scan_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_sta_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_toggler_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/base_address.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/ip_tools.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/ipv6_address.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/mac_address.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_common_event_helper.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/unittest/Mock/mock_wifi_settings.cpp",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_wifi_manager.cpp",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock/mock_wifi_config_center.cpp",
"wifi_scan_manager_test.cpp",
"wifi_sta_manager_test.cpp",
"wifi_toggler_manager_test.cpp",
]
if (defined(global_parts_info) && defined(global_parts_info.msdp_movement)) {
sources += [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_msdp_state_listener.cpp",
"wifi_msdp_state_listener_test.cpp",
]
}
include_dirs = [
"$WIFI_ROOT_DIR/utils/inc",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock",
"$WIFI_ROOT_DIR/base/utils",
"$WIFI_ROOT_DIR/interfaces/inner_api",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/include",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/hal_device_manage",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/idl_interface",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa",
"$WIFI_ROOT_DIR/services/wifi_standard/include",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/wifi_asset",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/unittest/Mock",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock",
]
deps = [
"$WIFI_ROOT_DIR/base:wifi_base",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:app_manager",
"ability_runtime:extension_manager",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"cellular_data:tel_cellular_data_api",
"core_service:tel_core_service_api",
"data_share:datashare_consumer",
"dhcp:dhcp_sdk",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"jsoncpp:jsoncpp",
"libxml2:libxml2",
"netmanager_base:net_conn_manager_if",
"netmanager_base:net_native_manager_if",
"netmanager_base:net_stats_manager_if",
"power_manager:powermgr_client",
"samgr:samgr_proxy",
"time_service:time_client",
]
ldflags = [
"-fPIC",
"--coverage",
"-Wl,-E",
]
defines += [
"private=public",
"FEATURE_AP_SUPPORT",
"FEATURE_STA_SUPPORT",
"STA_INSTANCE_MAX_NUM=$wifi_feature_with_sta_num",
"AP_INSTANCE_MAX_NUM=$wifi_feature_with_ap_num",
"FEATURE_SELF_CURE_SUPPORT",
"SUPPORT_RANDOM_MAC_ADDR",
]
if (defined(global_parts_info) && defined(global_parts_info.msdp_movement)) {
external_deps += [ "movement:movement_client" ]
defines += [ "HAS_MOVEMENT_PART" ]
}
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <string>
#include <vector>
#include "wifi_msdp_state_listener.h"
#include "wifi_logger.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "mock_wifi_manager.h"
#include "mock_wifi_config_center.h"
#include "mock_wifi_settings.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
namespace OHOS {
namespace Wifi {
class DeviceMovementCallbackTest : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
virtual void SetUp()
{
deviceMovementCallback_ = std::make_unique<DeviceMovementCallback>();
}
virtual void TearDown()
{
deviceMovementCallback_.reset();
}
std::unique_ptr<DeviceMovementCallback> deviceMovementCallback_;
};
HWTEST_F(DeviceMovementCallbackTest, DealMultiStaStopTest01, TestSize.Level1)
{
Msdp::MovementDataUtils::MovementData movementData;
movementData.type = Msdp::MovementDataUtils::MovementType::TYPE_STILL;
movementData.value = Msdp::MovementDataUtils::MovementValue::VALUE_ENTER;
deviceMovementCallback_->OnMovementChanged(movementData);
EXPECT_NE(deviceMovementCallback_->movementChangeEventHandler, nullptr);
movementData.value = Msdp::MovementDataUtils::MovementValue::VALUE_INVALID;
deviceMovementCallback_->OnMovementChanged(movementData);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,138 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <string>
#include <vector>
#include "wifi_scan_manager.h"
#include "wifi_logger.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "mock_wifi_manager.h"
#include "mock_wifi_config_center.h"
#include "mock_wifi_settings.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
namespace OHOS {
namespace Wifi {
constexpr int TEN = 10;
class WifiScanManagerTest : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
virtual void SetUp()
{
wifiScanManager_ = std::make_unique<WifiScanManager>();
wifiScanManager_->InitScanCallback();
}
virtual void TearDown()
{
wifiScanManager_.reset();
}
std::unique_ptr<WifiScanManager> wifiScanManager_;
};
HWTEST_F(WifiScanManagerTest, GetScanCallbackTest01, TestSize.Level1)
{
wifiScanManager_->GetScanCallback();
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, GetStaCallbackTest01, TestSize.Level1)
{
wifiScanManager_->GetStaCallback();
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
#ifndef OHOS_ARCH_LITE
HWTEST_F(WifiScanManagerTest, StopUnloadScanSaTimerTest01, TestSize.Level1)
{
wifiScanManager_->unloadScanSaTimerId = 1;
wifiScanManager_->StopUnloadScanSaTimer();
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
#endif
HWTEST_F(WifiScanManagerTest, TryToStartScanServiceTest01, TestSize.Level1)
{
int instId = 1;
EXPECT_NE(wifiScanManager_->TryToStartScanService(instId), WIFI_OPT_FAILED);
}
HWTEST_F(WifiScanManagerTest, CheckAndStopScanServiceTest01, TestSize.Level1)
{
int instId = 1;
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetScanMidState(_)).WillRepeatedly(Return(WifiOprMidState::OPENING));
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetAirplaneModeState()).WillRepeatedly(Return(MODE_STATE_OPEN));
wifiScanManager_->CheckAndStopScanService(instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, CloseScanServiceTest01, TestSize.Level1)
{
int instId = 1;
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetScanMidState(_)).WillRepeatedly(Return(WifiOprMidState::OPENING));
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetWifiMidState(_)).WillRepeatedly(Return(WifiOprMidState::OPENING));
wifiScanManager_->CloseScanService(instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, DealScanOpenResTest01, TestSize.Level1)
{
int instId = 1;
wifiScanManager_->DealScanOpenRes(instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, DealScanCloseResTest01, TestSize.Level1)
{
int instId = 1;
wifiScanManager_->DealScanCloseRes(instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, DealStoreScanInfoEventTest01, TestSize.Level1)
{
std::vector<InterScanInfo> results;
int instId = 1;
wifiScanManager_->DealStoreScanInfoEvent(results, instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
HWTEST_F(WifiScanManagerTest, DealStaOpenedTest01, TestSize.Level1)
{
int instId = 1;
wifiScanManager_->DealStaOpened(instId);
EXPECT_NE(wifiScanManager_->unloadScanSaTimerId, TEN);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <string>
#include <vector>
#include "wifi_sta_manager.h"
#include "wifi_logger.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "mock_wifi_manager.h"
#include "mock_wifi_config_center.h"
#include "mock_wifi_settings.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
namespace OHOS {
namespace Wifi {
constexpr int TEN = 10;
class WifiStaManagerTest : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
virtual void SetUp()
{
wifiStaManager_ = std::make_unique<WifiStaManager>();
wifiStaManager_->InitStaCallback();
}
virtual void TearDown()
{
wifiStaManager_.reset();
}
std::unique_ptr<WifiStaManager> wifiStaManager_;
};
HWTEST_F(WifiStaManagerTest, GetStaCallbackTest01, TestSize.Level1)
{
wifiStaManager_->GetStaCallback();
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
#ifndef OHOS_ARCH_LITE
HWTEST_F(WifiStaManagerTest, StartUnloadStaSaTimerTest01, TestSize.Level1)
{
wifiStaManager_->unloadStaSaTimerId = 0;
wifiStaManager_->StartUnloadStaSaTimer();
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, StopUnloadStaSaTimerTest01, TestSize.Level1)
{
wifiStaManager_->unloadStaSaTimerId = 1;
wifiStaManager_->StopUnloadStaSaTimer();
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
#endif
HWTEST_F(WifiStaManagerTest, CloseStaServiceTest01, TestSize.Level1)
{
int instId = 1;
wifiStaManager_->CloseStaService(instId);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, DealStaOpenedTest01, TestSize.Level1)
{
int instId = 1;
wifiStaManager_->DealStaOpened(instId);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, PublishWifiOperateStateHiSysEventTest01, TestSize.Level1)
{
OperateResState state = OperateResState::CONNECT_ASSOCIATING;
wifiStaManager_->PublishWifiOperateStateHiSysEvent(state);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, PublishWifiOperateStateHiSysEventTest02, TestSize.Level1)
{
OperateResState state = OperateResState::CONNECT_ASSOCIATED;
wifiStaManager_->PublishWifiOperateStateHiSysEvent(state);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, PublishWifiOperateStateHiSysEventTest03, TestSize.Level1)
{
OperateResState state = OperateResState::CONNECT_CONNECTION_FULL;
wifiStaManager_->PublishWifiOperateStateHiSysEvent(state);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, PublishWifiOperateStateHiSysEventTest04, TestSize.Level1)
{
OperateResState state = OperateResState::CONNECT_OBTAINING_IP;
wifiStaManager_->PublishWifiOperateStateHiSysEvent(state);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, PublishWifiOperateStateHiSysEventTest05, TestSize.Level1)
{
OperateResState state = OperateResState::DISCONNECT_DISCONNECTING;
wifiStaManager_->PublishWifiOperateStateHiSysEvent(state);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, IgnoreConnStateChangeTest01, TestSize.Level1)
{
WifiLinkedInfo info;
int instId = 1;
wifiStaManager_->IgnoreConnStateChange(info, instId);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, DealStaConnChangedTest01, TestSize.Level1)
{
OperateResState state = OperateResState::CONNECT_AP_CONNECTED;
WifiLinkedInfo info;
info.connState = ConnState::AUTHENTICATING;
int instId = 1;
wifiStaManager_->DealStaConnChanged(state, info, instId);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
HWTEST_F(WifiStaManagerTest, DealAutoSelectNetworkChangedTest01, TestSize.Level1)
{
int networkId = 1;
int instId = 1;
wifiStaManager_->DealAutoSelectNetworkChanged(networkId, instId);
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
#ifndef OHOS_ARCH_LITE
HWTEST_F(WifiStaManagerTest, StopSatelliteTimerTest01, TestSize.Level1)
{
wifiStaManager_->satelliteTimerId = 1;
wifiStaManager_->StopSatelliteTimer();
EXPECT_NE(wifiStaManager_->unloadStaSaTimerId, TEN);
}
#endif
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,138 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <string>
#include <vector>
#include "wifi_toggler_manager.h"
#include "wifi_logger.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "mock_wifi_manager.h"
#include "mock_wifi_config_center.h"
#include "mock_wifi_settings.h"
using ::testing::_;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
namespace OHOS {
namespace Wifi {
class WifiTogglerManagerTest : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
virtual void SetUp()
{
wifiTogglerManager_ = std::make_unique<WifiTogglerManager>();
}
virtual void TearDown()
{
wifiTogglerManager_.reset();
}
std::unique_ptr<WifiTogglerManager> wifiTogglerManager_;
};
HWTEST_F(WifiTogglerManagerTest, SoftapToggledTest01, TestSize.Level1)
{
int isOpen = 1;
int id = 1;
EXPECT_EQ(wifiTogglerManager_->SoftapToggled(isOpen, id), WIFI_OPT_SUCCESS);
}
HWTEST_F(WifiTogglerManagerTest, SoftapToggledTest02, TestSize.Level1)
{
int isOpen = 0;
int id = 1;
EXPECT_EQ(wifiTogglerManager_->SoftapToggled(isOpen, id), WIFI_OPT_SUCCESS);
}
HWTEST_F(WifiTogglerManagerTest, ScanOnlyToggledTest01, TestSize.Level1)
{
int isOpen = 0;
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetAirplaneModeState()).WillRepeatedly(Return(MODE_STATE_OPEN));
EXPECT_EQ(wifiTogglerManager_->ScanOnlyToggled(isOpen), WIFI_OPT_FAILED);
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetAirplaneModeState()).WillRepeatedly(Return(MODE_STATE_CLOSE));
EXPECT_EQ(wifiTogglerManager_->ScanOnlyToggled(isOpen), WIFI_OPT_SUCCESS);
}
HWTEST_F(WifiTogglerManagerTest, AirplaneToggledTest01, TestSize.Level1)
{
int isOpen = 1;
EXPECT_EQ(wifiTogglerManager_->AirplaneToggled(isOpen), WIFI_OPT_SUCCESS);
}
HWTEST_F(WifiTogglerManagerTest, GetControllerMachineTest01, TestSize.Level1)
{
EXPECT_NE(wifiTogglerManager_->GetControllerMachine(), nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealConcreateStopTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealConcreateStop(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealRptStopTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealRptStop(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealRptStartFailureTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealRptStartFailure(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealClientRemovedTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealClientRemoved(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealMultiStaStartFailureTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealMultiStaStartFailure(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
HWTEST_F(WifiTogglerManagerTest, DealMultiStaStopTest01, TestSize.Level1)
{
int id = 1;
wifiTogglerManager_->DealMultiStaStop(id);
EXPECT_NE(wifiTogglerManager_->pWifiControllerMachine, nullptr);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -152,6 +152,8 @@ public:
const std::string &randomAddr) = 0;
virtual std::string GetP2pIfaceName() = 0;
virtual int GetScanGenieState() const = 0;
virtual int Init() = 0;
virtual void SetFreezeModeState(int state) = 0;
};
class WifiConfigCenter : public MockWifiConfigCenter {
@ -284,6 +286,8 @@ public:
const std::string &randomAddr));
MOCK_METHOD0(GetP2pIfaceName, std::string());
MOCK_CONST_METHOD0(GetScanGenieState, int());
MOCK_METHOD0(Init, int());
MOCK_METHOD1(SetFreezeModeState, void(int state));
private:
WifiConfigCenter();
std::unique_ptr<WifiScanConfig> wifiScanConfig = nullptr;

View File

@ -88,6 +88,47 @@ HWTEST_F(WifiAssetManagerTest, TestWifiAssetUpdatePack, testing::ext::TestSize.L
int32_t userId = USER_ID_DEFAULT;
WifiAssetManager::GetInstance().WifiAssetUpdatePack(mWifiDeviceConfig, userId);
}
HWTEST_F(WifiAssetManagerTest, InitUpLoadLocalDeviceSyncTest01, testing::ext::TestSize.Level1)
{
WifiAssetManager::GetInstance().InitUpLoadLocalDeviceSync();
EXPECT_NE(WifiAssetManager::GetInstance().assetServiceThread_, nullptr);
}
HWTEST_F(WifiAssetManagerTest, CloudAssetSyncTest01, testing::ext::TestSize.Level1)
{
WifiAssetManager::GetInstance().CloudAssetSync();
EXPECT_NE(WifiAssetManager::GetInstance().assetServiceThread_, nullptr);
}
HWTEST_F(WifiAssetManagerTest, WifiAssetRemovePackTest01, testing::ext::TestSize.Level1)
{
std::vector<WifiDeviceConfig> mWifiDeviceConfig;
WifiDeviceConfig wifiDeviceConfig;
wifiDeviceConfig.bssidType = 1;
mWifiDeviceConfig.push_back(wifiDeviceConfig);
int32_t userId = USER_ID_DEFAULT;
bool flagSync = true;
WifiAssetManager::GetInstance().WifiAssetRemovePack(mWifiDeviceConfig, userId, flagSync);
EXPECT_NE(WifiAssetManager::GetInstance().assetServiceThread_, nullptr);
}
HWTEST_F(WifiAssetManagerTest, IsWifiConfigUpdatedTest01, testing::ext::TestSize.Level1)
{
std::vector<WifiDeviceConfig> newWifiDeviceConfigs;
WifiDeviceConfig config;
config.uid = 1;
config.keyMgmt = KEY_MGMT_WAPI;
config.ssid = "TEST";
WifiDeviceConfig config1;
config1.ssid = "TEST";
newWifiDeviceConfigs.push_back(config1);
WifiAssetManager::GetInstance().IsWifiConfigUpdated(newWifiDeviceConfigs, config);
EXPECT_NE(WifiAssetManager::GetInstance().assetServiceThread_, nullptr);
}
#endif
} // namespace Wifi
} // namespace OHOS

View File

@ -22,6 +22,8 @@ using namespace testing::ext;
namespace OHOS {
namespace Wifi {
constexpr int TEN = 10;
HWTEST_F(WifiConfigCenterTest, SetGetWifiMidState_SUCCESS, TestSize.Level1)
{
WifiOprMidState state = OHOS::Wifi::WifiOprMidState::RUNNING;
@ -53,5 +55,349 @@ HWTEST_F(WifiConfigCenterTest, GetWifiStaIntervalTest, TestSize.Level1)
EXPECT_TRUE(interval >= 1000 && interval <= 2000);
}
HWTEST_F(WifiConfigCenterTest, GetWifiAllowSemiActiveTest01, TestSize.Level1)
{
EXPECT_EQ(WifiConfigCenter::GetInstance().GetWifiAllowSemiActive(), false);
}
HWTEST_F(WifiConfigCenterTest, GetWifiStateTest01, TestSize.Level1)
{
int state = 0;
int instId = 1;
WifiConfigCenter::GetInstance().SetWifiState(state, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetWifiState(state), 1);
}
HWTEST_F(WifiConfigCenterTest, GetWifiDetailStateTest01, TestSize.Level1)
{
int instId = 1;
WifiDetailState state = WifiDetailState::STATE_UNKNOWN;
WifiConfigCenter::GetInstance().SetWifiDetailState(state, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetWifiDetailState(instId), WifiDetailState::STATE_UNKNOWN);
}
HWTEST_F(WifiConfigCenterTest, GetIpInfoTest01, TestSize.Level1)
{
int instId = 1;
IpInfo info;
WifiConfigCenter::GetInstance().SaveIpInfo(info, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetIpInfo(info, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, GetIpv6InfoTest01, TestSize.Level1)
{
int instId = 1;
IpV6Info info;
WifiConfigCenter::GetInstance().SaveIpV6Info(info, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetIpv6Info(info, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, GetLinkedInfoTest01, TestSize.Level1)
{
int instId = 1;
WifiLinkedInfo info;
WifiLinkedInfo info1;
info.channelWidth = WifiChannelWidth::WIDTH_40MHZ;
info.bssid = "TEST";
WifiConfigCenter::GetInstance().SaveLinkedInfo(info, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetLinkedInfo(info1, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, GetMacAddressTest01, TestSize.Level1)
{
std::string macAddress = "TEST";
std::string macAddress1;
int instId = 1;
WifiConfigCenter::GetInstance().SetMacAddress(macAddress, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetMacAddress(macAddress1, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, GetUserLastSelectedNetworkIdTest01, TestSize.Level1)
{
int instId = 1;
int networkId = 1;
WifiConfigCenter::GetInstance().SetUserLastSelectedNetworkId(networkId, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetUserLastSelectedNetworkId(instId), 1);
}
HWTEST_F(WifiConfigCenterTest, GetUserLastSelectedNetworkTimeValTest01, TestSize.Level1)
{
int instId = 1;
int networkId = 1;
WifiConfigCenter::GetInstance().SetUserLastSelectedNetworkId(networkId, instId);
EXPECT_NE(WifiConfigCenter::GetInstance().GetUserLastSelectedNetworkTimeVal(instId), 0);
}
HWTEST_F(WifiConfigCenterTest, SetConnectTimeoutBssidTest01, TestSize.Level1)
{
std::string bssid = "TEST";
int instId = 1;
EXPECT_EQ(WifiConfigCenter::GetInstance().SetConnectTimeoutBssid(bssid, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, GetDisconnectedReasonTest01, TestSize.Level1)
{
DisconnectedReason discReason = DisconnectedReason::DISC_REASON_DEFAULT;
int instId = 1;
WifiConfigCenter::GetInstance().SaveDisconnectedReason(discReason, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetDisconnectedReason(discReason, instId), 0);
}
HWTEST_F(WifiConfigCenterTest, InsertWifiCategoryBlackListCacheTest01, TestSize.Level1)
{
int blacklistType = 1;
std::string currentBssid = "TEST";
WifiCategoryBlackListInfo wifiBlackListInfo;
WifiConfigCenter::GetInstance().InsertWifiCategoryBlackListCache(blacklistType, currentBssid, wifiBlackListInfo);
WifiConfigCenter::GetInstance().RemoveWifiCategoryBlackListCache(blacklistType, currentBssid);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, GetWifiCategoryBlackListCacheTest01, TestSize.Level1)
{
int blacklistType = 0;
std::map<std::string, WifiCategoryBlackListInfo> blackListCache;
EXPECT_NE(WifiConfigCenter::GetInstance().GetWifiCategoryBlackListCache(blacklistType, blackListCache), 0);
}
HWTEST_F(WifiConfigCenterTest, UpdateWifiConnectFailListCacheTest01, TestSize.Level1)
{
int blacklistType = 0;
std::string bssid = "TEST";
WifiCategoryConnectFailInfo wifiConnectFailInfo;
std::map<std::string, WifiCategoryBlackListInfo> blackListCache;
WifiConfigCenter::GetInstance().UpdateWifiConnectFailListCache(blacklistType, bssid, wifiConnectFailInfo);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, RemoveWifiConnectFailListCacheTest01, TestSize.Level1)
{
std::string bssid = "TEST";
WifiConfigCenter::GetInstance().RemoveWifiConnectFailListCache(bssid);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, EnableNetworkTest01, TestSize.Level1)
{
int networkId = 1;
bool disableOthers = true;
int instId = 1;
EXPECT_EQ(WifiConfigCenter::GetInstance().EnableNetwork(networkId, disableOthers, instId), true);
}
HWTEST_F(WifiConfigCenterTest, GetScanMidStateTest01, TestSize.Level1)
{
WifiOprMidState expState = OHOS::Wifi::WifiOprMidState::CLOSED;
WifiOprMidState state = OHOS::Wifi::WifiOprMidState::CLOSED;
int instId = 1;
WifiConfigCenter::GetInstance().SetScanMidState(expState, state, instId);
WifiConfigCenter::GetInstance().SetScanMidState(state, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetScanMidState(instId), OHOS::Wifi::WifiOprMidState::CLOSED);
}
HWTEST_F(WifiConfigCenterTest, GetWifiScanOnlyMidStateTest01, TestSize.Level1)
{
WifiOprMidState expState = OHOS::Wifi::WifiOprMidState::CLOSED;
WifiOprMidState state = OHOS::Wifi::WifiOprMidState::CLOSED;
int instId = 1;
WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(expState, state, instId);
WifiConfigCenter::GetInstance().SetWifiScanOnlyMidState(state, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetWifiScanOnlyMidState(instId), OHOS::Wifi::WifiOprMidState::CLOSED);
}
HWTEST_F(WifiConfigCenterTest, SetWifiLinkedStandardAndMaxSpeedTest01, TestSize.Level1)
{
WifiLinkedInfo linkInfo;
linkInfo.bssid = "TEST";
EXPECT_EQ(WifiConfigCenter::GetInstance().SetWifiLinkedStandardAndMaxSpeed(linkInfo), 0);
}
HWTEST_F(WifiConfigCenterTest, GetConnectedBssidTest01, TestSize.Level1)
{
int instId = 1;
EXPECT_EQ(WifiConfigCenter::GetInstance().GetConnectedBssid(instId), "");
}
HWTEST_F(WifiConfigCenterTest, GetApMidStateTest01, TestSize.Level1)
{
WifiOprMidState expState = OHOS::Wifi::WifiOprMidState::CLOSED;
WifiOprMidState state = OHOS::Wifi::WifiOprMidState::CLOSED;
int id = 1;
WifiConfigCenter::GetInstance().SetApMidState(expState, state, id);
WifiConfigCenter::GetInstance().SetApMidState(state, id);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetApMidState(id), OHOS::Wifi::WifiOprMidState::CLOSED);
}
HWTEST_F(WifiConfigCenterTest, GetHotspotStateTest01, TestSize.Level1)
{
int state = 1;
int id = 1;
WifiConfigCenter::GetInstance().SetHotspotState(state, id);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetHotspotState(id), 1);
}
HWTEST_F(WifiConfigCenterTest, GetPowerModelTest01, TestSize.Level1)
{
PowerModel model = PowerModel::GENERAL;
int id = 1;
WifiConfigCenter::GetInstance().SetPowerModel(model, id);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetPowerModel(model, id), 0);
}
HWTEST_F(WifiConfigCenterTest, GetStationListTest01, TestSize.Level1)
{
std::vector<StationInfo> results;
int id = 1;
EXPECT_EQ(WifiConfigCenter::GetInstance().GetStationList(results, id), 0);
}
HWTEST_F(WifiConfigCenterTest, ManageStationTest01, TestSize.Level1)
{
StationInfo info;
info.bssid = "TEST";
int mode = MODE_ADD;
int id = 1;
EXPECT_EQ(WifiConfigCenter::GetInstance().ManageStation(info, mode, id), 0);
mode = MODE_DEL;
EXPECT_EQ(WifiConfigCenter::GetInstance().ManageStation(info, mode, id), 0);
mode = 3;
EXPECT_EQ(WifiConfigCenter::GetInstance().ManageStation(info, mode, id), -1);
}
HWTEST_F(WifiConfigCenterTest, GetHid2dUpperSceneTest01, TestSize.Level1)
{
int uid = 1;
Hid2dUpperScene scene;
WifiConfigCenter::GetInstance().SetHid2dUpperScene(uid, scene);
EXPECT_EQ(WifiConfigCenter::GetInstance().GetHid2dUpperScene(uid, scene), 0);
}
HWTEST_F(WifiConfigCenterTest, ClearLocalHid2dInfoTest01, TestSize.Level1)
{
int uid = 1;
WifiConfigCenter::GetInstance().ClearLocalHid2dInfo(uid);
uid = 0;
WifiConfigCenter::GetInstance().ClearLocalHid2dInfo(uid);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, SetWifiStateOnAirplaneChangedTest01, TestSize.Level1)
{
int state = MODE_STATE_OPEN;
WifiConfigCenter::GetInstance().SetWifiStateOnAirplaneChanged(state);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, GetWifiToggledEnableTest01, TestSize.Level1)
{
int id = 1;
WifiConfigCenter::GetInstance().GetWifiToggledEnable(id);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, SetWifiToggledStateTest01, TestSize.Level1)
{
int state = 1;
int id = 1;
WifiConfigCenter::GetInstance().SetWifiToggledState(state, id);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, SetThreadStatusFlagTest01, TestSize.Level1)
{
bool state = true;
WifiConfigCenter::GetInstance().SetThreadStatusFlag(state);
WifiConfigCenter::GetInstance().SetThreadStatusFlag(false);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, RemoveMacAddrPairsTest01, TestSize.Level1)
{
WifiMacAddrInfoType type = WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO;
WifiMacAddrInfo macAddrInfo;
EXPECT_EQ(WifiConfigCenter::GetInstance().RemoveMacAddrPairs(type, macAddrInfo), 0);
type = WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO;
EXPECT_EQ(WifiConfigCenter::GetInstance().RemoveMacAddrPairs(type, macAddrInfo), 0);
type = WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO;
EXPECT_EQ(WifiConfigCenter::GetInstance().RemoveMacAddrPairs(type, macAddrInfo), 0);
type = WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO;
EXPECT_EQ(WifiConfigCenter::GetInstance().RemoveMacAddrPairs(type, macAddrInfo), 0);
type = WifiMacAddrInfoType::INVALID_MACADDR_INFO;
EXPECT_EQ(WifiConfigCenter::GetInstance().RemoveMacAddrPairs(type, macAddrInfo), -1);
}
HWTEST_F(WifiConfigCenterTest, GetMacAddrPairsTest01, TestSize.Level1)
{
WifiMacAddrInfoType type = WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO;
WifiMacAddrInfo macAddrInfo;
EXPECT_NE(WifiConfigCenter::GetInstance().GetMacAddrPairs(type, macAddrInfo), "test");
type = WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO;
EXPECT_NE(WifiConfigCenter::GetInstance().GetMacAddrPairs(type, macAddrInfo), "test");
type = WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO;
EXPECT_NE(WifiConfigCenter::GetInstance().GetMacAddrPairs(type, macAddrInfo), "test");
type = WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO;
EXPECT_NE(WifiConfigCenter::GetInstance().GetMacAddrPairs(type, macAddrInfo), "test");
type = WifiMacAddrInfoType::INVALID_MACADDR_INFO;
EXPECT_NE(WifiConfigCenter::GetInstance().GetMacAddrPairs(type, macAddrInfo), "test");
}
HWTEST_F(WifiConfigCenterTest, ClearMacAddrPairsTest01, TestSize.Level1)
{
WifiMacAddrInfoType type = WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO;
WifiConfigCenter::GetInstance().ClearMacAddrPairs(type);
type = WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO;
WifiConfigCenter::GetInstance().ClearMacAddrPairs(type);
type = WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO;
WifiConfigCenter::GetInstance().ClearMacAddrPairs(type);
type = WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO;
WifiConfigCenter::GetInstance().ClearMacAddrPairs(type);
type = WifiMacAddrInfoType::INVALID_MACADDR_INFO;
WifiConfigCenter::GetInstance().ClearMacAddrPairs(type);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, HasWifiActiveTest01, TestSize.Level1)
{
int state = 2;
int instId = 1;
WifiConfigCenter::GetInstance().SetWifiState(state, instId);
EXPECT_EQ(WifiConfigCenter::GetInstance().HasWifiActive(), true);
}
HWTEST_F(WifiConfigCenterTest, UpdateLinkedInfoTest01, TestSize.Level1)
{
int instId = 1;
WifiConfigCenter::GetInstance().UpdateLinkedInfo(instId);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, SetPersistWifiStateTest01, TestSize.Level1)
{
int state = 1;
int instId = 1;
WifiConfigCenter::GetInstance().SetPersistWifiState(state, instId);
EXPECT_NE(WifiConfigCenter::GetInstance().mWifiIpV6Info.size(), TEN);
}
HWTEST_F(WifiConfigCenterTest, GetPersistWifiStateTest01, TestSize.Level1)
{
int instId = 3;
EXPECT_EQ(WifiConfigCenter::GetInstance().GetPersistWifiState(instId), -1);
instId = 1;
EXPECT_NE(WifiConfigCenter::GetInstance().GetPersistWifiState(instId), -1);
}
HWTEST_F(WifiConfigCenterTest, AddMacAddrPairsTest01, TestSize.Level1)
{
WifiMacAddrInfoType type = WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO;
WifiMacAddrInfo macAddrInfo;
macAddrInfo.bssid = "TEST";
std::string randomMacAddr = "TEST";
EXPECT_EQ(WifiConfigCenter::GetInstance().AddMacAddrPairs(type, macAddrInfo, randomMacAddr), 0);
type = WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO;
EXPECT_EQ(WifiConfigCenter::GetInstance().AddMacAddrPairs(type, macAddrInfo, randomMacAddr), 0);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -26,7 +26,9 @@ public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
virtual void SetUp()
{}
{
WifiConfigCenter::GetInstance().Init();
}
virtual void TearDown()
{}
};