diff --git a/tests/exampls.cpp b/tests/exampls.cpp index 69cc17ed..6ae29410 100644 --- a/tests/exampls.cpp +++ b/tests/exampls.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "tpunit++.hpp" #include "fakeit.hpp" @@ -17,7 +19,7 @@ using namespace fakeit; using namespace std; using namespace tpunit; -/* + struct DemoTests : tpunit::TestFixture { @@ -25,10 +27,7 @@ struct DemoTests : tpunit::TestFixture( - TEST(DemoTests::on_other_invocations_verification), // - TEST(DemoTests::simple_inheritance_upcast), // - TEST(DemoTests::simple_inheritance_dynamic_down_cast) - // + TEST(DemoTests::test1) // ) { } @@ -40,122 +39,19 @@ struct DemoTests virtual void f2(){} }; - class Some2: public Some { - public: - virtual ~Some2(){} - virtual void f3(){} - }; - struct SomeInterface { virtual int foo(int) = 0; virtual int bar(int, int) = 0; }; - void basic_stubbing() { - } - - void basic_verification() { - }// - - struct A { - virtual int foo() = 0; - }; - - struct B : public A { - virtual int foo() override = 0; - }; - - struct C : public B - { - virtual int foo() override = 0; - }; - - void simple_inheritance_upcast() { - auto size = VTUtils::getVTSize(); - Mock cMock; - When(cMock[&C::foo]).AlwaysReturn(0); - - C& c = cMock.get(); - B& b = c; - A& a = b; - - ASSERT_EQUAL(0, c.foo()); - ASSERT_EQUAL(0, b.foo()); - ASSERT_EQUAL(0, a.foo()); - } - - void simple_inheritance_dynamic_down_cast() { - Mock cMock; - When(cMock[&C::foo]).AlwaysReturn(0); - A& a = cMock.get(); - B& b = dynamic_cast(a); - ASSERT_EQUAL(0, b.foo()); +#define Call(mock, method) \ + mock[&std::remove_reference::type::method] - C& c = dynamic_cast(a); - ASSERT_EQUAL(0, c.foo()); + void test1(){ + Mock m; + When(Call(m,foo)).Return(0); + ASSERT_EQUAL(0,m.get().foo(1)); } - void on_other_invocations_verification() { - Mock mock; - // Stub a method to return a value once - When(mock[&SomeInterface::foo]).Return(1); - - // Stub multiple return values (The next two lines do exactly the same) - When(mock[&SomeInterface::foo]).Return(1, 2, 3); - When(mock[&SomeInterface::foo]).Return(1).Return(2).Return(3); - - // Return the same value many times (56 in this example) - When(mock[&SomeInterface::foo]).Return(Times<56>::of(1)); - - // Return many values many times (First 100 calls will return 1, next 200 calls will return 2) - When(mock[&SomeInterface::foo]).Return(Times<100>::of(1), Times<200>::of(2)); - - // Always return a value (The next two lines do exactly the same) - When(mock[&SomeInterface::foo]).AlwaysReturn(1); - mock[&SomeInterface::foo] = 1; - - // Throw once - When(mock[&SomeInterface::foo]).Throw(exception()); - // Throw several times - When(mock[&SomeInterface::foo]).Throw(exception(), exception()); - // Throw many times - When(mock[&SomeInterface::foo]).Throw(Times<23>::of(exception())); - // Always throw - When(mock[&SomeInterface::foo]).AlwaysThrow(exception()); - - When(mock[&SomeInterface::foo]).AlwaysReturn(1); - - SomeInterface & i = mock.get(); - - // Production code: - i.foo(1); - i.foo(2); - i.foo(3); - - // Verify foo was invoked at least once. (The four lines do exactly the same) - Verify(mock[&SomeInterface::foo]); - Verify(mock[&SomeInterface::foo]).AtLeastOnce(); - Verify(mock[&SomeInterface::foo]).AtLeast(1); - Verify(mock[&SomeInterface::foo]).AtLeast(Times<1>()); - - // Verify foo was invoked at exactly 3 times. (The next two lines do exactly the same) - Verify(mock[&SomeInterface::foo]).Exactly(3); - Verify(mock[&SomeInterface::foo]).Exactly(Times<3>()); - - // Verify foo(1) was invoked exactly once - Verify(mock[&SomeInterface::foo].Using(1)).Once(); - Verify(mock[&SomeInterface::foo].Using(1)).Exactly(Once); - - // verify the actual invocation sequence contains two consecutive invocations of foo at least once. - Verify(mock[&SomeInterface::foo] * 2); - - // verify the actual invocation sequence contains two consecutive invocations of foo exactly once. - Verify(mock[&SomeInterface::foo] * 2).Exactly(Once); - - // verify the actual invocation sequence contains an invocation of foo(1) followed by bar(1,2) exactly twice. - Verify(mock[&SomeInterface::foo].Using(1) + mock[&SomeInterface::bar].Using(1,2)).Exactly(Times<2>()); - }// - } __DemoTests; -*/