OSDN Git Service

Wificond: Introduce new APIS to OffloadScanManager
[android-x86/system-connectivity-wificond.git] / tests / client_interface_impl_unittest.cpp
1 /*
2  * Copyright (C) 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <memory>
18 #include <vector>
19
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 #include <wifi_system/supplicant_manager.h>
23 #include <wifi_system_test/mock_interface_tool.h>
24 #include <wifi_system_test/mock_supplicant_manager.h>
25
26 #include "wificond/client_interface_impl.h"
27 #include "wificond/tests/mock_netlink_manager.h"
28 #include "wificond/tests/mock_netlink_utils.h"
29 #include "wificond/tests/mock_scan_utils.h"
30
31 using android::wifi_system::MockInterfaceTool;
32 using android::wifi_system::MockSupplicantManager;
33 using android::wifi_system::SupplicantManager;
34 using std::unique_ptr;
35 using std::vector;
36 using testing::NiceMock;
37 using testing::Return;
38 using testing::_;
39
40 namespace android {
41 namespace wificond {
42 namespace {
43
44 const uint32_t kTestWiphyIndex = 2;
45 const char kTestInterfaceName[] = "testwifi0";
46 const uint32_t kTestInterfaceIndex = 42;
47
48 class ClientInterfaceImplTest : public ::testing::Test {
49  protected:
50
51   void SetUp() override {
52     EXPECT_CALL(*netlink_utils_,
53                 SubscribeMlmeEvent(kTestInterfaceIndex, _));
54     EXPECT_CALL(*netlink_utils_,
55                 GetWiphyInfo(kTestWiphyIndex, _, _, _));
56     client_interface_.reset(new ClientInterfaceImpl{
57         kTestWiphyIndex,
58         kTestInterfaceName,
59         kTestInterfaceIndex,
60         vector<uint8_t>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
61         if_tool_.get(),
62         supplicant_manager_.get(),
63         netlink_utils_.get(),
64         scan_utils_.get()});
65   }
66
67   void TearDown() override {
68     EXPECT_CALL(*netlink_utils_,
69                 UnsubscribeMlmeEvent(kTestInterfaceIndex));
70     EXPECT_CALL(*supplicant_manager_, StopSupplicant())
71         .WillOnce(Return(false));
72   }
73
74   unique_ptr<NiceMock<MockInterfaceTool>> if_tool_{
75       new NiceMock<MockInterfaceTool>};
76   unique_ptr<NiceMock<MockSupplicantManager>> supplicant_manager_{
77       new NiceMock<MockSupplicantManager>};
78   unique_ptr<NiceMock<MockNetlinkManager>> netlink_manager_{
79       new NiceMock<MockNetlinkManager>()};
80   unique_ptr<NiceMock<MockNetlinkUtils>> netlink_utils_{
81       new NiceMock<MockNetlinkUtils>(netlink_manager_.get())};
82   unique_ptr<NiceMock<MockScanUtils>> scan_utils_{
83       new NiceMock<MockScanUtils>(netlink_manager_.get())};
84   unique_ptr<ClientInterfaceImpl> client_interface_;
85 };  // class ClientInterfaceImplTest
86
87 }  // namespace
88
89 TEST_F(ClientInterfaceImplTest, ShouldReportEnableFailure) {
90   EXPECT_CALL(*supplicant_manager_, StartSupplicant())
91       .WillOnce(Return(false));
92   EXPECT_FALSE(client_interface_->EnableSupplicant());
93 }
94
95 TEST_F(ClientInterfaceImplTest, ShouldReportEnableSuccess) {
96   EXPECT_CALL(*supplicant_manager_, StartSupplicant())
97       .WillOnce(Return(true));
98   EXPECT_TRUE(client_interface_->EnableSupplicant());
99 }
100
101 TEST_F(ClientInterfaceImplTest, ShouldReportDisableFailure) {
102   EXPECT_CALL(*supplicant_manager_, StopSupplicant())
103       .WillOnce(Return(false));
104   EXPECT_FALSE(client_interface_->DisableSupplicant());
105 }
106
107 TEST_F(ClientInterfaceImplTest, ShouldReportDisableSuccess) {
108   EXPECT_CALL(*supplicant_manager_, StopSupplicant())
109       .WillOnce(Return(true));
110   EXPECT_TRUE(client_interface_->DisableSupplicant());
111 }
112
113 }  // namespace wificond
114 }  // namespace android