blob: de259271b0d87a3acdc5c8c1b058842a494bab2f [file] [log] [blame]
Yu Shane2974562022-08-10 18:37:03 -07001/*
2 * Copyright (C) 2022 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 "RemoteAccessService.h"
18
19#include <gmock/gmock.h>
20#include <gtest/gtest.h>
21#include <wakeup_client.grpc.pb.h>
22
23namespace android {
24namespace hardware {
25namespace automotive {
26namespace remoteaccess {
27
28using ::grpc::ClientAsyncReaderInterface;
29using ::grpc::ClientAsyncResponseReaderInterface;
30using ::grpc::ClientContext;
31using ::grpc::ClientReader;
32using ::grpc::ClientReaderInterface;
33using ::grpc::CompletionQueue;
34using ::grpc::Status;
35
36using ::ndk::ScopedAStatus;
37
38class MockGrpcClientStub : public WakeupClient::StubInterface {
39 public:
40 MOCK_METHOD(ClientReaderInterface<GetRemoteTasksResponse>*, GetRemoteTasksRaw,
41 (ClientContext * context, const GetRemoteTasksRequest& request));
42 MOCK_METHOD(Status, NotifyWakeupRequired,
43 (ClientContext * context, const NotifyWakeupRequiredRequest& request,
44 NotifyWakeupRequiredResponse* response));
45 // Async methods which we do not care.
46 MOCK_METHOD(ClientAsyncReaderInterface<GetRemoteTasksResponse>*, AsyncGetRemoteTasksRaw,
47 (ClientContext * context, const GetRemoteTasksRequest& request, CompletionQueue* cq,
48 void* tag));
49 MOCK_METHOD(ClientAsyncReaderInterface<GetRemoteTasksResponse>*, PrepareAsyncGetRemoteTasksRaw,
50 (ClientContext * context, const GetRemoteTasksRequest& request,
51 CompletionQueue* cq));
52 MOCK_METHOD(ClientAsyncResponseReaderInterface<NotifyWakeupRequiredResponse>*,
53 AsyncNotifyWakeupRequiredRaw,
54 (ClientContext * context, const NotifyWakeupRequiredRequest& request,
55 CompletionQueue* cq));
56 MOCK_METHOD(ClientAsyncResponseReaderInterface<NotifyWakeupRequiredResponse>*,
57 PrepareAsyncNotifyWakeupRequiredRaw,
58 (ClientContext * context, const NotifyWakeupRequiredRequest& request,
59 CompletionQueue* cq));
60};
61
62class RemoteAccessServiceUnitTest : public ::testing::Test {
63 public:
64 RemoteAccessServiceUnitTest() {
65 mGrpcWakeupClientStub = std::make_unique<MockGrpcClientStub>();
66 mService = ndk::SharedRefBase::make<RemoteAccessService>(mGrpcWakeupClientStub.get());
67 }
68
69 MockGrpcClientStub* getGrpcWakeupClientStub() { return mGrpcWakeupClientStub.get(); }
70
71 RemoteAccessService* getService() { return mService.get(); }
72
73 private:
74 std::unique_ptr<MockGrpcClientStub> mGrpcWakeupClientStub;
75 std::shared_ptr<RemoteAccessService> mService;
76};
77
78TEST_F(RemoteAccessServiceUnitTest, TestGetWakeupServiceName) {
79 std::string serviceName;
80
81 ScopedAStatus status = getService()->getWakeupServiceName(&serviceName);
82
83 EXPECT_TRUE(status.isOk());
84 EXPECT_EQ(serviceName, "com.google.vehicle.wakeup");
85}
86
87} // namespace remoteaccess
88} // namespace automotive
89} // namespace hardware
90} // namespace android