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 <gtest/gtest.h>
17
18 #include <android-base/logging.h>
19
20 #include "mock_chre_interface.h"
21 #include "mock_chre_interface_factory.h"
22
23 #include "chre_interface_callbacks.h"
24 #include "offload_server.h"
25
26 namespace {
27
28 using android::hardware::wifi::offload::V1_0::implementation::ChreInterfaceCallbacks;
29 using android::hardware::wifi::offload::V1_0::implementation::MockChreInterface;
30 using android::hardware::wifi::offload::V1_0::implementation::ChreInterface;
31
32 ChreInterface*
CaptureCallback(ChreInterfaceCallbacks * callback,std::unique_ptr<ChreInterfaceCallbacks> * chre_interface_callback,std::unique_ptr<testing::NiceMock<MockChreInterface>> * chre_interface)33 CaptureCallback(ChreInterfaceCallbacks* callback,
34 std::unique_ptr<ChreInterfaceCallbacks>* chre_interface_callback,
35 std::unique_ptr<testing::NiceMock<MockChreInterface>>* chre_interface) {
36 chre_interface->reset(new testing::NiceMock<MockChreInterface>(callback));
37 chre_interface_callback->reset(callback);
38 return chre_interface->get();
39 }
40
41 } // namespace
42
43 namespace android {
44 namespace hardware {
45 namespace wifi {
46 namespace offload {
47 namespace V1_0 {
48 namespace implementation {
49
50 class OffloadServerTest : public ::testing::Test {
51 protected:
SetUp()52 virtual void SetUp() {
53 ON_CALL(*chre_interface_factory_, getChreInterface(testing::_))
54 .WillByDefault(testing::Invoke(std::bind(CaptureCallback, std::placeholders::_1,
55 &chre_interface_callback_, &chre_interface_)));
56 }
57
TearDown()58 void TearDown() override {
59 }
60
61 std::unique_ptr<testing::NiceMock<MockChreInterfaceFactory>> chre_interface_factory_{
62 new testing::NiceMock<MockChreInterfaceFactory>()};
63 std::unique_ptr<testing::NiceMock<MockChreInterface>> chre_interface_;
64 std::unique_ptr<ChreInterfaceCallbacks> chre_interface_callback_;
65 };
66
TEST_F(OffloadServerTest,createOffloadServerTest)67 TEST_F(OffloadServerTest, createOffloadServerTest) {
68 EXPECT_CALL(*chre_interface_factory_, getChreInterface(testing::_));
69 OffloadServer* server = new OffloadServer(chre_interface_factory_.get());
70 EXPECT_FALSE(chre_interface_callback_.get() == nullptr);
71 }
72
73 } // namespace implementation
74 } // namespace V1_0
75 } // namespace offload
76 } // namespace wifi
77 } // namespace hardware
78 } // namespace android
79