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 <ChangeModeForVehicleProperty.h>
19 
20 #include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h>
21 #include <gtest/gtest.h>
22 #include <unordered_set>
23 
24 namespace aidl_vehicle = ::aidl::android::hardware::automotive::vehicle;
25 using aidl_vehicle::AccessForVehicleProperty;
26 using aidl_vehicle::ChangeModeForVehicleProperty;
27 using aidl_vehicle::VehicleProperty;
28 
29 namespace {
30     template<class T>
doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty,T> annotationMap)31     bool doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty, T> annotationMap) {
32         for (const VehicleProperty& v : ::ndk::enum_range<VehicleProperty>()) {
33             std::string name = aidl_vehicle::toString(v);
34             if (name == "INVALID") {
35                 continue;
36             }
37             if (annotationMap.find(v) == annotationMap.end()) {
38                 return false;
39             }
40         }
41         return true;
42     }
43 
44 }  // namespace
45 
TEST(VehiclePropertyAnnotationCppTest,testChangeMode)46 TEST(VehiclePropertyAnnotationCppTest, testChangeMode) {
47     ASSERT_TRUE(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty))
48             << "Outdated annotation-generated AIDL files. Please run "
49             << "generate_annotation_enums.py to update.";
50 }
51 
TEST(VehiclePropertyAnnotationCppTest,testAccess)52 TEST(VehiclePropertyAnnotationCppTest, testAccess) {
53     ASSERT_TRUE(doesAnnotationMapContainsAllProps(AccessForVehicleProperty))
54             << "Outdated annotation-generated AIDL files. Please run "
55             << "generate_annotation_enums.py to update.";
56 }
57