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