offload_callback_test.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <functional>
  17. #include <memory>
  18. #include <string>
  19. #include <vector>
  20. #include <gtest/gtest.h>
  21. #include "wificond/scanning/offload/offload_callback.h"
  22. #include "wificond/scanning/scan_result.h"
  23. #include "wificond/tests/mock_offload_callback_handlers.h"
  24. #include "wificond/tests/offload_test_utils.h"
  25. using android::hardware::wifi::offload::V1_0::ScanResult;
  26. using android::hardware::wifi::offload::V1_0::OffloadStatus;
  27. using android::hardware::wifi::offload::V1_0::OffloadStatusCode;
  28. using android::hardware::hidl_vec;
  29. using testing::NiceMock;
  30. namespace android {
  31. namespace wificond {
  32. class OffloadCallbackTest : public ::testing::Test {
  33. protected:
  34. virtual void SetUp() {
  35. dummy_scan_results_ = OffloadTestUtils::createOffloadScanResults();
  36. }
  37. void TearDown() override { dummy_scan_results_.clear(); }
  38. std::vector<ScanResult> dummy_scan_results_;
  39. std::unique_ptr<OffloadCallback> offload_callback_;
  40. std::unique_ptr<NiceMock<MockOffloadCallbackHandlers>> handlers_;
  41. };
  42. /**
  43. * Testing OffloadCallback to invoke the registered callback handler
  44. * with the scan results when they are available
  45. */
  46. TEST_F(OffloadCallbackTest, checkScanResultSize) {
  47. std::vector<ScanResult> scan_result;
  48. handlers_.reset(new NiceMock<MockOffloadCallbackHandlers>());
  49. ON_CALL(*handlers_, OnScanResultHandler(testing::_))
  50. .WillByDefault(testing::Invoke(
  51. [&scan_result](std::vector<ScanResult> scanResult) -> void {
  52. scan_result = scanResult;
  53. }));
  54. offload_callback_.reset(new OffloadCallback(handlers_.get()));
  55. hidl_vec<ScanResult> offloadScanResult(dummy_scan_results_);
  56. offload_callback_->onScanResult(offloadScanResult);
  57. EXPECT_EQ(dummy_scan_results_.size(), scan_result.size());
  58. }
  59. /**
  60. * Testing OffloadCallback to invoke the registered error handler
  61. */
  62. TEST_F(OffloadCallbackTest, checkErrorStatus) {
  63. OffloadStatus status_;
  64. handlers_.reset(new NiceMock<MockOffloadCallbackHandlers>());
  65. ON_CALL(*handlers_, OnErrorHandler(testing::_))
  66. .WillByDefault(testing::Invoke(
  67. [&status_](OffloadStatus status) -> void { status_ = status; }));
  68. offload_callback_.reset(new OffloadCallback(handlers_.get()));
  69. OffloadStatus status =
  70. OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR);
  71. offload_callback_->onError(status);
  72. EXPECT_EQ(status_.code, OffloadStatusCode::ERROR);
  73. }
  74. } // namespace wificond
  75. } // namespace android