/* * Copyright (c) Facebook, Inc. and its affiliates. * * Licensed under the Apache License Version 2.0 with LLVM Exceptions * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://llvm.org/LICENSE.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or bodyied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include namespace unifex_test { template struct mock_receiver_body_base_impl; template struct mock_receiver_body_base_impl { MOCK_METHOD(void, set_value, (), (noexcept(NoExcept))); }; template struct mock_receiver_body_base_impl { MOCK_METHOD(void, set_value, (T), (noexcept(NoExcept))); }; template struct mock_receiver_body_base_impl { MOCK_METHOD(void, set_value, (T, U), (noexcept(NoExcept))); }; template struct mock_receiver_body_base_impl { MOCK_METHOD(void, set_value, (T, U, V), (noexcept(NoExcept))); }; template struct mock_receiver_body_base; template struct mock_receiver_body_base { using type = mock_receiver_body_base_impl; }; template struct mock_receiver_body_base { using type = mock_receiver_body_base_impl; }; template using mock_receiver_body_base_t = typename mock_receiver_body_base::type; template struct mock_receiver_body_impl : Bases... { using Bases::gmock_set_value...; using Bases::set_value...; MOCK_METHOD(void, set_error, (std::exception_ptr), (noexcept)); MOCK_METHOD(void, set_done, (), (noexcept)); }; template using mock_receiver_body = mock_receiver_body_impl...>; template struct mock_receiver { private: std::shared_ptr> body_ = std::make_shared>(); public: template auto set_value(T&&... ts) noexcept(noexcept(body_->set_value((T&&)ts...))) -> decltype(body_->set_value((T&&)ts...)) { body_->set_value((T&&)ts...); } void set_error(std::exception_ptr eptr) noexcept { body_->set_error(std::move(eptr)); } void set_done() noexcept { body_->set_done(); } mock_receiver_body& operator*() noexcept { return *body_; } const mock_receiver_body& operator*() const noexcept { return *body_; } }; } // namespace unifex_test