Home | History | Annotate | Download | only in libvehiclenetwork-native-test
      1 /*
      2  * Copyright (C) 2015 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_VEHICLE_HAL_MOCK_H
     18 #define ANDROID_VEHICLE_HAL_MOCK_H
     19 
     20 #include <IVehicleNetworkHalMock.h>
     21 
     22 extern "C" {
     23 vehicle_prop_config_t const * getTestProperties();
     24 int getNumTestProperties();
     25 };
     26 
     27 namespace android {
     28 
     29 class VehicleHalMock : public BnVehicleNetworkHalMock {
     30 public:
     31     VehicleHalMock() {
     32         mProperties = new VehiclePropertiesHolder(false /* deleteConfigsInDestructor */);
     33         vehicle_prop_config_t const * properties = getTestProperties();
     34         for (int i = 0; i < getNumTestProperties(); i++) {
     35             mProperties->getList().push_back(properties + i);
     36         }
     37     };
     38 
     39     virtual ~VehicleHalMock() {};
     40 
     41     virtual sp<VehiclePropertiesHolder> onListProperties() {
     42         return mProperties;
     43     };
     44 
     45     virtual status_t onPropertySet(const vehicle_prop_value_t& /*value*/) {
     46         return NO_ERROR;
     47     };
     48 
     49     virtual status_t onPropertyGet(vehicle_prop_value_t* /*value*/) {
     50         return NO_ERROR;
     51     };
     52 
     53     virtual status_t onPropertySubscribe(int32_t /*property*/, float /*sampleRate*/,
     54             int32_t /*zones*/) {
     55         return NO_ERROR;
     56     };
     57 
     58     virtual void onPropertyUnsubscribe(int32_t /*property*/) {
     59     };
     60 
     61     bool isTheSameProperties(sp<VehiclePropertiesHolder>& list) {
     62         if (mProperties->getList().size() != list->getList().size()) {
     63             return false;
     64         }
     65         auto l = mProperties->getList().begin();
     66         auto r = list->getList().begin();
     67         while (l != mProperties->getList().end() && r != list->getList().end()) {
     68             if (!VehiclePropertiesUtil::isTheSame(**l, **r)) {
     69                 return false;
     70             }
     71             l++;
     72             r++;
     73         }
     74         return true;
     75     }
     76 
     77 private:
     78     sp<VehiclePropertiesHolder> mProperties;
     79 
     80 };
     81 
     82 }; // namespace android
     83 #endif /* ANDROID_VEHICLE_HAL_MOCK_H */
     84