• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <securec.h>
17 
18 #include "bus_center_client_proxy.h"
19 #include "common_event_data.h"
20 #include "lnn_wifiservice_monitor.cpp"
21 #include "lnn_wifiservice_monitor_mock.cpp"
22 #include "softbus_error_code.h"
23 #include "softbus_wifi_api_adapter.h"
24 #include "gtest/gtest.h"
25 
26 namespace OHOS {
27 using namespace testing;
28 using namespace testing::ext;
29 bool g_subscribeCommonEventRet = false;
30 namespace EventFwk {
SubscribeCommonEvent(const std::shared_ptr<EventFwk::CommonEventSubscriber> & subscriber)31 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<EventFwk::CommonEventSubscriber> &subscriber)
32 {
33     return g_subscribeCommonEventRet;
34 }
35 } // namespace EventFwk
36 
37 class LnnWifiServiceMonitorTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase()45 void LnnWifiServiceMonitorTest::SetUpTestCase() { }
46 
TearDownTestCase()47 void LnnWifiServiceMonitorTest::TearDownTestCase() { }
48 
SetUp()49 void LnnWifiServiceMonitorTest::SetUp() { }
50 
TearDown()51 void LnnWifiServiceMonitorTest::TearDown() { }
52 
53 /**
54  * @tc.name: LNN_WIFISERVICE_MONITOR_SetSoftBusWifiConnState_001
55  * @tc.desc: Verify the SetSoftBusWifiConnState function return value equal SOFTBUS_WIFI_UNKNOWN.
56  * @tc.type: FUNC
57  * @tc.require: 1
58  */
59 HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiConnState_001, TestSize.Level1)
60 {
61     SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
62 
63     EventFwk::SetSoftBusWifiConnState((int)OHOS::Wifi::ConnState::OBTAINING_IPADDR, &state);
64     EXPECT_EQ(state, SOFTBUS_WIFI_OBTAINING_IPADDR);
65 
66     EventFwk::SetSoftBusWifiConnState((int)OHOS::Wifi::ConnState::CONNECTED, &state);
67     EXPECT_EQ(state, SOFTBUS_WIFI_CONNECTED);
68 
69     EventFwk::SetSoftBusWifiConnState((int)OHOS::Wifi::ConnState::DISCONNECTED, &state);
70     EXPECT_EQ(state, SOFTBUS_WIFI_DISCONNECTED);
71 
72     state = SOFTBUS_WIFI_UNKNOWN;
73     EventFwk::SetSoftBusWifiConnState((int)OHOS::Wifi::ConnState::UNKNOWN, &state);
74     EXPECT_EQ(state, SOFTBUS_WIFI_UNKNOWN);
75 }
76 
77 /**
78  * @tc.name: LNN_WIFISERVICE_MONITOR_SetSoftBusWifiUseState_001
79  * @tc.desc: Verify the SetSoftBusWifiUseState function return value equal SOFTBUS_WIFI_UNKNOWN.
80  * @tc.type: FUNC
81  * @tc.require: 1
82  */
83 HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiUseState_001, TestSize.Level1)
84 {
85     SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
86 
87     EventFwk::SetSoftBusWifiUseState((int)OHOS::Wifi::WifiState::DISABLED, &state);
88     EXPECT_EQ(state, SOFTBUS_WIFI_DISABLED);
89 
90     EventFwk::SetSoftBusWifiUseState((int)OHOS::Wifi::WifiState::ENABLED, &state);
91     EXPECT_EQ(state, SOFTBUS_WIFI_ENABLED);
92 
93     state = SOFTBUS_WIFI_UNKNOWN;
94     EventFwk::SetSoftBusWifiUseState((int)OHOS::Wifi::WifiState::UNKNOWN, &state);
95     EXPECT_EQ(state, SOFTBUS_WIFI_UNKNOWN);
96 }
97 
98 /**
99  * @tc.name: LNN_WIFISERVICE_MONITOR_SetSoftBusWifiHotSpotState_001
100  * @tc.desc: Verify the SetSoftBusWifiHotSpotState function return value equal SOFTBUS_WIFI_UNKNOWN.
101  * @tc.type: FUNC
102  * @tc.require: 1
103  */
104 HWTEST_F(LnnWifiServiceMonitorTest, LNN_WIFISERVICE_MONITOR_SetSoftBusWifiHotSpotState_001, TestSize.Level1)
105 {
106     SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
107 
108     EventFwk::SetSoftBusWifiHotSpotState((int)OHOS::Wifi::ApState::AP_STATE_STARTED, &state);
109     EXPECT_EQ(state, SOFTBUS_AP_ENABLED);
110 
111     EventFwk::SetSoftBusWifiHotSpotState((int)OHOS::Wifi::ApState::AP_STATE_CLOSED, &state);
112     EXPECT_EQ(state, SOFTBUS_AP_DISABLED);
113 
114     state = SOFTBUS_WIFI_UNKNOWN;
115     EventFwk::SetSoftBusWifiHotSpotState((int)OHOS::Wifi::ApState::AP_STATE_NONE, &state);
116     EXPECT_EQ(state, SOFTBUS_WIFI_UNKNOWN);
117 }
118 
119 } // namespace OHOS