• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <vector>
18 
19 #include <gtest/gtest.h>
20 
21 #include "android/net/wifi/nl80211/IWifiScannerImpl.h"
22 #include "wificond/scanning/channel_settings.h"
23 #include "wificond/scanning/hidden_network.h"
24 #include "wificond/scanning/pno_network.h"
25 #include "wificond/scanning/pno_settings.h"
26 #include "wificond/scanning/single_scan_settings.h"
27 
28 using ::android::net::wifi::nl80211::IWifiScannerImpl;
29 using ::android::net::wifi::nl80211::ChannelSettings;
30 using ::android::net::wifi::nl80211::HiddenNetwork;
31 using ::android::net::wifi::nl80211::PnoNetwork;
32 using ::android::net::wifi::nl80211::PnoSettings;
33 using ::android::net::wifi::nl80211::SingleScanSettings;
34 using std::vector;
35 
36 namespace android {
37 namespace wificond {
38 
39 namespace {
40 
41 const uint8_t kFakeSsid[] =
42     {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
43 const uint8_t kFakeSsid1[] =
44     {'A', 'n', 'd', 'r', 'o', 'i', 'd', 'A', 'P', 'T', 'e', 's', 't'};
45 
46 constexpr int32_t kFakePnoIntervalMs = 20000;
47 constexpr int32_t kFakePnoMin2gRssi = -80;
48 constexpr int32_t kFakePnoMin5gRssi = -85;
49 constexpr int32_t kFakePnoMin6gRssi = -89;
50 
51 constexpr uint32_t kFakeFrequency = 5260;
52 constexpr uint32_t kFakeFrequency1 = 2460;
53 constexpr uint32_t kFakeFrequency2 = 2500;
54 
55 }  // namespace
56 
57 class ScanSettingsTest : public ::testing::Test {
58 };
59 
TEST_F(ScanSettingsTest,ChannelSettingsParcelableTest)60 TEST_F(ScanSettingsTest, ChannelSettingsParcelableTest) {
61   ChannelSettings channel_settings;
62   channel_settings.frequency_ = kFakeFrequency;
63 
64   Parcel parcel;
65   EXPECT_EQ(::android::OK, channel_settings.writeToParcel(&parcel));
66 
67   ChannelSettings channel_settings_copy;
68   parcel.setDataPosition(0);
69   EXPECT_EQ(::android::OK, channel_settings_copy.readFromParcel(&parcel));
70 
71   EXPECT_EQ(channel_settings, channel_settings_copy);
72 }
73 
TEST_F(ScanSettingsTest,HiddenNetworkParcelableTest)74 TEST_F(ScanSettingsTest, HiddenNetworkParcelableTest) {
75   HiddenNetwork hidden_network;
76   hidden_network.ssid_ =
77       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
78 
79   Parcel parcel;
80   EXPECT_EQ(::android::OK, hidden_network.writeToParcel(&parcel));
81 
82   HiddenNetwork hidden_network_copy;
83   parcel.setDataPosition(0);
84   EXPECT_EQ(::android::OK, hidden_network_copy.readFromParcel(&parcel));
85 
86   EXPECT_EQ(hidden_network, hidden_network_copy);
87 }
88 
TEST_F(ScanSettingsTest,SingleScanSettingsParcelableTest)89 TEST_F(ScanSettingsTest, SingleScanSettingsParcelableTest) {
90   SingleScanSettings scan_settings;
91 
92   ChannelSettings channel, channel1, channel2;
93   channel.frequency_ = kFakeFrequency;
94   channel1.frequency_ = kFakeFrequency1;
95   channel2.frequency_ = kFakeFrequency2;
96   scan_settings.scan_type_ = IWifiScannerImpl::SCAN_TYPE_LOW_SPAN;
97 
98   HiddenNetwork network;
99   network.ssid_ =
100       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
101 
102   scan_settings.channel_settings_ = {channel, channel1, channel2};
103   scan_settings.hidden_networks_ = {network};
104 
105   Parcel parcel;
106   EXPECT_EQ(::android::OK, scan_settings.writeToParcel(&parcel));
107 
108   SingleScanSettings scan_settings_copy;
109   parcel.setDataPosition(0);
110   EXPECT_EQ(::android::OK, scan_settings_copy.readFromParcel(&parcel));
111 
112   EXPECT_EQ(scan_settings, scan_settings_copy);
113 }
114 
TEST_F(ScanSettingsTest,SingleScanSettingsParcelableWriteInvalidScanType)115 TEST_F(ScanSettingsTest, SingleScanSettingsParcelableWriteInvalidScanType) {
116   SingleScanSettings scan_settings;
117 
118   ChannelSettings channel, channel1, channel2;
119   channel.frequency_ = kFakeFrequency;
120   channel1.frequency_ = kFakeFrequency1;
121   channel2.frequency_ = kFakeFrequency2;
122   scan_settings.scan_type_ = IWifiScannerImpl::SCAN_TYPE_DEFAULT;
123 
124   HiddenNetwork network;
125   network.ssid_ =
126       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
127 
128   scan_settings.channel_settings_ = {channel, channel1, channel2};
129   scan_settings.hidden_networks_ = {network};
130 
131   Parcel parcel;
132   EXPECT_EQ(::android::BAD_VALUE, scan_settings.writeToParcel(&parcel));
133 }
134 
135 
TEST_F(ScanSettingsTest,PnoNetworkParcelableTest)136 TEST_F(ScanSettingsTest, PnoNetworkParcelableTest) {
137   PnoNetwork pno_network;
138   pno_network.ssid_ =
139       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
140   pno_network.is_hidden_ = true;
141 
142   Parcel parcel;
143   EXPECT_EQ(::android::OK, pno_network.writeToParcel(&parcel));
144 
145   PnoNetwork pno_network_copy;
146   parcel.setDataPosition(0);
147   EXPECT_EQ(::android::OK, pno_network_copy.readFromParcel(&parcel));
148 
149   EXPECT_EQ(pno_network, pno_network_copy);
150 }
151 
TEST_F(ScanSettingsTest,PnoSettingsParcelableTest)152 TEST_F(ScanSettingsTest, PnoSettingsParcelableTest) {
153   PnoSettings pno_settings;
154 
155   PnoNetwork network, network1;
156   network.ssid_ =
157       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
158   network.is_hidden_ = true;
159   network1.ssid_ =
160       vector<uint8_t>(kFakeSsid1, kFakeSsid1 + sizeof(kFakeSsid1));
161   network1.is_hidden_ = false;
162 
163   pno_settings.interval_ms_ = kFakePnoIntervalMs;
164   pno_settings.min_2g_rssi_ = kFakePnoMin2gRssi;
165   pno_settings.min_5g_rssi_ = kFakePnoMin5gRssi;
166   pno_settings.min_6g_rssi_ = kFakePnoMin6gRssi;
167 
168   pno_settings.pno_networks_ = {network, network1};
169 
170   Parcel parcel;
171   EXPECT_EQ(::android::OK, pno_settings.writeToParcel(&parcel));
172 
173   PnoSettings pno_settings_copy;
174   parcel.setDataPosition(0);
175   EXPECT_EQ(::android::OK, pno_settings_copy.readFromParcel(&parcel));
176 
177   EXPECT_EQ(pno_settings, pno_settings_copy);
178 }
179 
180 
181 
182 }  // namespace wificond
183 }  // namespace android
184