Utils: Add backtrace to exception message in SENF_DEBUG builds
[senf.git] / Utils / Exception.test.cc
index 314cc41..9a29f71 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 
 #include "../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
+#include <boost/format.hpp>
+#include <errno.h>
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
 BOOST_AUTO_UNIT_TEST(errnoException)
-{}
+{
+    try {
+        try {
+            throw senf::SystemException("::open()", ENOENT) << "\nmore";
+        }
+        catch(senf::Exception & e) {
+            e << "\nx=" << 1 << boost::format("\ny=%d") % 2;
+            throw;
+        }
+    }
+    catch (senf::SystemException & e) {
+        BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT );
+        BOOST_CHECK_EQUAL( e.errorString(), "No such file or directory" );
+        std::string what (e.what());
+        std::string::size_type pos (what.find("-- \n"));
+        if (pos != std::string::npos)
+            what = std::string(what, pos+4);
+        BOOST_CHECK_EQUAL( what, "[No such file or directory] ::open()\nmore\nx=1\ny=2" );
+    }
+}
 
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_