OSDN Git Service

Merge "Add dump state for wificond interface classes" into oc-dev am: 0d676773e1
[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 #include "wificond/tests/mock_offload_callback_handlers.h"
28
29 using android::hardware::wifi::offload::V1_0::ScanResult;
30 using android::hardware::wifi::offload::V1_0::OffloadStatus;
31 using android::hardware::hidl_vec;
32 using testing::NiceMock;
33
34 namespace android {
35 namespace wificond {
36
37 class OffloadCallbackTest: public ::testing::Test {
38  protected:
39   virtual void SetUp() {
40     dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults();
41   }
42
43   void TearDown() override {
44     dummy_scan_results_.clear();
45   }
46
47   std::vector<ScanResult> dummy_scan_results_;
48   std::unique_ptr<OffloadCallback> offload_callback_;
49   std::unique_ptr<NiceMock<MockOffloadCallbackHandlers>> handlers_;
50 };
51
52 /**
53  * Testing OffloadCallback to invoke the registered callback handler
54  * with the scan results when they are available
55  */
56 TEST_F(OffloadCallbackTest, checkScanResultSize) {
57   std::vector<ScanResult> scan_result;
58   handlers_.reset(new NiceMock<MockOffloadCallbackHandlers>());
59   ON_CALL(*handlers_, OnScanResultHandler(testing::_))
60       .WillByDefault(testing::Invoke(
61           [&scan_result] (std::vector<ScanResult> scanResult) -> void {
62             scan_result = scanResult;
63           }));
64   offload_callback_.reset(new OffloadCallback(handlers_.get()));
65   hidl_vec<ScanResult> offloadScanResult(dummy_scan_results_);
66   offload_callback_->onScanResult(offloadScanResult);
67   EXPECT_EQ(dummy_scan_results_.size(), scan_result.size());
68 }
69
70 /**
71  * Testing OffloadCallback to invoke the registered error handler
72  */
73 TEST_F(OffloadCallbackTest, checkErrorStatus) {
74   OffloadStatus status_;
75   handlers_.reset(new NiceMock<MockOffloadCallbackHandlers>());
76   ON_CALL(*handlers_, OnErrorHandler(testing::_))
77       .WillByDefault(testing::Invoke(
78           [&status_] (OffloadStatus status) -> void {
79             status_ = status;
80           }));
81   offload_callback_.reset(new OffloadCallback(handlers_.get()));
82   offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_ERROR);
83   EXPECT_EQ(status_, OffloadStatus::OFFLOAD_STATUS_ERROR);
84 }
85
86 } // namespace wificond
87 } // namespace android