diff --git a/livesupport/modules/core/etc/Makefile.in b/livesupport/modules/core/etc/Makefile.in index 516ae494a..e2c26d817 100644 --- a/livesupport/modules/core/etc/Makefile.in +++ b/livesupport/modules/core/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.1 $ +# Version : $Revision: 1.2 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # # @configure_input@ @@ -56,6 +56,10 @@ LIBXMLPP_INCLUDE_DIR = ${USR_INCLUDE_DIR}/libxml++-1.0 VPATH = ${SRC_DIR} +TEST_RESULTS = ${DOC_DIR}/testResults.xml +# the text result XSLT has to be relative to the test result file, e.g. TMP_DIR +TEST_XSLT = ../etc/testResultToHtml.xsl + CORE_LIB = livesupport_core CORE_LIB_FILE = ${LIB_DIR}/lib${CORE_LIB}.a TEST_RUNNER = ${TMP_DIR}/testRunner @@ -102,6 +106,7 @@ clean: docclean: ${RMDIR} ${DOXYGEN_DIR}/html + ${RM} ${TEST_RESULTS} depclean: clean @@ -109,7 +114,8 @@ distclean: clean docclean ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* check: ${TEST_RUNNER} - LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} + LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \ + -o ${TEST_RESULTS} -s ${TEST_XSLT} #------------------------------------------------------------------------------- diff --git a/livesupport/modules/core/etc/configure.ac b/livesupport/modules/core/etc/configure.ac index 5a39c28ee..ab611bab3 100644 --- a/livesupport/modules/core/etc/configure.ac +++ b/livesupport/modules/core/etc/configure.ac @@ -21,7 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl dnl dnl Author : $Author: maroy $ -dnl Version : $Revision: 1.1 $ +dnl Version : $Revision: 1.2 $ dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/configure.ac,v $ dnl----------------------------------------------------------------------------- @@ -35,14 +35,14 @@ dnl----------------------------------------------------------------------------- AC_INIT(Core, 1.0, bugs@campware.org) AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL]) -AC_REVISION($Revision: 1.1 $) +AC_REVISION($Revision: 1.2 $) AC_CONFIG_SRCDIR(../src/UniqueId.cxx) AC_CONFIG_HEADERS(configure.h) AC_PROG_CXX() -AC_CHECK_HEADERS() +AC_CHECK_HEADERS(getopt.h) AC_CONFIG_FILES(../Makefile:../etc/Makefile.in) diff --git a/livesupport/modules/core/etc/testResultToHtml.xsl b/livesupport/modules/core/etc/testResultToHtml.xsl new file mode 100644 index 000000000..d2165c2a4 --- /dev/null +++ b/livesupport/modules/core/etc/testResultToHtml.xsl @@ -0,0 +1,63 @@ + + + + + + + LiveSupport unit test results + + +

Preface

+This document is part of the +LiveSupport +project, Copyright © 2004 Media +Development Loan Fund, under the GNU +GPL. +
+This is an automatically generated document. +

Scope

+This document contains the generated unit test results for the +LiveSupport project. +

Summary

+ + + + + + + + + + + + + + + + + + +
Total number of tests:
Tests passed:
Tests failed:
Test errors:
+
+

Tests

