1 /*
2  * Copyright (C) 2020 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 #pragma once
18 
19 #include <android/aidl/tests/ICppJavaTests.h>
20 #include <android/aidl/tests/ITestService.h>
21 #include <binder/IServiceManager.h>
22 #include <gtest/gtest.h>
23 #include <utils/String16.h>
24 
25 using android::sp;
26 using android::aidl::tests::BackendType;
27 using android::aidl::tests::ICppJavaTests;
28 using android::aidl::tests::ITestService;
29 
30 class AidlTest : public testing::Test {
31  public:
SetUp()32   void SetUp() override {
33     using android::getService;
34     using android::OK;
35     using android::String16;
36 
37     ASSERT_EQ(OK, getService(ITestService::descriptor, &service));
38     ASSERT_NE(nullptr, service);
39 
40     sp<android::IBinder> ibinder;
41     auto status = service->GetCppJavaTests(&ibinder);
42     ASSERT_TRUE(status.isOk());
43     cpp_java_tests = android::interface_cast<ICppJavaTests>(ibinder);
44 
45     status = service->getBackendType(&backend);
46     ASSERT_TRUE(status.isOk()) << status;
47 
48     if (backend != BackendType::RUST) {
49       ASSERT_NE(cpp_java_tests, nullptr);
50     }
51   }
52 
53   BackendType backend;
54   sp<ITestService> service;
55   sp<ICppJavaTests> cpp_java_tests;
56 };
57