/* * Copyright (c) 2014 Eran Pe'er. * * This program is made available under the terms of the MIT License. * * Created on Mar 10, 2014 */ #pragma once #include "fakeit/DomainObjects.hpp" #include "fakeit/MockImpl.hpp" #include "fakeit/ActualInvocation.hpp" #include "fakeit/Prototype.hpp" namespace fakeit { namespace internal { } template class Mock : public ActualInvocationsSource { MockImpl impl; public: virtual ~Mock() = default; static_assert(std::is_polymorphic::value, "Can only mock a polymorphic type"); Mock() : impl(Fakeit) { } explicit Mock(C &obj) : impl(Fakeit, obj) { } virtual C &get() { return impl.get(); } C &operator()() { return get(); } void Reset() { impl.reset(); } template::value>::type> DataMemberStubbingRoot Stub(DATA_TYPE C::* member, const arglist &... ctorargs) { return impl.stubDataMember(member, ctorargs...); } template::value && std::is_base_of::value>::type> MockingContext stub(R (T::*vMethod)(arglist...) const) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...) volatile) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...) const volatile) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...)) { return impl.template stubMethod(vMethod); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...) const) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...) volatile) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...) const volatile) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } template::value && std::is_base_of::value>::type> MockingContext stub(R(T::*vMethod)(arglist...)) { auto methodWithoutConstVolatile = reinterpret_cast(vMethod); return impl.template stubMethod(methodWithoutConstVolatile); } DtorMockingContext dtor() { return impl.stubDtor(); } void getActualInvocations(std::unordered_set &into) const override { impl.getActualInvocations(into); } }; }