+ + + + + + + + + + + + + +
test nametest status
failedpassed
+ + +
+ +
+ diff --git a/livesupport/modules/core/src/TestRunner.cxx b/livesupport/modules/core/src/TestRunner.cxx index 1203642d9..2a3cba545 100644 --- a/livesupport/modules/core/src/TestRunner.cxx +++ b/livesupport/modules/core/src/TestRunner.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TestRunner.cxx,v $ ------------------------------------------------------------------------------*/ @@ -33,22 +33,107 @@ #include "configure.h" #endif +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + +#if HAVE_GETOPT_H +#include +#else +#error "Need getopt.h" +#endif + +#include + #include #include +#include #include #include #include #include +#include "LiveSupport/Core/Ptr.h" + + +using namespace LiveSupport::Core; /* =================================================== local data structures */ /* ================================================ local constants & macros */ +/** + * Our copyright notice, should be at most 80 columns + */ +static const char copyrightNotice[] = + "Copyright (c) 2004 Media Development Loan Fund under the GNU GPL"; + +/** + * String describing the short options. + */ +static const char options[] = "ho:s:v"; + +/** + * Structure describing the long options + */ +static const struct option longOptions[] = { + { "help", no_argument, 0, 'h' }, + { "output", required_argument, 0, 'o' }, + { "stylesheet", required_argument, 0, 's' }, + { "version", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } +}; + +/** + * The encoding to use for the output file. + */ +static const std::string encoding = "utf-8"; + +/** + * The output XML file name. + */ +static Ptr::Ref xmlOutFileName; + +/** + * The XSLT attached to the output file. + */ +static Ptr::Ref xsltFileName; + /* =============================================== local function prototypes */ +/** + * Print program version. + * + * @param os the std::ostream to print to. + */ +static void +printVersion ( std::ostream & os ); + +/** + * Print program usage information. + * + * @param invocation the command line command used to invoke this program. + * @param os the std::ostream to print to. + */ +static void +printUsage ( const char invocation[], + std::ostream & os ); + +/** + * Process command line arguments. + * + * @param argc the number of arguments. + * @param argv the arguments themselves. + * @return true of all went well, false in case the program should exit + * after this call. + */ +static bool +processArguments(int argc, char *argv[]); + /* ============================================================= module code */ @@ -59,6 +144,10 @@ int main( int argc, char * argv[] ) throw () { + if (!processArguments(argc, argv)) { + return 0; + } + // Create the event manager and test controller CPPUNIT_NS::TestResult controller; @@ -79,7 +168,113 @@ main( int argc, CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); outputter.setLocationFormat("%p:%l:"); outputter.write(); - + + // also generate an XML document as an output + std::ofstream xmlOutFile(xmlOutFileName->c_str()); + CPPUNIT_NS::XmlOutputter xmlOutputter(&result, xmlOutFile, encoding); + if (xsltFileName) { + xmlOutputter.setStyleSheet(*xsltFileName); + } + xmlOutputter.write(); + xmlOutFile.flush(); + xmlOutFile.close(); + return result.wasSuccessful() ? 0 : 1; } + +/*------------------------------------------------------------------------------ + * Process command line arguments. + *----------------------------------------------------------------------------*/ +static bool +processArguments(int argc, char *argv[]) +{ + int i; + + while ((i = getopt_long(argc, argv, options, longOptions, 0)) != -1) { + switch (i) { + case 'h': + printUsage(argv[0], std::cout); + return false; + + case 'o': + xmlOutFileName.reset(new std::string(optarg)); + break; + + case 's': + xsltFileName.reset(new std::string(optarg)); + break; + + case 'v': + printVersion(std::cout); + return false; + + default: + printUsage(argv[0], std::cout); + return false; + } + } + + if (optind < argc) { + std::cerr << "error processing command line arguments" << std::endl; + printUsage(argv[0], std::cout); + return false; + } + + if (!xmlOutFileName) { + std::cerr << "mandatory option output file name not specified" + << std::endl; + printUsage(argv[0], std::cout); + return false; + } + + std::cerr << "writing output to '" << *xmlOutFileName << '\'' << std::endl; + if (xsltFileName) { + std::cerr << "using XSLT file '" << *xsltFileName << '\'' << std::endl; + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Print program version. + *----------------------------------------------------------------------------*/ +static void +printVersion ( std::ostream & os ) +{ + os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl + << "Unit test runner" << std::endl + << copyrightNotice << std::endl; +} + + +/*------------------------------------------------------------------------------ + * Print program usage. + *----------------------------------------------------------------------------*/ +static void +printUsage ( const char invocation[], + std::ostream & os ) +{ + os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl + << "Unit test runner" << std::endl + << std::endl + << "Usage: " << invocation << " [OPTION]" + << std::endl + << " mandatory options:" << std::endl + << " -o, --output=file.name write test results into this XML file" + << std::endl + << " optional options:" << std::endl + << " -s, --stylesheet specify this XSLT for the output file" + << std::endl + << " this is either an absolute URI, or a" + << std::endl + << " relative path for the output document" + << std::endl + << " -h, --help display this help and exit" << std::endl + << " -v, --version display version information and exit" + << std::endl + << std::endl + << "Report bugs to " << PACKAGE_BUGREPORT << std::endl; +} + diff --git a/livesupport/modules/db/etc/Makefile.in b/livesupport/modules/db/etc/Makefile.in index 5cce32c56..2c2a55659 100644 --- a/livesupport/modules/db/etc/Makefile.in +++ b/livesupport/modules/db/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.1 $ +# Version : $Revision: 1.2 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/etc/Makefile.in,v $ # # @configure_input@ @@ -64,6 +64,10 @@ CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a VPATH = ${SRC_DIR} +TEST_RESULTS = ${DOC_DIR}/testResults.xml +# the text result XSLT has to be relative to the test result file, e.g. TMP_DIR +TEST_XSLT = ../etc/testResultToHtml.xsl + DB_LIB = livesupport_db DB_LIB_FILE = ${LIB_DIR}/lib${DB_LIB}.a TEST_RUNNER = ${TMP_DIR}/testRunner @@ -114,6 +118,7 @@ clean: docclean: ${RMDIR} ${DOXYGEN_DIR}/html + ${RM} ${TEST_RESULTS} depclean: clean @@ -121,7 +126,8 @@ distclean: clean docclean ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* check: all ${TEST_RUNNER} - LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} + LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \ + -o ${TEST_RESULTS} -s ${TEST_XSLT} #------------------------------------------------------------------------------- diff --git a/livesupport/modules/db/etc/configure.ac b/livesupport/modules/db/etc/configure.ac index 96e228cb9..09c3cce3a 100644 --- a/livesupport/modules/db/etc/configure.ac +++ b/livesupport/modules/db/etc/configure.ac @@ -21,7 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl dnl dnl Author : $Author: maroy $ -dnl Version : $Revision: 1.2 $ +dnl Version : $Revision: 1.3 $ dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/etc/configure.ac,v $ dnl----------------------------------------------------------------------------- @@ -35,14 +35,14 @@ dnl----------------------------------------------------------------------------- AC_INIT(Db, 1.0, bugs@campware.org) AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL]) -AC_REVISION($Revision: 1.2 $) +AC_REVISION($Revision: 1.3 $) AC_CONFIG_SRCDIR(../include/LiveSupport/Db/ConnectionManagerInterface.h) AC_CONFIG_HEADERS(configure.h) AC_PROG_CXX() -AC_CHECK_HEADERS() +AC_CHECK_HEADERS(getopt.h) AC_CONFIG_FILES(../Makefile:../etc/Makefile.in) diff --git a/livesupport/modules/db/etc/testResultToHtml.xsl b/livesupport/modules/db/etc/testResultToHtml.xsl new file mode 100644 index 000000000..d2165c2a4 --- /dev/null +++ b/livesupport/modules/db/etc/testResultToHtml.xsl @@ -0,0 +1,63 @@ + + + + + + + LiveSupport unit test results + + +

