static void TestExceptionMessageStream() { //##### this method is ONLY to test the streaming operators of the exceptions and //##### NO code example. Please do not instantiate exceptions by yourself in normal code! //##### Normally exceptions should only be thrown by using the exception macro! mitk::Exception myException = mitk::Exception("testfile.cpp", 111, "testmessage"); myException << " and additional stream"; MITK_TEST_CONDITION_REQUIRED(myException.GetDescription() == std::string("testmessage and additional stream"), "Testing mitkException message stream (adding std::string)"); myException.SetDescription("testmessage2"); myException << ' ' << 'a' << 'n' << 'd' << ' ' << 'c' << 'h' << 'a' << 'r' << 's'; MITK_TEST_CONDITION_REQUIRED(myException.GetDescription() == std::string("testmessage2 and chars"), "Testing mitkException message stream (adding single chars)"); myException.SetDescription("testmessage3"); myException << myException; // adding the object itself makes no sense but should work MITK_TEST_CONDITION_REQUIRED(myException.GetDescription() != std::string(""), "Testing mitkException message stream (adding object)"); SpecializedTestException mySpecializedException = SpecializedTestException("testfile.cpp", 111, "testmessage", "test"); mySpecializedException << " and additional stream"; MITK_TEST_CONDITION_REQUIRED( mySpecializedException.GetDescription() == std::string("testmessage and additional stream"), "Testing specialized exception message stream (adding std::string)"); }
void TestSpecializedExceptionMessageStreamAddingString() { SpecializedTestException mySpecializedException = SpecializedTestException("testfile.cpp", 111, "testmessage", "test"); mySpecializedException << " and additional stream"; CPPUNIT_ASSERT_MESSAGE("Testing specialized exception message stream (adding std::string)", mySpecializedException.GetDescription() == std::string("testmessage and additional stream")); }