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