• 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/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::IWifiScannerImpl;
29 using ::com::android::server::wifi::wificond::ChannelSettings;
30 using ::com::android::server::wifi::wificond::HiddenNetwork;
31 using ::com::android::server::wifi::wificond::PnoNetwork;
32 using ::com::android::server::wifi::wificond::PnoSettings;
33 using ::com::android::server::wifi::wificond::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 
50 constexpr uint32_t kFakeFrequency = 5260;
51 constexpr uint32_t kFakeFrequency1 = 2460;
52 constexpr uint32_t kFakeFrequency2 = 2500;
53 
54 }  // namespace
55 
56 class ScanSettingsTest : public ::testing::Test {
57 };
58 
TEST_F(ScanSettingsTest,ChannelSettingsParcelableTest)59 TEST_F(ScanSettingsTest, ChannelSettingsParcelableTest) {
60   ChannelSettings channel_settings;
61   channel_settings.frequency_ = kFakeFrequency;
62 
63   Parcel parcel;
64   EXPECT_EQ(::android::OK, channel_settings.writeToParcel(&parcel));
65 
66   ChannelSettings channel_settings_copy;
67   parcel.setDataPosition(0);
68   EXPECT_EQ(::android::OK, channel_settings_copy.readFromParcel(&parcel));
69 
70   EXPECT_EQ(channel_settings, channel_settings_copy);
71 }
72 
TEST_F(ScanSettingsTest,HiddenNetworkParcelableTest)73 TEST_F(ScanSettingsTest, HiddenNetworkParcelableTest) {
74   HiddenNetwork hidden_network;
75   hidden_network.ssid_ =
76       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
77 
78   Parcel parcel;
79   EXPECT_EQ(::android::OK, hidden_network.writeToParcel(&parcel));
80 
81   HiddenNetwork hidden_network_copy;
82   parcel.setDataPosition(0);
83   EXPECT_EQ(::android::OK, hidden_network_copy.readFromParcel(&parcel));
84 
85   EXPECT_EQ(hidden_network, hidden_network_copy);
86 }
87 
TEST_F(ScanSettingsTest,SingleScanSettingsParcelableTest)88 TEST_F(ScanSettingsTest, SingleScanSettingsParcelableTest) {
89   SingleScanSettings scan_settings;
90 
91   ChannelSettings channel, channel1, channel2;
92   channel.frequency_ = kFakeFrequency;
93   channel1.frequency_ = kFakeFrequency1;
94   channel2.frequency_ = kFakeFrequency2;
95   scan_settings.scan_type_ = IWifiScannerImpl::SCAN_TYPE_LOW_SPAN;
96 
97   HiddenNetwork network;
98   network.ssid_ =
99       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
100 
101   scan_settings.channel_settings_ = {channel, channel1, channel2};
102   scan_settings.hidden_networks_ = {network};
103 
104   Parcel parcel;
105   EXPECT_EQ(::android::OK, scan_settings.writeToParcel(&parcel));
106 
107   SingleScanSettings scan_settings_copy;
108   parcel.setDataPosition(0);
109   EXPECT_EQ(::android::OK, scan_settings_copy.readFromParcel(&parcel));
110 
111   EXPECT_EQ(scan_settings, scan_settings_copy);
112 }
113 
TEST_F(ScanSettingsTest,SingleScanSettingsParcelableWriteInvalidScanType)114 TEST_F(ScanSettingsTest, SingleScanSettingsParcelableWriteInvalidScanType) {
115   SingleScanSettings scan_settings;
116 
117   ChannelSettings channel, channel1, channel2;
118   channel.frequency_ = kFakeFrequency;
119   channel1.frequency_ = kFakeFrequency1;
120   channel2.frequency_ = kFakeFrequency2;
121   scan_settings.scan_type_ = IWifiScannerImpl::SCAN_TYPE_DEFAULT;
122 
123   HiddenNetwork network;
124   network.ssid_ =
125       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
126 
127   scan_settings.channel_settings_ = {channel, channel1, channel2};
128   scan_settings.hidden_networks_ = {network};
129 
130   Parcel parcel;
131   EXPECT_EQ(::android::BAD_VALUE, scan_settings.writeToParcel(&parcel));
132 }
133 
134 
TEST_F(ScanSettingsTest,PnoNetworkParcelableTest)135 TEST_F(ScanSettingsTest, PnoNetworkParcelableTest) {
136   PnoNetwork pno_network;
137   pno_network.ssid_ =
138       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
139   pno_network.is_hidden_ = true;
140 
141   Parcel parcel;
142   EXPECT_EQ(::android::OK, pno_network.writeToParcel(&parcel));
143 
144   PnoNetwork pno_network_copy;
145   parcel.setDataPosition(0);
146   EXPECT_EQ(::android::OK, pno_network_copy.readFromParcel(&parcel));
147 
148   EXPECT_EQ(pno_network, pno_network_copy);
149 }
150 
TEST_F(ScanSettingsTest,PnoSettingsParcelableTest)151 TEST_F(ScanSettingsTest, PnoSettingsParcelableTest) {
152   PnoSettings pno_settings;
153 
154   PnoNetwork network, network1;
155   network.ssid_ =
156       vector<uint8_t>(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
157   network.is_hidden_ = true;
158   network1.ssid_ =
159       vector<uint8_t>(kFakeSsid1, kFakeSsid1 + sizeof(kFakeSsid1));
160   network1.is_hidden_ = false;
161 
162   pno_settings.interval_ms_ = kFakePnoIntervalMs;
163   pno_settings.min_2g_rssi_ = kFakePnoMin2gRssi;
164   pno_settings.min_5g_rssi_ = kFakePnoMin5gRssi;
165 
166   pno_settings.pno_networks_ = {network, network1};
167 
168   Parcel parcel;
169   EXPECT_EQ(::android::OK, pno_settings.writeToParcel(&parcel));
170 
171   PnoSettings pno_settings_copy;
172   parcel.setDataPosition(0);
173   EXPECT_EQ(::android::OK, pno_settings_copy.readFromParcel(&parcel));
174 
175   EXPECT_EQ(pno_settings, pno_settings_copy);
176 }
177 
178 
179 
180 }  // namespace wificond
181 }  // namespace android
182