DelayedCallDriverTest.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "../DelayedCallDriver.h"
00025 #include "../BoundFunction.h"
00026 #include "../CallDriver.h"
00027 #include "../ExpectationDriver.h"
00028 #include "../ExpectedFunction.h"
00029 #include "Imports.cpp"
00030
00031 namespace Utils {
00032 namespace CalitkoMocks {
00033 namespace Testing {
00034
00036
00039 class DelayedCallDriverTest : public CppUnit::TestFixture
00040 {
00041 CPPUNIT_TEST_SUITE (DelayedCallDriverTest);
00042 CPPUNIT_TEST (testWillReturnOk);
00043 CPPUNIT_TEST_FAIL (testBoundFooWillCallNotCheckedFail);
00044 CPPUNIT_TEST (testWillCallOk);
00045 CPPUNIT_TEST_SUITE_END();
00046
00047 public:
00048 bool fooOk;
00049 int foo (int a) { fooOk = true; return a * 2; }
00050 typedef BoundFunction <DelayedCallDriverTest, int (int)> fooType;
00051 typedef CallDriver <fooType> CallDriverFoo;
00052 typedef ExpectedFunction <bool ()> ExpectedFoo;
00053 typedef ExpectationDriver <CallDriverFoo, ExpectedFoo> ExpectationDriverFoo;
00054
00056 void testWillReturnOk()
00057 {
00058 fooType delayedFoo (this, &DelayedCallDriverTest::foo, 1);
00059
00060
00061 DelayedCallDriver <ExpectationDriver <CallDriverFoo, ExpectedFoo>,
00062 fooType> driver (*(ExpectationDriverFoo *) 0, delayedFoo);
00063 fooOk = false;
00064 driver.willReturn (2);
00065 CPPUNIT_ASSERT (fooOk == false);
00066 }
00067
00069
00073 void testBoundFooWillCallNotCheckedFail()
00074 {
00075 typedef ExpectedFunction <void()> Foo;
00076
00077
00078 ExpectationsList <Foo> list;
00079 fooType delayedFoo (this, &DelayedCallDriverTest::foo, 1);
00080
00081
00082 DelayedCallDriver <ExpectationDriver <CallDriverFoo, ExpectedFoo>,
00083 fooType> driver (*(ExpectationDriverFoo *) 0, delayedFoo);
00084 auto_ptr <Foo> expectation (new Foo());
00085 ExpectationPair <Foo> pair (list, expectation);
00086
00087 driver.willCall (pair);
00088
00089 delayedFoo.willReturn (2);
00090 delayedFoo.call();
00091 }
00092
00094 void testWillCallOk()
00095 {
00096 typedef ExpectedFunction <void()> Foo;
00097
00098
00099 ExpectationsList <Foo> list;
00100 fooType delayedFoo (this, &DelayedCallDriverTest::foo, 1);
00101 typedef DelayedCallDriver <ExpectationDriver <CallDriverFoo,
00102 ExpectedFoo>, fooType> DelayedCallDriverType;
00103
00104
00105 DelayedCallDriverType driver (*(ExpectationDriverFoo *) 0, delayedFoo);
00106 auto_ptr <Foo> expectation (new Foo());
00107 ExpectationPair <Foo> pair (list, expectation);
00108
00109 ExpectationDriver <DelayedCallDriverType, ExpectedFunction <void ()> >
00110 newExpectation = driver.willCall (pair);
00111 }
00112 };
00113
00114 CPPUNIT_TEST_SUITE_REGISTRATION (DelayedCallDriverTest);
00115
00116 }
00117 }
00118 }