Preface

+This document is part of the +LiveSupport +project, Copyright © 2004 Media +Development Loan Fund, under the GNU +GPL. +
+This is an automatically generated document. +

Scope

+This document contains the generated unit test results for the +LiveSupport project. +

Summary

+ + + + + + + + + + + + + + + + + + +
Total number of tests:
Tests passed:
Tests failed:
Test errors:
+
+

Tests

+ + + + + + + + + + + + + +
test nametest status
failedpassed
+ + +
+ +
+ diff --git a/livesupport/modules/db/src/TestRunner.cxx b/livesupport/modules/db/src/TestRunner.cxx index 94ab09046..08df0a5e5 100644 --- a/livesupport/modules/db/src/TestRunner.cxx +++ b/livesupport/modules/db/src/TestRunner.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/TestRunner.cxx,v $ ------------------------------------------------------------------------------*/ @@ -33,22 +33,107 @@ #include "configure.h" #endif +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + +#if HAVE_GETOPT_H +#include +#else +#error "Need getopt.h" +#endif + +#include + #include #include +#include #include #include #include #include +#include "LiveSupport/Core/Ptr.h" + + +using namespace LiveSupport::Core; /* =================================================== local data structures */ /* ================================================ local constants & macros */ +/** + * Our copyright notice, should be at most 80 columns + */ +static const char copyrightNotice[] = + "Copyright (c) 2004 Media Development Loan Fund under the GNU GPL"; + +/** + * String describing the short options. + */ +static const char options[] = "ho:s:v"; + +/** + * Structure describing the long options + */ +static const struct option longOptions[] = { + { "help", no_argument, 0, 'h' }, + { "output", required_argument, 0, 'o' }, + { "stylesheet", required_argument, 0, 's' }, + { "version", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } +}; + +/** + * The encoding to use for the output file. + */ +static const std::string encoding = "utf-8"; + +/** + * The output XML file name. + */ +static Ptr::Ref xmlOutFileName; + +/** + * The XSLT attached to the output file. + */ +static Ptr::Ref xsltFileName; + /* =============================================== local function prototypes */ +/** + * Print program version. + * + * @param os the std::ostream to print to. + */ +static void +printVersion ( std::ostream & os ); + +/** + * Print program usage information. + * + * @param invocation the command line command used to invoke this program. + * @param os the std::ostream to print to. + */ +static void +printUsage ( const char invocation[], + std::ostream & os ); + +/** + * Process command line arguments. + * + * @param argc the number of arguments. + * @param argv the arguments themselves. + * @return true of all went well, false in case the program should exit + * after this call. + */ +static bool +processArguments(int argc, char *argv[]); + /* ============================================================= module code */ @@ -59,6 +144,10 @@ int main( int argc, char * argv[] ) throw () { + if (!processArguments(argc, argv)) { + return 0; + } + // Create the event manager and test controller CPPUNIT_NS::TestResult controller; @@ -79,7 +168,113 @@ main( int argc, CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); outputter.setLocationFormat("%p:%l:"); outputter.write(); - + + // also generate an XML document as an output + std::ofstream xmlOutFile(xmlOutFileName->c_str()); + CPPUNIT_NS::XmlOutputter xmlOutputter(&result, xmlOutFile, encoding); + if (xsltFileName) { + xmlOutputter.setStyleSheet(*xsltFileName); + } + xmlOutputter.write(); + xmlOutFile.flush(); + xmlOutFile.close(); + return result.wasSuccessful() ? 0 : 1; } + +/*------------------------------------------------------------------------------ + * Process command line arguments. + *----------------------------------------------------------------------------*/ +static bool +processArguments(int argc, char *argv[]) +{ + int i; + + while ((i = getopt_long(argc, argv, options, longOptions, 0)) != -1) { + switch (i) { + case 'h': + printUsage(argv[0], std::cout); + return false; + + case 'o': + xmlOutFileName.reset(new std::string(optarg)); + break; + + case 's': + xsltFileName.reset(new std::string(optarg)); + break; + + case 'v': + printVersion(std::cout); + return false; + + default: + printUsage(argv[0], std::cout); + return false; + } + } + + if (optind < argc) { + std::cerr << "error processing command line arguments" << std::endl; + printUsage(argv[0], std::cout); + return false; + } + + if (!xmlOutFileName) { + std::cerr << "mandatory option output file name not specified" + << std::endl; + printUsage(argv[0], std::cout); + return false; + } + + std::cerr << "writing output to '" << *xmlOutFileName << '\'' << std::endl; + if (xsltFileName) { + std::cerr << "using XSLT file '" << *xsltFileName << '\'' << std::endl; + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Print program version. + *----------------------------------------------------------------------------*/ +static void +printVersion ( std::ostream & os ) +{ + os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl + << "Unit test runner" << std::endl + << copyrightNotice << std::endl; +} + + +/*------------------------------------------------------------------------------ + * Print program usage. + *----------------------------------------------------------------------------*/ +static void +printUsage ( const char invocation[], + std::ostream & os ) +{ + os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl + << "Unit test runner" << std::endl + << std::endl + << "Usage: " << invocation << " [OPTION]" + << std::endl + << " mandatory options:" << std::endl + << " -o, --output=file.name write test results into this XML file" + << std::endl + << " optional options:" << std::endl + << " -s, --stylesheet specify this XSLT for the output file" + << std::endl + << " this is either an absolute URI, or a" + << std::endl + << " relative path for the output document" + << std::endl + << " -h, --help display this help and exit" << std::endl + << " -v, --version display version information and exit" + << std::endl + << std::endl + << "Report bugs to " << PACKAGE_BUGREPORT << std::endl; +} +