• 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 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <hidl/metadata.h>
20 
21 #include <optional>
22 
23 using ::android::HidlInterfaceMetadata;
24 using ::testing::ElementsAre;
25 
metadataForModule(const std::string & name)26 static std::optional<HidlInterfaceMetadata> metadataForModule(const std::string& name) {
27     for (const HidlInterfaceMetadata& info : HidlInterfaceMetadata::all()) {
28         if (name == info.name) return info;
29     }
30     return std::nullopt;
31 }
32 
TEST(AidlMetadata,HasTestInstances)33 TEST(AidlMetadata, HasTestInstances) {
34     const auto& info = metadataForModule("android.hardware.tests.bar@1.0::IBar");
35     ASSERT_NE(info, std::nullopt);
36     EXPECT_THAT(info->inherited, ElementsAre("android.hardware.tests.foo@1.0::IFoo"));
37 }
38 
TEST(AidlMetadata,HasPrebuiltInstances)39 TEST(AidlMetadata, HasPrebuiltInstances) {
40     for (const std::string& iface : {"hidl.metadata.test@1.0::IBar", "hidl.metadata.test@1.0::IBaz",
41                                      "hidl.metadata.test@1.0::IFoo"}) {
42         const auto& info = metadataForModule(iface);
43         ASSERT_NE(info, std::nullopt) << iface;
44     }
45 }
46