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 <android-base/logging.h>
18
19 #include <android/hardware/wifi/1.0/IWifiApIface.h>
20
21 #include <VtsHalHidlTargetTestBase.h>
22
23 #include "wifi_hidl_call_util.h"
24 #include "wifi_hidl_test_utils.h"
25
26 using ::android::hardware::wifi::V1_0::IfaceType;
27 using ::android::hardware::wifi::V1_0::IWifiApIface;
28 using ::android::hardware::wifi::V1_0::WifiBand;
29 using ::android::hardware::wifi::V1_0::WifiStatusCode;
30 using ::android::sp;
31
32 /**
33 * Fixture to use for all AP Iface HIDL interface tests.
34 */
35 class WifiApIfaceHidlTest : public ::testing::VtsHalHidlTargetTestBase {
36 public:
SetUp()37 virtual void SetUp() override {
38 wifi_ap_iface_ = getWifiApIface();
39 ASSERT_NE(nullptr, wifi_ap_iface_.get());
40 }
41
TearDown()42 virtual void TearDown() override { stopWifi(); }
43
44 protected:
45 sp<IWifiApIface> wifi_ap_iface_;
46 };
47
48 /*
49 * Create:
50 * Ensures that an instance of the IWifiApIface proxy object is
51 * successfully created.
52 */
TEST(WifiApIfaceHidlTestNoFixture,Create)53 TEST(WifiApIfaceHidlTestNoFixture, Create) {
54 EXPECT_NE(nullptr, getWifiApIface().get());
55 stopWifi();
56 }
57
58 /*
59 * GetType:
60 * Ensures that the correct interface type is returned for AP interface.
61 */
TEST_F(WifiApIfaceHidlTest,GetType)62 TEST_F(WifiApIfaceHidlTest, GetType) {
63 const auto& status_and_type = HIDL_INVOKE(wifi_ap_iface_, getType);
64 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_type.first.code);
65 EXPECT_EQ(IfaceType::AP, status_and_type.second);
66 }
67
68 /*
69 * SetCountryCode:
70 * Ensures that a call to set the country code will return with a success
71 * status code.
72 */
TEST_F(WifiApIfaceHidlTest,SetCountryCode)73 TEST_F(WifiApIfaceHidlTest, SetCountryCode) {
74 const android::hardware::hidl_array<int8_t, 2> kCountryCode{
75 std::array<int8_t, 2>{{0x55, 0x53}}};
76 EXPECT_EQ(WifiStatusCode::SUCCESS,
77 HIDL_INVOKE(wifi_ap_iface_, setCountryCode, kCountryCode).code);
78 }
79
80 /*
81 * GetValidFrequenciesForBand:
82 * Ensures that we can retrieve valid frequencies for 2.4 GHz band.
83 */
TEST_F(WifiApIfaceHidlTest,GetValidFrequenciesForBand)84 TEST_F(WifiApIfaceHidlTest, GetValidFrequenciesForBand) {
85 const auto& status_and_freqs = HIDL_INVOKE(
86 wifi_ap_iface_, getValidFrequenciesForBand, WifiBand::BAND_24GHZ);
87 EXPECT_EQ(WifiStatusCode::SUCCESS, status_and_freqs.first.code);
88 EXPECT_GT(status_and_freqs.second.size(), 0u);
89 }
90