1 /** 2 * Copyright (c) 2020, 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_MOCKWATCHDOGSERVICEHELPER_H_ 18 #define CPP_WATCHDOG_SERVER_TESTS_MOCKWATCHDOGSERVICEHELPER_H_ 19 20 #include "WatchdogProcessService.h" 21 #include "WatchdogServiceHelper.h" 22 23 #include <aidl/android/automotive/watchdog/TimeoutLength.h> 24 #include <aidl/android/automotive/watchdog/internal/ICarWatchdogServiceForSystem.h> 25 #include <aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.h> 26 #include <android-base/result.h> 27 #include <binder/Status.h> 28 #include <gmock/gmock.h> 29 #include <utils/StrongPointer.h> 30 31 namespace android { 32 namespace automotive { 33 namespace watchdog { 34 35 class MockWatchdogServiceHelper : public WatchdogServiceHelperInterface { 36 public: MockWatchdogServiceHelper()37 MockWatchdogServiceHelper() { 38 ON_CALL(*this, isServiceConnected()).WillByDefault(::testing::Return(false)); 39 ON_CALL(*this, requestAidlVhalPid()).WillByDefault([]() { 40 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); 41 }); 42 } ~MockWatchdogServiceHelper()43 ~MockWatchdogServiceHelper() {} 44 45 MOCK_METHOD(bool, isServiceConnected, (), (override)); 46 MOCK_METHOD(android::base::Result<void>, init, 47 (const android::sp<WatchdogProcessServiceInterface>&), (override)); 48 MOCK_METHOD( 49 ndk::ScopedAStatus, registerService, 50 (const std::shared_ptr< 51 aidl::android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>&), 52 (override)); 53 MOCK_METHOD( 54 ndk::ScopedAStatus, unregisterService, 55 (const std::shared_ptr< 56 aidl::android::automotive::watchdog::internal::ICarWatchdogServiceForSystem>&), 57 (override)); 58 MOCK_METHOD(void, handleBinderDeath, (void*), (override)); 59 MOCK_METHOD(ndk::ScopedAStatus, checkIfAlive, 60 (const ndk::SpAIBinder&, int32_t, 61 aidl::android::automotive::watchdog::TimeoutLength), 62 (const, override)); 63 MOCK_METHOD(ndk::ScopedAStatus, prepareProcessTermination, (const ndk::SpAIBinder&), 64 (override)); 65 MOCK_METHOD(ndk::ScopedAStatus, getPackageInfosForUids, 66 (const std::vector<int32_t>&, const std::vector<std::string>&, 67 std::vector<aidl::android::automotive::watchdog::internal::PackageInfo>*), 68 (const, override)); 69 MOCK_METHOD(ndk::ScopedAStatus, resetResourceOveruseStats, (const std::vector<std::string>&), 70 (const, override)); 71 MOCK_METHOD(ndk::ScopedAStatus, onLatestResourceStats, 72 (const std::vector<aidl::android::automotive::watchdog::internal::ResourceStats>&), 73 (const, override)); 74 MOCK_METHOD(ndk::ScopedAStatus, requestAidlVhalPid, (), (const, override)); 75 MOCK_METHOD(ndk::ScopedAStatus, requestTodayIoUsageStats, (), (const, override)); 76 MOCK_METHOD(void, terminate, (), (override)); 77 }; 78 79 } // namespace watchdog 80 } // namespace automotive 81 } // namespace android 82 83 #endif // CPP_WATCHDOG_SERVER_TESTS_MOCKWATCHDOGSERVICEHELPER_H_ 84