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 <array>
18 #include <vector>
19
20 #include <linux/if_ether.h>
21
22 #include <gtest/gtest.h>
23
24 #include "wificond/scanning/scan_result.h"
25
26 using ::android::net::wifi::nl80211::NativeScanResult;
27 using ::android::net::wifi::nl80211::RadioChainInfo;
28 using std::array;
29 using std::vector;
30
31 namespace android {
32 namespace wificond {
33
34 namespace {
35
36
37 const uint8_t kFakeSsid[] =
38 {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
39 const array<uint8_t, ETH_ALEN> kFakeBssid = {0x45, 0x54, 0xad, 0x67, 0x98, 0xf6};
40 const uint8_t kFakeIE[] = {0x05, 0x11, 0x32, 0x11};
41 constexpr uint32_t kFakeFrequency = 5240;
42 constexpr int32_t kFakeSignalMbm= -32;
43 constexpr uint64_t kFakeTsf = 1200;
44 constexpr int16_t kFakeCapability = 0;
45 constexpr bool kFakeAssociated = true;
46 constexpr int32_t kFakeRadioChainIds[] = { 0, 1 };
47 constexpr int32_t kFakeRadioChainLevels[] = { -56, -64};
48
49 } // namespace
50
51 class ScanResultTest : public ::testing::Test {
52 };
53
TEST_F(ScanResultTest,ParcelableTest)54 TEST_F(ScanResultTest, ParcelableTest) {
55 std::vector<uint8_t> ssid(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
56 array<uint8_t, ETH_ALEN> bssid = kFakeBssid;
57 std::vector<uint8_t> ie(kFakeIE, kFakeIE + sizeof(kFakeIE));
58 std::vector<RadioChainInfo> radio_chain_infos;
59 radio_chain_infos.emplace_back(
60 kFakeRadioChainIds[0], kFakeRadioChainLevels[0]);
61 radio_chain_infos.emplace_back(
62 kFakeRadioChainIds[1], kFakeRadioChainLevels[1]);
63
64 NativeScanResult scan_result(ssid, bssid, ie, kFakeFrequency,
65 kFakeSignalMbm, kFakeTsf, kFakeCapability, kFakeAssociated,
66 radio_chain_infos);
67
68 Parcel parcel;
69 EXPECT_EQ(::android::OK, scan_result.writeToParcel(&parcel));
70
71 NativeScanResult scan_result_copy;
72 parcel.setDataPosition(0);
73 EXPECT_EQ(::android::OK, scan_result_copy.readFromParcel(&parcel));
74
75 EXPECT_EQ(ssid, scan_result_copy.ssid);
76 EXPECT_EQ(bssid, scan_result_copy.bssid);
77 EXPECT_EQ(ie, scan_result_copy.info_element);
78 EXPECT_EQ(kFakeFrequency, scan_result_copy.frequency);
79 EXPECT_EQ(kFakeSignalMbm, scan_result_copy.signal_mbm);
80 EXPECT_EQ(kFakeTsf, scan_result_copy.tsf);
81 EXPECT_EQ(kFakeCapability, scan_result_copy.capability);
82 EXPECT_EQ(kFakeAssociated, scan_result_copy.associated);
83 EXPECT_EQ(2u, scan_result_copy.radio_chain_infos.size());
84 EXPECT_EQ(kFakeRadioChainIds[0], scan_result_copy.radio_chain_infos[0].chain_id);
85 EXPECT_EQ(kFakeRadioChainIds[1], scan_result_copy.radio_chain_infos[1].chain_id);
86 EXPECT_EQ(kFakeRadioChainLevels[0], scan_result_copy.radio_chain_infos[0].level);
87 EXPECT_EQ(kFakeRadioChainLevels[1], scan_result_copy.radio_chain_infos[1].level);
88 }
89
90 } // namespace wificond
91 } // namespace android
92