[Mockpp-commits] mockpp/mockpp/tests AssertMo_test.cpp,1.29,1.30 Makefile.am,1.96,1.97 NoException_t
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-12-23 22:03:39
|
Update of /cvsroot/mockpp/mockpp/mockpp/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19465/mockpp/tests Modified Files: AssertMo_test.cpp Makefile.am NoException_test.cpp VerifyingTestCaller_test.cpp mock_test.cpp Log Message: forward failures without execptions Index: AssertMo_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/AssertMo_test.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- AssertMo_test.cpp 11 Dec 2005 20:03:44 -0000 1.29 +++ AssertMo_test.cpp 23 Dec 2005 22:03:30 -0000 1.30 @@ -459,7 +459,7 @@ #ifndef MOCKPP_NO_EXCEPTIONS static void do_a_throw(unsigned val) { - mockpp::forwardMalfunctionData((unsigned) val); + MOCKPP_THROW((unsigned) val); } #endif Index: VerifyingTestCaller_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/VerifyingTestCaller_test.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- VerifyingTestCaller_test.cpp 11 Dec 2005 20:03:44 -0000 1.13 +++ VerifyingTestCaller_test.cpp 23 Dec 2005 22:03:30 -0000 1.14 @@ -125,7 +125,7 @@ void thrower() { - mockpp::forwardMalfunctionData(1); + MOCKPP_THROW(1); } }; Index: Makefile.am =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/Makefile.am,v retrieving revision 1.96 retrieving revision 1.97 diff -u -d -r1.96 -r1.97 --- Makefile.am 11 Dec 2005 20:11:33 -0000 1.96 +++ Makefile.am 23 Dec 2005 22:03:30 -0000 1.97 @@ -7,9 +7,9 @@ AM_LDFLAGS = $(all_libraries) -#mock_test_win32 +#mock_test_win32 +#mock_test_qt mock_test_x11 check_PROGRAMS = mock_test \ - mock_test_qt mock_test_x11 \ jmock_test \ readability_test check_inst Index: mock_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/mock_test.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- mock_test.cpp 17 Dec 2005 18:38:48 -0000 1.29 +++ mock_test.cpp 23 Dec 2005 22:03:30 -0000 1.30 @@ -29,7 +29,7 @@ // Expected number of tests: // 8 cppunit specific -// mock_test : 511 +// mock_test : 511 // jmock_test: 199 #include <mockpp/mockpp.h> // always first @@ -167,6 +167,8 @@ int main(int argc, char **argv) { +// mockpp::setAssertionFailedForwarder(0); + int ret = 1; std::cout << "starting tests..\n"; Index: NoException_test.cpp =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/tests/NoException_test.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- NoException_test.cpp 11 Dec 2005 20:03:44 -0000 1.3 +++ NoException_test.cpp 23 Dec 2005 22:03:30 -0000 1.4 @@ -27,11 +27,35 @@ * ***************************************************************************/ +#undef MOCKPP_THROW +#define MOCKPP_THROW(x) storeMalfunctionData(x) + +#undef MOCKPP_RETHROW +#define MOCKPP_RETHROW storeMalfunctionData("unexpected rethrow") + +#undef MOCKPP_NO_EXCEPTIONS +#define MOCKPP_NO_EXCEPTIONS + +#define MOCKPP_ENABLE_DEFAULT_FORMATTER + + #include <mockpp/mockpp.h> // always first +#include <iostream> + +#include <mockpp/ExpectationValue.h> +#include <mockpp/Throwable.h> + +#include <mockpp/util/AssertMo.h> + +#include <mockpp/compat/Assert.h> +#include <mockpp/compat/Exception.h> + #include "SelectFramework.h" +namespace { + class NoException_test MOCKPP_DERIVE_PUBLIC_UNITFRAMEWORK { @@ -52,6 +76,9 @@ public: void test_invoke(); + + virtual void setUp(); + virtual void tearDown(); }; @@ -67,10 +94,83 @@ #endif // frameworks +mockpp::String bad_data; + + +struct MyStruct { + MyStruct(int v) + : val(v){} + + MyStruct() + : val(0){} + + bool operator==(const MyStruct &o) const + { + return val == o.val; + } + + int val; +}; + +struct OtherStruct {}; + + +template <class T> +void storeMalfunctionData(const T & /* dummy */) +{ + std::cout << "dummy\n"; + bad_data = MOCKPP_PCHAR("unknown exception occured"); +} + + +template <> +void storeMalfunctionData(const MyStruct &e) +{ + std::cout << "mystruct\n"; + bad_data = MOCKPP_PCHAR("MyStruct"); +} + + +template <> +void storeMalfunctionData(const mockpp::AssertionFailedError &e) +{ + std::cout << mockpp::getLatin1(e.getMessage()).c_str() << std::endl; + bad_data = e.getMessage(); +} + + +void NoException_test::setUp() +{ + mockpp::setAssertionFailedForwarder(storeMalfunctionData<mockpp::AssertionFailedError>); +} + + +void NoException_test::tearDown() +{ + mockpp::setAssertionFailedForwarder(0); +} + void NoException_test::test_invoke() { + mockpp::ThrowableItem it; + it.take(MyStruct()); + it.get()->throw_me(); + MOCKPP_ASSERT_EQUALS(bad_data, mockpp::String(MOCKPP_PCHAR("MyStruct"))); + + it.take(OtherStruct()); + it.get()->throw_me(); + MOCKPP_ASSERT_EQUALS(bad_data, mockpp::String(MOCKPP_PCHAR("unknown exception occured"))); + + mockpp::ExpectationValue<MyStruct> ec (MOCKPP_PCHAR("verifyValue"), 0); + ec.setExpected(MyStruct(3)); + ec.setActual(MyStruct(4)); + + mockpp::setAssertionFailedForwarder(0); + + MOCKPP_ASSERT_EQUALS(bad_data, mockpp::String(MOCKPP_PCHAR("unknown exception occured"))); } +} // anon namespace |