| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | #include <exception>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | #include "Test.h"
 | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | #include "Failure.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | #include "TestResult.h"
 | 
					
						
							|  |  |  | #include "TestRegistry.h"
 | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | #include "SimpleString.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void TestRegistry::addTest (Test *test)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	instance ().add (test); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TestRegistry::runAllTests (TestResult& result)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	return instance ().run (result); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TestRegistry& TestRegistry::instance ()  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static TestRegistry registry; | 
					
						
							|  |  |  | 	return registry; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TestRegistry::add (Test *test)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (tests == 0) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	  test->setNext(0); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		tests = test; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		lastTest = test; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	test->setNext (0); | 
					
						
							|  |  |  | 	lastTest->setNext(test); | 
					
						
							|  |  |  | 	lastTest = test; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TestRegistry::run (TestResult& result)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	result.testsStarted (); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	for (Test *test = tests; test != 0; test = test->getNext ()) { | 
					
						
							| 
									
										
										
										
											2010-08-31 04:54:12 +08:00
										 |  |  | 		if (test->safe()) { | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				test->run (result); | 
					
						
							|  |  |  | 			} catch (std::exception& e) { | 
					
						
							|  |  |  | 				// catch standard exceptions and derivatives
 | 
					
						
							|  |  |  | 				result.addFailure( | 
					
						
							|  |  |  | 						Failure(test->getName(), test->getFilename(), test->getLineNumber(), | 
					
						
							|  |  |  | 								SimpleString("Exception: ") + SimpleString(e.what()))); | 
					
						
							|  |  |  | 			} catch (...) { | 
					
						
							|  |  |  | 				// catch all other exceptions
 | 
					
						
							|  |  |  | 				result.addFailure( | 
					
						
							|  |  |  | 						Failure(test->getName(), test->getFilename(), test->getLineNumber(), | 
					
						
							|  |  |  | 								SimpleString("ExceptionThrown!"))); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 			test->run (result); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 	result.testsEnded (); | 
					
						
							| 
									
										
										
										
											2010-07-17 03:30:38 +08:00
										 |  |  | 	return result.getFailureCount(); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |