summaryrefslogtreecommitdiff
path: root/src/DllPlugInTester/DllPlugInTester.cpp
diff options
context:
space:
mode:
authorBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-14 19:21:01 +0000
committerBaptiste Lepilleur <gaiacrtn@free.fr>2002-06-14 19:21:01 +0000
commit73a038f1eaa268cec330d971fb550befec6f7798 (patch)
treec3eba5d793e37413889acad5b0b9f70caf89b0f6 /src/DllPlugInTester/DllPlugInTester.cpp
parentf39e160fba25476de7d41e2f19d756db7ee76dc7 (diff)
downloadcppunit-73a038f1eaa268cec330d971fb550befec6f7798.tar.gz
Include/cppunit/plugin/PlugInManager.
include/cppunit/plugin/PlugInManager.h: * src/cppunit/PlugInManager.cpp: added two methods to use the plug-in interface for Xml Outputter hooks. * include/cppunit/plugin/TestPlugIn.h: added two methods to the plug-in interface for Xml Outputter hooks. * include/cppunit/plugin/TestPlugInAdapter.h: * src/cppunit/plugin/TestPlugInAdapter.cpp: renamed TestPlugInDefaultImpl. Added empty implementation for Xml outputter hook methods. * include/cppunit/tools/StringTools.h: * src/cppunit/tools/StringTools.cpp: added. Functions to manipulate string (conversion, wrapping...) * include/cppunit/tools/XmlElement.h: * src/cppunit/XmlElement.cpp: renamed addNode() to addElement(). Added methods to walk and modify XmlElement (for hook). Added documentation. Use StringTools. * include/cppunit/XmlOutputter.h: * src/cppunit/XmlOutputter.cpp: added hook calls & management. * include/cppunit/XmlOutputterHook.h: * src/cppunit/XmlOutputterHook.cpp: added. Hook to customize XML output. * src/DllPlugInTester/DllPlugInTester.cpp: call plug-in XmlOutputterHook when writing XML output. Modified so that memory is freed before unloading the test plug-in (caused crash when freeing the XmlDocument). * examples/ReadMe.txt: * examples/ClockerPlugIn/ReadMe.txt: added details about the plug-in (usage, xml content...) * examples/ClockerPlugIn/ClockerModel.h: * examples/ClockerPlugIn/ClockerModel.cpp: extracted from ClockerListener. Represents the test hierarchy and tracked time for each test. * examples/ClockerPlugIn/ClockerListener.h: * examples/ClockerPlugIn/ClockerListener.cpp: extracted test hierarchy tracking to ClockerModel. Replaced the 'flat' view option with a 'text' option to print the timed test tree to stdout. * examples/ClockerPlugIn/ClockerPlugIn.cpp: updated to hook the XML output and use the new classes. * examples/ClockerPlugIn/ClockerXmlHook.h: * examples/ClockerPlugIn/ClockerXmlHook.cpp: added. XmlOutputterHook to includes the timed test hierarchy and test timing in the XML output. * examples/cppunittest/XmlElementTest.h: * examples/cppunittest/XmlElementTest.cpp: added new test cases. * examples/cppunittest/XmlOutputterTest.h: * examples/cppunittest/XmlOutputterTest.cpp: added tests for XmlOutputterHook.
Diffstat (limited to 'src/DllPlugInTester/DllPlugInTester.cpp')
-rw-r--r--src/DllPlugInTester/DllPlugInTester.cpp136
1 files changed, 76 insertions, 60 deletions
diff --git a/src/DllPlugInTester/DllPlugInTester.cpp b/src/DllPlugInTester/DllPlugInTester.cpp
index b00fb77..3bbb797 100644
--- a/src/DllPlugInTester/DllPlugInTester.cpp
+++ b/src/DllPlugInTester/DllPlugInTester.cpp
@@ -17,6 +17,13 @@
#include "CommandLineParser.h"
+/* Notes:
+
+ Memory allocated by test plug-in must be freed before unloading the test plug-in.
+ That is the reason why the XmlOutputter is explicitely destroyed.
+ */
+
+
/*! Runs the specified tests located in the root suite.
* \param parser Command line parser.
* \return \c true if the run succeed, \c false if a test failed or if a test
@@ -25,76 +32,85 @@
bool
runTests( const CommandLineParser &parser )
{
- CppUnit::TestResult controller;
- CppUnit::TestResultCollector result;
- controller.addListener( &result );
-
- // Set up outputters
- std::ostream *stream = &std::cerr;
- if ( parser.useCoutStream() )
- stream = &std::cout;
-
- std::ostream *xmlStream = stream;
- if ( !parser.getXmlFileName().empty() )
- xmlStream = new std::ofstream( parser.getXmlFileName().c_str() );
-
- CppUnit::XmlOutputter xmlOutputter( &result, *xmlStream, parser.getEncoding() );
- xmlOutputter.setStyleSheet( parser.getXmlStyleSheet() );
- CppUnit::TextOutputter textOutputter( &result, *stream );
- CppUnit::CompilerOutputter compilerOutputter( &result, *stream );
-
- // Set up test listeners
- CppUnit::BriefTestProgressListener briefListener;
- CppUnit::TextTestProgressListener dotListener;
- if ( parser.useBriefTestProgress() )
- controller.addListener( &briefListener );
- else if ( !parser.noTestProgress() )
- controller.addListener( &dotListener );
-
- // Set up plug-ins
+ bool wasSuccessful = false;
CppUnit::PlugInManager plugInManager;
- for ( int index =0; index < parser.getPlugInCount(); ++index )
+
+ // The following scope is used to explicitely free all memory allocated before
+ // unload the test plug-ins (uppon plugInManager destruction).
{
- CommandLinePlugInInfo plugIn = parser.getPlugInAt( index );
- plugInManager.load( plugIn.m_fileName, plugIn.m_parameters );
- }
+ CppUnit::TestResult controller;
+ CppUnit::TestResultCollector result;
+ controller.addListener( &result );
- // Registers plug-in specific TestListener (global setUp/tearDown, custom TestListener...)
- plugInManager.addListener( &controller );
+ // Set up outputters
+ std::ostream *stream = &std::cerr;
+ if ( parser.useCoutStream() )
+ stream = &std::cout;
- // Adds the default registry suite
- CppUnit::TestRunner runner;
- runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
+ std::ostream *xmlStream = stream;
+ if ( !parser.getXmlFileName().empty() )
+ xmlStream = new std::ofstream( parser.getXmlFileName().c_str() );
- // Runs the specified test
- bool wasSuccessful = false;
- try
- {
- runner.run( controller, parser.getTestPath() );
- wasSuccessful = result.wasSuccessful();
- }
- catch ( std::invalid_argument & )
- {
- std::cerr << "Failed to resolve test path: "
- << parser.getTestPath()
- << std::endl;
- }
+ CppUnit::XmlOutputter xmlOutputter( &result, *xmlStream, parser.getEncoding() );
+ xmlOutputter.setStyleSheet( parser.getXmlStyleSheet() );
+ CppUnit::TextOutputter textOutputter( &result, *stream );
+ CppUnit::CompilerOutputter compilerOutputter( &result, *stream );
+
+ // Set up test listeners
+ CppUnit::BriefTestProgressListener briefListener;
+ CppUnit::TextTestProgressListener dotListener;
+ if ( parser.useBriefTestProgress() )
+ controller.addListener( &briefListener );
+ else if ( !parser.noTestProgress() )
+ controller.addListener( &dotListener );
+
+ // Set up plug-ins
+ for ( int index =0; index < parser.getPlugInCount(); ++index )
+ {
+ CommandLinePlugInInfo plugIn = parser.getPlugInAt( index );
+ plugInManager.load( plugIn.m_fileName, plugIn.m_parameters );
+ }
- // Removes plug-in specific TestListener (not really needed but...)
- plugInManager.removeListener( &controller );
+ // Registers plug-in specific TestListener (global setUp/tearDown, custom TestListener...)
+ plugInManager.addListener( &controller );
- // write using outputters
- if ( parser.useCompilerOutputter() )
- compilerOutputter.write();
+ // Adds the default registry suite
+ CppUnit::TestRunner runner;
+ runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
- if ( parser.useTextOutputter() )
- textOutputter.write();
+ // Runs the specified test
+ try
+ {
+ runner.run( controller, parser.getTestPath() );
+ wasSuccessful = result.wasSuccessful();
+ }
+ catch ( std::invalid_argument & )
+ {
+ std::cerr << "Failed to resolve test path: "
+ << parser.getTestPath()
+ << std::endl;
+ }
- if ( parser.useXmlOutputter() )
- xmlOutputter.write();
+ // Removes plug-in specific TestListener (not really needed but...)
+ plugInManager.removeListener( &controller );
- if ( !parser.getXmlFileName().empty() )
- delete xmlStream;
+ // write using outputters
+ if ( parser.useCompilerOutputter() )
+ compilerOutputter.write();
+
+ if ( parser.useTextOutputter() )
+ textOutputter.write();
+
+ if ( parser.useXmlOutputter() )
+ {
+ plugInManager.addXmlOutputterHooks( &xmlOutputter );
+ xmlOutputter.write();
+ plugInManager.removeXmlOutputterHooks();
+ }
+
+ if ( !parser.getXmlFileName().empty() )
+ delete xmlStream;
+ }
return wasSuccessful;
}