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 #pragma once 18 19 #include "MockSubscriptionClient.h" 20 21 #include <gmock/gmock.h> 22 23 #include <AidlHalPropValue.h> 24 25 namespace android { 26 namespace automotive { 27 namespace watchdog { 28 29 class MockVhalClient : public android::frameworks::automotive::vhal::IVhalClient { 30 public: 31 template <class T> 32 using VhalClientResult = android::frameworks::automotive::vhal::VhalClientResult<T>; 33 MockVhalClient(const std::shared_ptr<MockVehicle> & vehicle)34 explicit MockVhalClient(const std::shared_ptr<MockVehicle>& vehicle) { 35 mVehicle = vehicle; 36 ON_CALL(*this, isAidlVhal()).WillByDefault(testing::Return(true)); 37 } ~MockVhalClient()38 ~MockVhalClient() { mVehicle.reset(); } 39 40 MOCK_METHOD(bool, isAidlVhal, (), (override)); 41 42 std::unique_ptr<android::frameworks::automotive::vhal::ISubscriptionClient> getSubscriptionClient(std::shared_ptr<android::frameworks::automotive::vhal::ISubscriptionCallback> callback)43 getSubscriptionClient( 44 std::shared_ptr<android::frameworks::automotive::vhal::ISubscriptionCallback> callback) 45 override { 46 return std::make_unique<MockSubscriptionClient>(mVehicle, callback); 47 } 48 createHalPropValue(int32_t propId)49 std::unique_ptr<android::frameworks::automotive::vhal::IHalPropValue> createHalPropValue( 50 int32_t propId) override { 51 return std::make_unique<android::frameworks::automotive::vhal::AidlHalPropValue>(propId); 52 } 53 createHalPropValue(int32_t propId,int32_t areaId)54 std::unique_ptr<android::frameworks::automotive::vhal::IHalPropValue> createHalPropValue( 55 int32_t propId, int32_t areaId) override { 56 return std::make_unique<android::frameworks::automotive::vhal::AidlHalPropValue>(propId, 57 areaId); 58 } 59 60 MOCK_METHOD(void, getValue, 61 (const android::frameworks::automotive::vhal::IHalPropValue&, 62 std::shared_ptr<GetValueCallbackFunc>), 63 (override)); 64 MOCK_METHOD( 65 VhalClientResult<std::unique_ptr<android::frameworks::automotive::vhal::IHalPropValue>>, 66 getValueSync, (const android::frameworks::automotive::vhal::IHalPropValue&), 67 (override)); 68 MOCK_METHOD(void, setValue, 69 (const android::frameworks::automotive::vhal::IHalPropValue&, 70 std::shared_ptr<SetValueCallbackFunc>), 71 (override)); 72 MOCK_METHOD(VhalClientResult<void>, setValueSync, 73 (const android::frameworks::automotive::vhal::IHalPropValue&), (override)); 74 MOCK_METHOD(VhalClientResult<void>, addOnBinderDiedCallback, 75 (std::shared_ptr<OnBinderDiedCallbackFunc>), (override)); 76 MOCK_METHOD(VhalClientResult<void>, removeOnBinderDiedCallback, 77 (std::shared_ptr<OnBinderDiedCallbackFunc>), (override)); 78 MOCK_METHOD(VhalClientResult<std::vector< 79 std::unique_ptr<android::frameworks::automotive::vhal::IHalPropConfig>>>, 80 getAllPropConfigs, (), (override)); 81 MOCK_METHOD(VhalClientResult<std::vector< 82 std::unique_ptr<android::frameworks::automotive::vhal::IHalPropConfig>>>, 83 getPropConfigs, (std::vector<int32_t>), (override)); 84 85 private: 86 std::shared_ptr<MockVehicle> mVehicle; 87 }; 88 89 } // namespace watchdog 90 } // namespace automotive 91 } // namespace android 92