OSDN Git Service

wificond: Dump interface list am: 099ee0c764
[android-x86/system-connectivity-wificond.git] / tests / offload_callback_test.cpp
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 <functional>
18 #include <memory>
19 #include <vector>
20 #include <string>
21
22 #include <gtest/gtest.h>
23
24 #include "wificond/scanning/scan_result.h"
25 #include "wificond/scanning/offload/offload_callback.h"
26 #include "wificond/tests/offload_test_utils.h"
27
28 using android::hardware::wifi::offload::V1_0::ScanResult;
29 using android::hardware::hidl_vec;
30
31 namespace android {
32 namespace wificond {
33
34 class OffloadCallbackTest: public ::testing::Test {
35  protected:
36    virtual void SetUp() {
37      dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults();
38    }
39
40    void TearDown() override {
41      dummy_scan_results_.clear();
42    }
43
44    std::vector<ScanResult> dummy_scan_results_;
45    std::unique_ptr<OffloadCallback> dut_;
46 };
47
48 /**
49  * Testing OffloadCallback to invoke the registered callback handler
50  * with the scan results when they are available
51  */
52 TEST_F(OffloadCallbackTest, checkScanResultSize) {
53   std::vector<ScanResult> scan_result;
54   dut_.reset(new OffloadCallback(
55     [&scan_result] (std::vector<ScanResult> scanResult) -> void {
56       scan_result = scanResult;
57     }));
58   hidl_vec<ScanResult> offloadScanResult(dummy_scan_results_);
59   dut_->onScanResult(offloadScanResult);
60   EXPECT_EQ(dummy_scan_results_.size(), scan_result.size());
61 }
62
63 } // namespace wificond
64 } // namespace android