2 * Copyright (C) 2016, The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <gtest/gtest.h>
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"
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;
37 class OffloadCallbackTest: public ::testing::Test {
39 virtual void SetUp() {
40 dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults();
43 void TearDown() override {
44 dummy_scan_results_.clear();
47 std::vector<ScanResult> dummy_scan_results_;
48 std::unique_ptr<OffloadCallback> offload_callback_;
49 std::unique_ptr<NiceMock<MockOffloadCallbackHandlers>> handlers_;
53 * Testing OffloadCallback to invoke the registered callback handler
54 * with the scan results when they are available
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;
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());
71 * Testing OffloadCallback to invoke the registered error handler
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 {
81 offload_callback_.reset(new OffloadCallback(handlers_.get()));
82 offload_callback_->onError(OffloadStatus::OFFLOAD_STATUS_ERROR);
83 EXPECT_EQ(status_, OffloadStatus::OFFLOAD_STATUS_ERROR);
86 } // namespace wificond
87 } // namespace android