• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
18 #define android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
19 
20 #include <VehicleHalTypes.h>
21 
22 #include <aidl/android/hardware/automotive/vehicle/BnVehicleCallback.h>
23 #include <android-base/thread_annotations.h>
24 
25 #include <condition_variable>
26 #include <list>
27 #include <mutex>
28 #include <optional>
29 
30 namespace android {
31 namespace hardware {
32 namespace automotive {
33 namespace vehicle {
34 
35 template <class T>
pop(std::list<T> & items)36 std::optional<T> pop(std::list<T>& items) {
37     if (items.size() > 0) {
38         auto item = std::move(items.front());
39         items.pop_front();
40         return item;
41     }
42     return std::nullopt;
43 }
44 
45 // MockVehicleCallback is a mock VehicleCallback implementation that simply stores the results.
46 class MockVehicleCallback final
47     : public aidl::android::hardware::automotive::vehicle::BnVehicleCallback {
48   public:
49     ndk::ScopedAStatus onGetValues(
50             const aidl::android::hardware::automotive::vehicle::GetValueResults& results) override;
51     ndk::ScopedAStatus onSetValues(
52             const aidl::android::hardware::automotive::vehicle::SetValueResults& results) override;
53     ndk::ScopedAStatus onPropertyEvent(
54             const aidl::android::hardware::automotive::vehicle::VehiclePropValues&,
55             int32_t) override;
56     ndk::ScopedAStatus onPropertySetError(
57             const aidl::android::hardware::automotive::vehicle::VehiclePropErrors&) override;
58     ndk::ScopedAStatus onSupportedValueChange(
59             const std::vector<aidl::android::hardware::automotive::vehicle::PropIdAreaId>&)
60             override;
61 
62     // Test functions
63     std::optional<aidl::android::hardware::automotive::vehicle::GetValueResults>
64     nextGetValueResults();
65     std::optional<aidl::android::hardware::automotive::vehicle::SetValueResults>
66     nextSetValueResults();
67     std::optional<aidl::android::hardware::automotive::vehicle::VehiclePropValues>
68     nextOnPropertyEventResults();
69     size_t countOnPropertySetErrorResults();
70     std::optional<aidl::android::hardware::automotive::vehicle::VehiclePropErrors>
71     nextOnPropertySetErrorResults();
72     size_t countOnPropertyEventResults();
73     bool waitForSetValueResults(size_t size, size_t timeoutInNano);
74     bool waitForGetValueResults(size_t size, size_t timeoutInNano);
75     bool waitForOnPropertyEventResults(size_t size, size_t timeoutInNano);
76     bool waitForOnSupportedValueChange(size_t size, size_t timeoutInNano);
77     std::vector<aidl::android::hardware::automotive::vehicle::PropIdAreaId>
78     getOnSupportedValueChangePropIdAreaIds();
79 
80   private:
81     std::mutex mLock;
82     std::condition_variable mCond;
83     std::list<aidl::android::hardware::automotive::vehicle::GetValueResults> mGetValueResults
84             GUARDED_BY(mLock);
85     std::list<aidl::android::hardware::automotive::vehicle::SetValueResults> mSetValueResults
86             GUARDED_BY(mLock);
87     std::list<aidl::android::hardware::automotive::vehicle::VehiclePropValues>
88             mOnPropertyEventResults GUARDED_BY(mLock);
89     int32_t mSharedMemoryFileCount GUARDED_BY(mLock);
90     std::list<aidl::android::hardware::automotive::vehicle::VehiclePropErrors>
91             mOnPropertySetErrorResults GUARDED_BY(mLock);
92     std::vector<aidl::android::hardware::automotive::vehicle::PropIdAreaId>
93             mOnSupportedValueChangePropIdAreaIds GUARDED_BY(mLock);
94 };
95 
96 }  // namespace vehicle
97 }  // namespace automotive
98 }  // namespace hardware
99 }  // namespace android
100 
101 #endif  // android_hardware_automotive_vehicle_aidl_impl_vhal_test_MockVehicleCallback_H_
102