Signed-off-by: xionglei <xionglei3@huawei.com>
This commit is contained in:
xionglei 2024-11-20 06:55:05 +00:00 committed by Gitee
parent 7824d29a16
commit 7023cda192
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 439 additions and 0 deletions

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_EQ(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,131 @@
/*
* 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, 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