• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <binder/ProcessState.h>
23 #include <gtest/gtest.h>
24 #include <utils/String16.h>
25 
26 using android::sp;
27 using android::aidl::tests::BackendType;
28 using android::aidl::tests::ICppJavaTests;
29 using android::aidl::tests::ITestService;
30 
31 class AidlTest : public testing::Test {
32  public:
SetUp()33   void SetUp() override {
34     using android::OK;
35     using android::String16;
36     using android::waitForService;
37 
38     android::ProcessState::self()->setThreadPoolMaxThreadCount(1);
39     android::ProcessState::self()->startThreadPool();
40     service = waitForService<ITestService>(ITestService::descriptor);
41     ASSERT_NE(nullptr, service);
42 
43     sp<android::IBinder> ibinder;
44     auto status = service->GetCppJavaTests(&ibinder);
45     ASSERT_TRUE(status.isOk());
46     cpp_java_tests = android::interface_cast<ICppJavaTests>(ibinder);
47 
48     status = service->getBackendType(&backend);
49     ASSERT_TRUE(status.isOk()) << status;
50 
51     if (backend != BackendType::RUST && backend != BackendType::NDK) {
52       ASSERT_NE(cpp_java_tests, nullptr);
53     }
54   }
55 
56   BackendType backend;
57   sp<ITestService> service;
58   sp<ICppJavaTests> cpp_java_tests;
59 };
60