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 <aidl/metadata.h>
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 
21 #include <optional>
22 
23 using ::android::AidlInterfaceMetadata;
24 using ::testing::ElementsAre;
25 
metadataForModule(const std::string & name)26 static std::optional<AidlInterfaceMetadata> metadataForModule(const std::string& name) {
27   for (const AidlInterfaceMetadata& info : AidlInterfaceMetadata::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("test-piece-1");
35   ASSERT_NE(info, std::nullopt);
36   EXPECT_EQ(info->stability, "");
37   EXPECT_THAT(info->types,
38               ElementsAre("some_package.IFoo", "some_package.Thing",
39                           "some_package.sub_package.IFoo", "some_package.sub_package.SubThing"));
40   EXPECT_THAT(info->hashes, ElementsAre("13e24b2fac6a979971819fba2ab0d6d7c4182122",
41                                         "dc2a9292847e43b4360bb183f7491f0e9895eaa9",
42                                         "54f935920ab0934c242145cf00f9852ae3f5a63e",
43                                         "be5dd6bf9c9000ee053621f118b7d6a7cfd1e79e"));
44   EXPECT_THAT(info->versions, ElementsAre(1, 2, 3, 4));
45   EXPECT_EQ(info->has_development, false);
46 }
47 
TEST(AidlMetadata,HasTestInstancesNoDevelopment)48 TEST(AidlMetadata, HasTestInstancesNoDevelopment) {
49   const auto& info = metadataForModule("test-piece-2");
50   ASSERT_NE(info, std::nullopt);
51   EXPECT_EQ(info->stability, "");
52   EXPECT_THAT(info->types, ElementsAre("INoPackage", "some_package.IBar"));
53   EXPECT_THAT(info->hashes, ElementsAre("c544902ab8a1d2e72ae9396032ba113e9b9698c4",
54                                         "fcd36db451cdbeeb049833fd7f499a987acf3930"));
55   EXPECT_THAT(info->versions, ElementsAre(1));
56   EXPECT_EQ(info->has_development, false);
57 }
58 
TEST(AidlMetadata,UseUnfrozen)59 TEST(AidlMetadata, UseUnfrozen) {
60   const auto& info = metadataForModule("tests-unfrozen-vendor");
61   EXPECT_TRUE(info->use_unfrozen);
62 }
63