aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testUtils.cpp')
-rw-r--r--tests/testUtils.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/testUtils.cpp b/tests/testUtils.cpp
index ee17c923..36455cff 100644
--- a/tests/testUtils.cpp
+++ b/tests/testUtils.cpp
@@ -187,3 +187,61 @@ vmime::ref <vmime::net::timeoutHandler> testTimeoutHandlerFactory::create()
return vmime::create <testTimeoutHandler>();
}
+
+
+// Exception helper
+std::ostream& operator<<(std::ostream& os, const vmime::exception& e)
+{
+ os << "* vmime::exceptions::" << e.name() << std::endl;
+ os << " what = " << e.what() << std::endl;
+
+ // More information for special exceptions
+ if (dynamic_cast <const vmime::exceptions::command_error*>(&e))
+ {
+ const vmime::exceptions::command_error& cee =
+ dynamic_cast <const vmime::exceptions::command_error&>(e);
+
+ os << " command = " << cee.command() << std::endl;
+ os << " response = " << cee.response() << std::endl;
+ }
+
+ if (dynamic_cast <const vmime::exceptions::invalid_response*>(&e))
+ {
+ const vmime::exceptions::invalid_response& ir =
+ dynamic_cast <const vmime::exceptions::invalid_response&>(e);
+
+ os << " response = " << ir.response() << std::endl;
+ }
+
+ if (dynamic_cast <const vmime::exceptions::connection_greeting_error*>(&e))
+ {
+ const vmime::exceptions::connection_greeting_error& cgee =
+ dynamic_cast <const vmime::exceptions::connection_greeting_error&>(e);
+
+ os << " response = " << cgee.response() << std::endl;
+ }
+
+ if (dynamic_cast <const vmime::exceptions::authentication_error*>(&e))
+ {
+ const vmime::exceptions::authentication_error& aee =
+ dynamic_cast <const vmime::exceptions::authentication_error&>(e);
+
+ os << " response = " << aee.response() << std::endl;
+ }
+
+ if (dynamic_cast <const vmime::exceptions::filesystem_exception*>(&e))
+ {
+ const vmime::exceptions::filesystem_exception& fse =
+ dynamic_cast <const vmime::exceptions::filesystem_exception&>(e);
+
+ os << " path = " << vmime::platform::getHandler()->
+ getFileSystemFactory()->pathToString(fse.path()) << std::endl;
+ }
+
+ if (e.other() != NULL)
+ os << *e.other();
+
+ return os;
+}
+
+