Example #1
0
  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)");
  }
Example #2
0
 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"));
 }
Example #3
0
 void throwSpecializedExceptionManually()
 //this method is ONLY to test the constructor and no code example
 //normally exceptions should only be thrown by using the exception macro!
 {
 throw SpecializedTestException("test.cpp",155,"","");
 }