1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#ifndef IAM_MOCK_THREAD_HANDLER_H 16#define IAM_MOCK_THREAD_HANDLER_H 17 18#include <gmock/gmock.h> 19 20#include <future> 21 22#include "singleton.h" 23#include "thread_pool.h" 24 25#include "thread_handler.h" 26 27namespace OHOS { 28namespace UserIam { 29namespace FaceAuth { 30class MockThreadHandler final : public ThreadHandler { 31public: 32 MOCK_METHOD1(PostTask, void(const Task &task)); 33 MOCK_METHOD1(EnsureTask, void(const Task &task)); 34 static std::shared_ptr<ThreadHandler> InvokeDirectly() 35 { 36 using namespace testing; 37 auto handler = std::make_shared<MockThreadHandler>(); 38 EXPECT_CALL(*handler, PostTask(_)).Times(AnyNumber()); 39 ON_CALL(*handler, PostTask).WillByDefault([](const ThreadHandler::Task &f) { 40 if (f) { 41 f(); 42 } 43 }); 44 EXPECT_CALL(*handler, EnsureTask).Times(AnyNumber()); 45 return handler; 46 } 47}; 48} // namespace FaceAuth 49} // namespace UserIam 50} // namespace OHOS 51#endif // IAM_MOCK_THREAD_HANDLER_H