/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include using aidl::android::aidl::tests::INamedCallback; using aidl::android::aidl::tests::ITestService; using testing::Eq; struct AidlTest : testing::Test { template std::shared_ptr getService() { ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_getService(T::descriptor)); return T::fromBinder(binder); } }; TEST_F(AidlTest, InterfaceExchange) { auto service = getService(); std::vector names = {"Larry", "Curly", "Moe"}; for (size_t i = 0; i < names.size(); i++) { std::shared_ptr got; ASSERT_TRUE(service->GetOtherTestService(names[i], &got).isOk()); std::string name; ASSERT_TRUE(got->GetName(&name).isOk()); ASSERT_THAT(name, Eq(names[i])); } { std::vector> got; ASSERT_TRUE(service->GetInterfaceArray(names, &got).isOk()); bool verified = false; ASSERT_TRUE(service->VerifyNamesWithInterfaceArray(got, names, &verified).isOk()); ASSERT_TRUE(verified); for (size_t i = 0; i < names.size(); i++) { std::string name; ASSERT_TRUE(got[i]->GetName(&name).isOk()); ASSERT_THAT(name, Eq(names[i])); } } { std::vector> names = {"Larry", std::nullopt, "Moe"}; std::optional>> got; ASSERT_TRUE(service->GetNullableInterfaceArray(names, &got).isOk()); bool verified = false; ASSERT_TRUE(service->VerifyNamesWithNullableInterfaceArray(got, names, &verified).isOk()); ASSERT_TRUE(verified); ASSERT_TRUE(got.has_value()); for (size_t i = 0; i < names.size(); i++) { if (names[i].has_value()) { ASSERT_NE(got->at(i).get(), nullptr); std::string name; ASSERT_TRUE(got->at(i)->GetName(&name).isOk()); ASSERT_THAT(name, Eq(names[i].value())); } else { ASSERT_EQ(got->at(i).get(), nullptr); } } } { std::vector> names = {"Larry", std::nullopt, "Moe"}; std::optional>> got; ASSERT_TRUE(service->GetInterfaceList(names, &got).isOk()); bool verified = false; ASSERT_TRUE(service->VerifyNamesWithInterfaceList(got, names, &verified).isOk()); ASSERT_TRUE(verified); ASSERT_TRUE(got.has_value()); for (size_t i = 0; i < names.size(); i++) { if (names[i].has_value()) { ASSERT_NE(got->at(i).get(), nullptr); std::string name; ASSERT_TRUE(got->at(i)->GetName(&name).isOk()); ASSERT_THAT(name, Eq(names[i].value())); } else { ASSERT_EQ(got->at(i).get(), nullptr); } } } }