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 "wificond/scanning/scan_result.h"
22 
23 using ::com::android::server::wifi::wificond::NativeScanResult;
24 using std::vector;
25 
26 namespace android {
27 namespace wificond {
28 
29 namespace {
30 
31 
32 const uint8_t kFakeSsid[] =
33     {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
34 const uint8_t kFakeBssid[] = {0x45, 0x54, 0xad, 0x67, 0x98, 0xf6};
35 const uint8_t kFakeIE[] = {0x05, 0x11, 0x32, 0x11};
36 constexpr uint32_t kFakeFrequency = 5240;
37 constexpr int32_t kFakeSignalMbm= -32;
38 constexpr uint64_t kFakeTsf = 1200;
39 constexpr int16_t kFakeCapability = 0;
40 constexpr bool kFakeAssociated = true;
41 
42 }  // namespace
43 
44 class ScanResultTest : public ::testing::Test {
45 };
46 
TEST_F(ScanResultTest,ParcelableTest)47 TEST_F(ScanResultTest, ParcelableTest) {
48   std::vector<uint8_t> ssid(kFakeSsid, kFakeSsid + sizeof(kFakeSsid));
49   std::vector<uint8_t> bssid(kFakeBssid, kFakeBssid + sizeof(kFakeBssid));
50   std::vector<uint8_t> ie(kFakeIE, kFakeIE + sizeof(kFakeIE));
51 
52   NativeScanResult scan_result(ssid, bssid, ie, kFakeFrequency,
53       kFakeSignalMbm, kFakeTsf, kFakeCapability, kFakeAssociated);
54   Parcel parcel;
55   EXPECT_EQ(::android::OK, scan_result.writeToParcel(&parcel));
56 
57   NativeScanResult scan_result_copy;
58   parcel.setDataPosition(0);
59   EXPECT_EQ(::android::OK, scan_result_copy.readFromParcel(&parcel));
60 
61   EXPECT_EQ(ssid, scan_result_copy.ssid);
62   EXPECT_EQ(bssid, scan_result_copy.bssid);
63   EXPECT_EQ(ie, scan_result_copy.info_element);
64   EXPECT_EQ(kFakeFrequency, scan_result_copy.frequency);
65   EXPECT_EQ(kFakeSignalMbm, scan_result_copy.signal_mbm);
66   EXPECT_EQ(kFakeTsf, scan_result_copy.tsf);
67   EXPECT_EQ(kFakeCapability, scan_result_copy.capability);
68   EXPECT_EQ(kFakeAssociated, scan_result_copy.associated);
69 }
70 
71 }  // namespace wificond
72 }  // namespace android
73