diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-17 21:27:28 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-04-17 21:27:28 +0000 |
| commit | 87e5cf8f526380c40f63208c6c9e785f73d327b7 (patch) | |
| tree | ba1871a917dfae7667b31587ced4072d5d18657d /src/DllPlugInTester/DllPlugInTester.cpp | |
| parent | 6c1e9ed0f8fd7339084186df71b4dfc4c98a524e (diff) | |
| download | cppunit-87e5cf8f526380c40f63208c6c9e785f73d327b7.tar.gz | |
Bumped version to 1.
bumped version to 1.9.3
* FAQ: added question about 4786 warning on VC++.
* NEWS: updated.
* contrib/msvc/readme.txt: moved to contrib/readme.txt.
* contrib/xml-xsl/report.xsl: added XML style sheet contributed by
'cuppa' project team (http://sourceforge.jp/projects/cuppa/)
* examples/cppunittest/TestResultTest.h:
* examples/cppunittest/TestResultTest.cpp: added tests for
startTestRun()/endTestRun().
* examples/simple/*: added. A simple example.
* include/cppunit/BriefTestProgressListener.h:
* src/cppunit/BriefTestProgressListener.cpp: added. Verbose progess listener
that print the test name before running the test.
* include/cppunit/TestListener.h: added startTestRun()/endTestRun().
* include/cppunit/TestResult.h:
* src/cppunit/TestResult.cpp: added runTest(), to be called to run
a test by test runner.
* src/cppunit/TextTestRunner.cpp:
* src/cppunit/TestRunner.cpp: updated to use TestResult::runTest().
* include/cppunit/plugin/PlugInManager.h:
* src/cppunit/PlugInManager.cpp: added. Managers for all loaded plug-ins.
* include/cppunit/plugin/TestPlugInDefaultImpl.h:
* src/cppunit/TestPlugInDefaultImpl.cpp: renamed TestPlugInAdapter. All
implementations are empty.
* include/cppunit/plugin/TestPlugInSuite.h: removed.
* src/cppunit/TestPlugInSuite.cpp: removed. Replaced by PlugInManager.
* include/cppunit/plugin/TestPlugIn.h: rewrote the plug-in interface to
provide more versatility. updated macros to match new interface.
* include/cppunit/extensions/TestFactoryRegistry.h:
* include/cppunit/extensions/TestFactoryRegistry.cpp: Added unregisterFactory().
Added convenience method addRegistry(). Rewrote registry life cycle
management. AutoRegisterSuite can now detect that the registry has been
destroy and not call to it to unregister its test factory.
* include/cppunit/extensions/AutoRegisterTest.h: on destruction, the registered
factory is unregistered from the registry.
* include/cppunit/extensions/HelperMacros.h: added macros
CPPUNIT_REGISTRY_ADD_TO_DEFAULT and CPPUNIT_REGISTRY_ADD to help
build test suite hierarchy.
* src/cppunit/msvc/DllPlugInTester/*: moved to src/cppunit/DllPlugInTester/.
* src/cppunit/DllPlugInTester/DllPlugInTester.cpp: removed UNICODE stuffs. Use
the PlugInManager instead of PlugInTestSuite. Simplified: only one test on
command line, but many DLL can be specified. Added configurations to link
against cppunit dll, those are now the default configuration (static linking
don't make much sense for plug-in).
Diffstat (limited to 'src/DllPlugInTester/DllPlugInTester.cpp')
| -rw-r--r-- | src/DllPlugInTester/DllPlugInTester.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/DllPlugInTester/DllPlugInTester.cpp b/src/DllPlugInTester/DllPlugInTester.cpp new file mode 100644 index 0000000..532ee7f --- /dev/null +++ b/src/DllPlugInTester/DllPlugInTester.cpp @@ -0,0 +1,134 @@ +#include <cppunit/CompilerOutputter.h> +#include <cppunit/TestPath.h> +#include <cppunit/TestResult.h> +#include <cppunit/TestResultCollector.h> +#include <cppunit/TestRunner.h> +#include <cppunit/TextTestProgressListener.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/plugin/DynamicLibraryManagerException.h> +#include <cppunit/plugin/Parameters.h> +#include <cppunit/plugin/PlugInManager.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <iostream> + + +/*! Runs the specified tests located in the root suite. + * \param parameters List of string representing the command line arguments. + * \return \c true if the run succeed, \c false if a test failed or if a test + * path was not resolved. + */ +bool +runTests( CppUnit::Parameters parameters ) +{ + CppUnit::TestResult controller; + CppUnit::TestResultCollector result; + controller.addListener( &result ); + CppUnit::TextTestProgressListener progress; + controller.addListener( &progress ); + + std::string testPath; + CppUnit::PlugInManager plugInManager; + // Loads plug-ins & get test path. + for ( int index =0; index < parameters.size(); ++index ) + { + std::string parameter = parameters[index]; + if ( parameter[0] == ':' ) + testPath = parameter.substr(1); + else + plugInManager.load( parameter ); + } + + // Registers plug-in specific TestListener (global setUp/tearDown, custom TestListener...) + plugInManager.addListener( &controller ); + + // Adds the default registry suite + CppUnit::TestRunner runner; + runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() ); + + // Runs the specified test + try + { + runner.run( controller ); + } + catch ( std::invalid_argument & ) + { + std::cerr << "Failed to resolve test path: " << testPath << std::endl; + return false; + } + + // Removes plug-in specific TestListener (not really needed but...) + plugInManager.removeListener( &controller ); + + std::cerr << std::endl; + + // Outputs test result + CppUnit::CompilerOutputter outputter( &result, std::cerr ); + outputter.write(); + + return result.wasSuccessful(); +} + + +/*! Main + * + * Usage: + * + * DllPlugInTester.exe dll-filename1 [dll-filename2 [dll-filename3 ...]] [:testpath] + * + * <em>dll-filename</em> must be the name of the DLL. If the DLL use some other DLL, they + * should be in the path or in the same directory as the DLL. The DLL must export + * a function named "GetTestPlugInInterface" with the signature + * GetTestPlugInInterfaceFunction. Both are defined in: + * \code + * #include <msvc6/testrunner/TestPlugInInterface.h> + * \endcode. + * + * See examples/msvc6/TestPlugIn for an example of post-build testing. + * + * If no test path is specified, they all the test of the suite returned by the DLL + * are run. If a test path is specified, then only the specified test is run. The test + * path must be prefixed by ':'. + * + * Test paths are resolved using Test::resolveTestPath() on the suite returned by + * TestFactoryRegistry::getRegistry().makeTest(); + * + * If all test succeed and no error happen then the application exit with code 0. + * If any error occurs (failed to load dll, failed to resolve test paths) or a + * test fail, the application exit with code 1. + */ +int +main( int argc, + char *argv[] ) +{ + const int successReturnCode = 0; + const int failureReturnCode = 1; + + // check command line + std::string applicationName( argv[0] ); + if ( argc < 2 ) + { + std::cerr << "Usage: " << std::endl + << applicationName + << " dll-filename1 [dll-filename2 ...] [:test-path]..." + << std::endl; + return failureReturnCode; + } + + bool wasSuccessful = false; + try + { + CppUnit::Parameters parameters; + for ( int index =1; index < argc; ++index ) + parameters.push_back( argv[index] ); + wasSuccessful = runTests( parameters ); + } + catch ( CppUnit::DynamicLibraryManagerException &e ) + { + std::cerr << "Failed to load test plug-in:" << std::endl + << e.what() << std::endl; + } + + return wasSuccessful ? successReturnCode : failureReturnCode; +} + + |
