• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 <AccessForVehicleProperty.h>
18 #include <AnnotationsForVehicleProperty.h>
19 #include <ChangeModeForVehicleProperty.h>
20 #include <EnumForVehicleProperty.h>
21 #include <VehicleHalTypes.h>
22 
23 #include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
24 #include <gmock/gmock.h>
25 #include <gtest/gtest.h>
26 #include <unordered_set>
27 
28 namespace aidl_vehicle = ::aidl::android::hardware::automotive::vehicle;
29 using aidl_vehicle::AllowedAccessForVehicleProperty;
30 using aidl_vehicle::AnnotationsForVehicleProperty;
31 using aidl_vehicle::ChangeModeForVehicleProperty;
32 using aidl_vehicle::DefaultAccessForVehicleProperty;
33 using aidl_vehicle::VehicleProperty;
34 using testing::IsEmpty;
35 
36 namespace {
37     template<class T>
doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty,T> annotationMap)38     bool doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty, T> annotationMap) {
39         for (const VehicleProperty& v : ::ndk::enum_range<VehicleProperty>()) {
40             std::string name = aidl_vehicle::toString(v);
41             if (name == "INVALID") {
42                 continue;
43             }
44             if (annotationMap.find(v) == annotationMap.end()) {
45                 return false;
46             }
47         }
48         return true;
49     }
50 
51 }  // namespace
52 
TEST(VehiclePropertyAnnotationCppTest,testChangeMode)53 TEST(VehiclePropertyAnnotationCppTest, testChangeMode) {
54     ASSERT_TRUE(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty))
55             << "Outdated annotation-generated AIDL files. Please run "
56             << "generate_annotation_enums.py to update.";
57 }
58 
TEST(VehiclePropertyAnnotationCppTest,testDefaultAccess)59 TEST(VehiclePropertyAnnotationCppTest, testDefaultAccess) {
60     ASSERT_TRUE(doesAnnotationMapContainsAllProps(DefaultAccessForVehicleProperty))
61             << "Outdated annotation-generated AIDL files. Please run "
62             << "generate_annotation_enums.py to update.";
63 }
64 
TEST(VehiclePropertyAnnotationCppTest,testAllowedAccess)65 TEST(VehiclePropertyAnnotationCppTest, testAllowedAccess) {
66     ASSERT_TRUE(doesAnnotationMapContainsAllProps(AllowedAccessForVehicleProperty))
67             << "Outdated annotation-generated AIDL files. Please run "
68             << "generate_annotation_enums.py to update.";
69 }
70 
TEST(VehiclePropertyAnnotationCppTest,testAnnotations)71 TEST(VehiclePropertyAnnotationCppTest, testAnnotations) {
72     for (const auto& [propertyId, annotations] : AnnotationsForVehicleProperty) {
73         ASSERT_THAT(annotations, Not(IsEmpty()))
74                 << "annotations set for property: " << aidl_vehicle::toString(propertyId)
75                 << " must not be empty";
76     }
77 }
78 
TEST(VehiclePropertyAnnotationCppTest,testSupportedEnums)79 TEST(VehiclePropertyAnnotationCppTest, testSupportedEnums) {
80     auto supportedEnums =
81             aidl_vehicle::getSupportedEnumValuesForProperty(VehicleProperty::INFO_FUEL_TYPE);
82     // We only listed part of the fuel type values here. This is enough to verify that the
83     // generated code is correct.
84     ASSERT_THAT(supportedEnums,
85                 ::testing::IsSupersetOf(
86                         {static_cast<int64_t>(aidl_vehicle::FuelType::FUEL_TYPE_UNLEADED),
87                          static_cast<int64_t>(aidl_vehicle::FuelType::FUEL_TYPE_LEADED),
88                          static_cast<int64_t>(aidl_vehicle::FuelType::FUEL_TYPE_DIESEL_1),
89                          static_cast<int64_t>(aidl_vehicle::FuelType::FUEL_TYPE_DIESEL_2)}));
90 }
91