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_callbacks.h"
21
22 #include "chre_interface.h"
23
24 namespace {
25
26 const size_t kBufSize = 256;
27 const uint8_t kDefaultValue = 0xaa;
28 const uint32_t kDefaultMessageType = 0;
29
30 } // namespace
31
32 namespace android {
33 namespace hardware {
34 namespace wifi {
35 namespace offload {
36 namespace V1_0 {
37 namespace implementation {
38
39 class ChreInterfaceTest : public ::testing::Test {
40 protected:
SetUp()41 virtual void SetUp() {
42 chre_interface_.reset(new ChreInterface(chre_interface_callback_.get()));
43 }
44
TearDown()45 void TearDown() override {
46 }
47
48 std::unique_ptr<testing::NiceMock<MockChreInterfaceCallbacks>> chre_interface_callback_{
49 new testing::NiceMock<MockChreInterfaceCallbacks>()};
50 std::unique_ptr<ChreInterface> chre_interface_;
51 };
52
TEST_F(ChreInterfaceTest,ChreInterfaceConnectionEventTest)53 TEST_F(ChreInterfaceTest, ChreInterfaceConnectionEventTest) {
54 EXPECT_CALL(*chre_interface_callback_, handleConnectionEvents(testing::_));
55 chre_interface_->reportConnectionEvent(ChreInterfaceCallbacks::CONNECTED);
56 EXPECT_TRUE(chre_interface_->isConnected());
57 }
58
TEST_F(ChreInterfaceTest,ChreInterfaceHandleMessageTest)59 TEST_F(ChreInterfaceTest, ChreInterfaceHandleMessageTest) {
60 EXPECT_CALL(*chre_interface_callback_, handleMessage(testing::_, testing::_));
61 uint32_t messageType;
62 std::vector<uint8_t> buffer_recvd;
63 ON_CALL(*chre_interface_callback_, handleMessage(testing::_, testing::_))
64 .WillByDefault(
65 DoAll(testing::SaveArg<0>(&messageType), testing::SaveArg<1>(&buffer_recvd)));
66 uint8_t buffer_sent[kBufSize];
67 for (size_t j = 0; j < kBufSize; j++) {
68 buffer_sent[j] = kDefaultValue;
69 }
70 chre_interface_->handleMessage(kDefaultMessageType, (void*)&buffer_sent[0], kBufSize);
71 EXPECT_EQ(messageType, kDefaultMessageType);
72 EXPECT_EQ(buffer_recvd.size(), kBufSize);
73 for (size_t i = 0; i < buffer_recvd.size(); i++) {
74 EXPECT_EQ(buffer_recvd[i], buffer_sent[i]);
75 }
76 }
77
78 } // namespace implementation
79 } // namespace V1_0
80 } // namespace offload
81 } // namespace wifi
82 } // namespace hardware
83 } // namespace android
84