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 CPP_WATCHDOG_SERVER_TESTS_MOCKRESOURCEOVERUSELISTENER_H_ 18 #define CPP_WATCHDOG_SERVER_TESTS_MOCKRESOURCEOVERUSELISTENER_H_ 19 20 #include "MockBinder.h" 21 22 #include <android/automotive/watchdog/BnResourceOveruseListener.h> 23 #include <android/automotive/watchdog/ResourceOveruseStats.h> 24 #include <binder/Status.h> 25 #include <gmock/gmock.h> 26 27 namespace android { 28 namespace automotive { 29 namespace watchdog { 30 31 class MockResourceOveruseListener : public IResourceOveruseListenerDefault { 32 public: MockResourceOveruseListener()33 MockResourceOveruseListener() : mMockBinder(new MockBinder()) { 34 ON_CALL(*this, onAsBinder()).WillByDefault(::testing::Return(mMockBinder.get())); 35 } ~MockResourceOveruseListener()36 ~MockResourceOveruseListener() { mMockBinder.clear(); } 37 38 MOCK_METHOD(android::IBinder*, onAsBinder, (), (override)); 39 MOCK_METHOD(android::binder::Status, onOveruse, (const ResourceOveruseStats&), (override)); 40 injectLinkToDeathFailure()41 void injectLinkToDeathFailure() { 42 EXPECT_CALL(*mMockBinder, linkToDeath(::testing::_, nullptr, 0)) 43 .WillOnce(::testing::Return(android::binder::Status::EX_ILLEGAL_STATE)); 44 } injectUnlinkToDeathFailure()45 void injectUnlinkToDeathFailure() { 46 EXPECT_CALL(*mMockBinder, unlinkToDeath(::testing::_, nullptr, 0, nullptr)) 47 .WillOnce(::testing::Return(android::binder::Status::EX_ILLEGAL_STATE)); 48 } 49 50 private: 51 android::sp<MockBinder> mMockBinder; 52 }; 53 54 } // namespace watchdog 55 } // namespace automotive 56 } // namespace android 57 58 #endif // CPP_WATCHDOG_SERVER_TESTS_MOCKRESOURCEOVERUSELISTENER_H_ 59