| 
									
										
										
										
											2004-08-28 16:21:25 +00:00
										 |  |  | /** @file
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $Id$ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $Date$ | 
					
						
							|  |  |  |     $Author$ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @copy © Marc Wäckerlin | 
					
						
							|  |  |  |     @license LGPL, see file <a href="license.html">COPYING</a> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $Log$ | 
					
						
							|  |  |  |     Revision 1.2  2004/08/28 16:21:25  marc | 
					
						
							|  |  |  |     mrw-c++-0.92 (mrw) | 
					
						
							| 
									
										
										
										
											2011-12-10 11:39:09 +00:00
										 |  |  |     - new file: version.cxx | 
					
						
							| 
									
										
										
										
											2004-08-28 16:21:25 +00:00
										 |  |  |     - new file header for all sources | 
					
						
							|  |  |  |     - work around warning in mrw::auto<T> | 
					
						
							|  |  |  |     - possibility to compile without log4cxx | 
					
						
							|  |  |  |     - work around bugs in demangle.h and libiberty.h | 
					
						
							|  |  |  |     - corrections in documentation | 
					
						
							|  |  |  |     - added simple tracing mechanism | 
					
						
							|  |  |  |     - more warnings | 
					
						
							|  |  |  |     - small corrections in Auto<>::Free and a new test for it | 
					
						
							|  |  |  |     - possibility to compile without stack trace | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2011-12-10 11:39:09 +00:00
										 |  |  | #include <mrw/exception.hxx>
 | 
					
						
							| 
									
										
										
										
											2004-04-23 16:03:29 +00:00
										 |  |  | #include <log4cxx/basicconfigurator.h>
 | 
					
						
							|  |  |  | #include <cppunit/TestFixture.h>
 | 
					
						
							|  |  |  | #include <cppunit/ui/text/TestRunner.h>
 | 
					
						
							|  |  |  | #include <cppunit/extensions/HelperMacros.h>
 | 
					
						
							|  |  |  | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-11 14:24:33 +00:00
										 |  |  | #include <cppunit/XmlOutputter.h>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							| 
									
										
										
										
											2004-04-23 16:03:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace mrw { | 
					
						
							|  |  |  |   class AutoExcLog4CxxTest: public CppUnit::TestFixture { | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     bool enter_unexpectedThrow; | 
					
						
							|  |  |  |     bool exit_unexpectedThrow; | 
					
						
							|  |  |  |     bool enter_passUnexpected; | 
					
						
							|  |  |  |     bool exit_passUnexpected; | 
					
						
							|  |  |  |     bool enter_catchUnexpected; | 
					
						
							|  |  |  |     bool exit_catchUnexpected; | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     void setUp() { | 
					
						
							|  |  |  |       enter_unexpectedThrow = false; | 
					
						
							|  |  |  |       exit_unexpectedThrow = false; | 
					
						
							|  |  |  |       enter_passUnexpected = false; | 
					
						
							|  |  |  |       exit_passUnexpected = false; | 
					
						
							|  |  |  |       enter_catchUnexpected = false; | 
					
						
							|  |  |  |       exit_catchUnexpected = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     void unexpectedThrow() throw(std::bad_exception) { | 
					
						
							|  |  |  |       enter_unexpectedThrow = true; | 
					
						
							|  |  |  |       throw mrw::exception(); | 
					
						
							|  |  |  |       exit_unexpectedThrow = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     void passUnexpected() throw(std::bad_exception) { | 
					
						
							|  |  |  |       enter_passUnexpected = true; | 
					
						
							|  |  |  |       unexpectedThrow(); | 
					
						
							|  |  |  |       exit_passUnexpected = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     void catchUnexpected() throw() { | 
					
						
							|  |  |  |       enter_catchUnexpected = true; | 
					
						
							|  |  |  |       bool caught(false); | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         passUnexpected(); | 
					
						
							|  |  |  |       } catch (std::bad_exception&) { | 
					
						
							|  |  |  |         caught = true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       CPPUNIT_ASSERT(caught); | 
					
						
							|  |  |  |       exit_catchUnexpected = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     void testcase() { | 
					
						
							| 
									
										
										
										
											2017-04-05 10:50:42 +00:00
										 |  |  |       std::set_unexpected([]{throw std::bad_exception();}); | 
					
						
							| 
									
										
										
										
											2004-04-23 16:03:29 +00:00
										 |  |  |       catchUnexpected(); | 
					
						
							|  |  |  |       CPPUNIT_ASSERT(enter_catchUnexpected && | 
					
						
							|  |  |  |                      enter_passUnexpected && | 
					
						
							|  |  |  |                      enter_unexpectedThrow && | 
					
						
							|  |  |  |                      exit_catchUnexpected && | 
					
						
							|  |  |  |                      !exit_passUnexpected && | 
					
						
							|  |  |  |                      !exit_unexpectedThrow); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     CPPUNIT_TEST_SUITE(AutoExcLog4CxxTest); | 
					
						
							|  |  |  |     CPPUNIT_TEST(testcase); | 
					
						
							|  |  |  |     CPPUNIT_TEST_SUITE_END(); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   CPPUNIT_TEST_SUITE_REGISTRATION(AutoExcLog4CxxTest); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-11 13:47:45 +00:00
										 |  |  | int main(int argc, char** argv) try { | 
					
						
							|  |  |  |   std::ofstream ofs((*argv+std::string(".xml")).c_str()); | 
					
						
							| 
									
										
										
										
											2004-04-23 16:03:29 +00:00
										 |  |  |   CppUnit::TextUi::TestRunner runner; | 
					
						
							| 
									
										
										
										
											2011-12-11 13:47:45 +00:00
										 |  |  |   runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs)); | 
					
						
							| 
									
										
										
										
											2004-04-23 16:03:29 +00:00
										 |  |  |   runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); | 
					
						
							|  |  |  |   return runner.run() ? 0 : 1; | 
					
						
							| 
									
										
										
										
											2011-12-11 13:47:45 +00:00
										 |  |  |  } catch (std::exception& e) { | 
					
						
							|  |  |  |   std::cerr<<"***Exception: "<<e.what()<<std::endl; | 
					
						
							|  |  |  |   return 1; | 
					
						
							|  |  |  |  } |