added XML test reporting

This commit is contained in:
maroy 2004-07-24 08:13:07 +00:00
parent f41e3d5a1f
commit b492553d7a
3 changed files with 209 additions and 7 deletions

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.1 $
# Version : $Revision: 1.2 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/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
STORAGE_LIB = livesupport_storage
STORAGE_LIB_FILE = ${LIB_DIR}/lib${STORAGE_LIB}.a
TEST_RUNNER = ${TMP_DIR}/testRunner
@ -111,6 +115,7 @@ clean:
docclean:
${RMDIR} ${DOXYGEN_DIR}/html
${RM} ${TEST_RESULTS}
depclean: clean
@ -118,7 +123,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}
#-------------------------------------------------------------------------------

View File

@ -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/storage/etc/configure.ac,v $
dnl-----------------------------------------------------------------------------
@ -35,14 +35,14 @@ dnl-----------------------------------------------------------------------------
AC_INIT(Storage, 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/StorageClientFactory.cxx)
AC_CONFIG_HEADERS(configure.h)
AC_PROG_CXX()
AC_CHECK_HEADERS()
AC_CHECK_HEADERS(getopt.h)
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestRunner.cxx,v $
------------------------------------------------------------------------------*/
@ -33,22 +33,107 @@
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#if HAVE_GETOPT_H
#include <getopt.h>
#else
#error "Need getopt.h"
#endif
#include <fstream>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#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<std::string>::Ref xmlOutFileName;
/**
* The XSLT attached to the output file.
*/
static Ptr<std::string>::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;
@ -80,6 +169,113 @@ main( int argc,
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);
xmlOutputter.setStandalone(false);
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;
}