added authentication module

This commit is contained in:
fgerlits 2004-11-20 10:24:23 +00:00
parent f44a150b4d
commit 03e541ce79
8 changed files with 5364 additions and 0 deletions

View File

@ -0,0 +1,87 @@
#!/bin/sh
#-------------------------------------------------------------------------------
# Copyright (c) 2004 Media Development Loan Fund
#
# This file is part of the LiveSupport project.
# http://livesupport.campware.org/
# To report bugs, send an e-mail to bugs@campware.org
#
# LiveSupport is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LiveSupport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LiveSupport; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.1 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/bin/autogen.sh,v $
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Run this to set up the build system: configure, makefiles, etc.
# (based on the version in enlightenment's cvs)
#-------------------------------------------------------------------------------
package="Storage"
# assume we're in $basedir/bin
basedir=`dirname $0`/..
test -z "$basedir" && basedir=.
tmpdir=$basedir/tmp
cd "$tmpdir"
DIE=0
# look at all other directories as seen from ${basedir}/tmp
tmpdir=.
bindir=../bin
etcdir=../etc
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
if test "$DIE" -eq 1; then
exit 1
fi
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
echo "Generating configuration files for $package, please wait...."
configure_ac=${etcdir}/configure.ac
configure=${tmpdir}/configure
#echo " aclocal $ACLOCAL_FLAGS"
#aclocal $ACLOCAL_FLAGS
echo " autoheader ${configure_ac}"
autoheader ${configure_ac}
echo " autoconf -o ${configure} ${configure_ac}"
autoconf -o ${configure} ${configure_ac}
${configure} "$@" && echo

View File

@ -0,0 +1,80 @@
#!/bin/sh
#-------------------------------------------------------------------------------
# Copyright (c) 2004 Media Development Loan Fund
#
# This file is part of the LiveSupport project.
# http://livesupport.campware.org/
# To report bugs, send an e-mail to bugs@campware.org
#
# LiveSupport is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LiveSupport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LiveSupport; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.1 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/bin/gen_coverage_data.sh,v $
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# This script generates code coverage data for the module
#-------------------------------------------------------------------------------
module="LiveSupport Storage"
reldir=`dirname $0`/..
basedir=`cd $reldir; pwd; cd -`
bindir=$basedir/bin
docdir=$basedir/doc
tmpdir=$basedir/tmp
usrdir=`cd $basedir/../../usr; pwd; cd -`
coverage_report_dir=$docdir/coverage
raw_coverage_file=$tmpdir/raw_coverage.info
coverage_file=$tmpdir/coverage.info
lcov=$usrdir/bin/lcov
genhtml=$usrdir/bin/genhtml
cd $basedir
#-------------------------------------------------------------------------------
# Re-configure with covarege collection enabled, compile and run the tests
#-------------------------------------------------------------------------------
$bindir/autogen.sh --enable-coverage
make clean
make check
#-------------------------------------------------------------------------------
# Generate some symlinks so that the sources are visible from tmpdir
#-------------------------------------------------------------------------------
ln -s $basedir/include $tmpdir/include
ln -s $basedir/src $tmpdir/src
#-------------------------------------------------------------------------------
# Use lcov to generate an HTML report on the coverage data
#-------------------------------------------------------------------------------
$lcov -d $tmpdir -c > $raw_coverage_file
$lcov -e $raw_coverage_file "$tmpdir/*" > $coverage_file
rm -rf $coverage_report_dir
mkdir -p $coverage_report_dir
$genhtml -t "$module" -o $coverage_report_dir $coverage_file
#-------------------------------------------------------------------------------
# Clean up
#-------------------------------------------------------------------------------
rm -f $tmpdir/include
rm -f $tmpdir/src

View File

@ -0,0 +1,162 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2004 Media Development Loan Fund
#
# This file is part of the LiveSupport project.
# http://livesupport.campware.org/
# To report bugs, send an e-mail to bugs@campware.org
#
# LiveSupport is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LiveSupport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LiveSupport; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.1 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/etc/Makefile.in,v $
#
# @configure_input@
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# General command definitions
#-------------------------------------------------------------------------------
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
DOXYGEN = doxygen
#-------------------------------------------------------------------------------
# Basic directory and file definitions
#-------------------------------------------------------------------------------
BASE_DIR = @builddir@
DOC_DIR = ${BASE_DIR}/doc
DOXYGEN_DIR = ${DOC_DIR}/doxygen
COVERAGE_DIR = ${DOC_DIR}/coverage
ETC_DIR = ${BASE_DIR}/etc
INCLUDE_DIR = ${BASE_DIR}/include
LIB_DIR = ${BASE_DIR}/lib
SRC_DIR = ${BASE_DIR}/src
TMP_DIR = ${BASE_DIR}/tmp
USR_DIR = ${BASE_DIR}/../../usr
USR_INCLUDE_DIR = ${USR_DIR}/include
USR_LIB_DIR = ${USR_DIR}/lib
BOOST_INCLUDE_DIR = ${USR_INCLUDE_DIR}/boost-1_31
LIBXMLPP_INCLUDE_DIR = ${USR_INCLUDE_DIR}/libxml++-1.0
MODULES_DIR = ${BASE_DIR}/..
CORE_DIR = ${MODULES_DIR}/core
CORE_INCLUDE_DIR = ${CORE_DIR}/include
CORE_LIB_DIR = ${CORE_DIR}/lib
CORE_LIB = livesupport_core
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
AUTHENTICATION_LIB = livesupport_authentication
AUTHENTICATION_LIB_FILE = ${LIB_DIR}/lib${AUTHENTICATION_LIB}.a
TEST_RUNNER = ${TMP_DIR}/testRunner
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
#-------------------------------------------------------------------------------
# Configuration parameters
#-------------------------------------------------------------------------------
CPPFLAGS = @CPPFLAGS@
CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ \
-pedantic -Wall -Wno-long-long \
-I${USR_INCLUDE_DIR} \
-I${BOOST_INCLUDE_DIR} \
-I${LIBXMLPP_INCLUDE_DIR} \
-I${CORE_INCLUDE_DIR} \
-I${INCLUDE_DIR} -I${TMP_DIR}
LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR}
#-------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------
AUTHENTICATION_LIB_OBJS = ${TMP_DIR}/AuthenticationClientFactory.o \
${TMP_DIR}/WebAuthenticationClient.o
TEST_RUNNER_OBJS = ${TMP_DIR}/WebAuthenticationClientTest.o \
${TMP_DIR}/TestRunner.o
TEST_RUNNER_LIBS = -l${AUTHENTICATION_LIB} -l${CORE_LIB} -lxml++-1.0 \
-lcppunit -ldl -lxmlrpc++ -lssl
#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------
.PHONY: all dir_setup doc clean docclean depclean distclean
all: dir_setup ${AUTHENTICATION_LIB_FILE}
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
doc:
${DOXYGEN} ${DOXYGEN_CONFIG}
clean:
${RM} ${AUTHENTICATION_LIB_OBJS} ${AUTHENTICATION_LIB_FILE}
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER}
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
docclean:
${RMDIR} ${DOXYGEN_DIR}/html
${RMDIR} ${COVERAGE_DIR}/*
${RM} ${TEST_RESULTS}
depclean: clean
distclean: clean docclean
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
check: all ${TEST_RUNNER}
LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \
-o ${TEST_RESULTS} -s ${TEST_XSLT}
#-------------------------------------------------------------------------------
# Specific targets
#-------------------------------------------------------------------------------
${AUTHENTICATION_LIB_FILE}: ${AUTHENTICATION_LIB_OBJS}
${AR} crus $@ $^
${TMP_DIR}:
${MKDIR} ${TMP_DIR}
${DOXYGEN_DIR}:
${MKDIR} ${DOXYGEN_DIR}
${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS} ${AUTHENTICATION_LIB_FILE}
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
${CORE_LIB_FILE}:
${MAKE} -C ${CORE_DIR}
#-------------------------------------------------------------------------------
# Pattern rules
#-------------------------------------------------------------------------------
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<

View File

@ -0,0 +1,66 @@
dnl-----------------------------------------------------------------------------
dnl Copyright (c) 2004 Media Development Loan Fund
dnl
dnl This file is part of the LiveSupport project.
dnl http://livesupport.campware.org/
dnl To report bugs, send an e-mail to bugs@campware.org
dnl
dnl LiveSupport is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl LiveSupport is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with LiveSupport; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl
dnl Author : $Author: fgerlits $
dnl Version : $Revision: 1.1 $
dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/etc/configure.ac,v $
dnl-----------------------------------------------------------------------------
dnl-----------------------------------------------------------------------------
dnl NOTE: Run all configure related scripts from the tmp directory of the
dnl project.
dnl This is due to the fact that configure spreads a lot of trash around,
dnl like atom4te cache directories, config.* files, etc. into the directory
dnl it is being run from. We clearly don't want these in our base directory.
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_CONFIG_SRCDIR(../src/AuthenticationClientFactory.cxx)
AC_CONFIG_HEADERS(configure.h)
AC_PROG_CXX()
AC_CHECK_HEADERS(getopt.h)
dnl-----------------------------------------------------------------------------
dnl enable compilaton for code coverage data
dnl-----------------------------------------------------------------------------
AC_SUBST(COVERAGE_CXXFLAGS)
AC_ARG_ENABLE( coverage,
[ --enable-coverage enable code coverage data generaton (no) ],
ENABLE_COVERAGE=${enableval}, ENABLE_COVERAGE="no" )
if test "x${ENABLE_COVERAGE}" == "xyes" ; then
COVERAGE_CXXFLAGS="-fprofile-arcs -ftest-coverage"
AC_MSG_RESULT([compiling in code coverage mode])
else
AC_MSG_RESULT([not compiling in code coverage mode])
fi
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)
AC_OUTPUT()

View File

@ -0,0 +1,188 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientFactory.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Authentication_AuthenticationClientFactory_h
#define LiveSupport_Authentication_AuthenticationClientFactory_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Authentication/AuthenticationClientInterface.h"
namespace LiveSupport {
namespace Authentication {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* The factory to create appropriate AuthenticationClient objects.
*
* This object has to be configured with an XML configuration element
* called authenticationClientFactory. This element contains a child element
* specifying and configuring the kind of AuthenticationClient that the
* factory builds. Currently only the WebAuthenticationClient is supported.
*
* A authenticationClientFactory configuration element may look like the following:
*
* <pre><code>
* &lt;authenticationClientFactory&gt;
* &lt;webAuthentication&gt;
* ...
* &lt;/webAuthentication&gt;
* &lt;/authenticationClientFactory&gt;
* </code></pre>
*
* For detais of the testAuthentication element, see the documentation for the
* WebAuthenticationClient class.
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT authenticationClientFactory (webAuthentication) &gt;
* </code></pre>
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see TestAuthenticationClient
*/
class AuthenticationClientFactory :
virtual public Configurable
{
private:
/**
* The name of the configuration XML elmenent used by this object.
*/
static const std::string configElementNameStr;
/**
* The singleton instance of this object.
*/
static Ptr<AuthenticationClientFactory>::Ref singleton;
/**
* The authentication client created by this factory.
*/
Ptr<AuthenticationClientInterface>::Ref authenticationClient;
/**
* The default constructor.
*/
AuthenticationClientFactory(void) throw()
{
}
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~AuthenticationClientFactory(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Returns the singleton instance of this object.
*
* @return the singleton instance of this object.
*/
static Ptr<AuthenticationClientFactory>::Ref
getInstance() throw ();
/**
* Configure the object based on the XML element supplied.
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
/**
* Return an authentication client.
*
* @return the appropriate authentication client, according to the
* configuration of this factory.
*/
Ptr<AuthenticationClientInterface>::Ref
getAuthenticationClient(void) throw ()
{
return authenticationClient;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Authentication
} // namespace LiveSupport
#endif // LiveSupport_Authentication_AuthenticationClientFactory_h

View File

@ -0,0 +1,111 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/AuthenticationClientFactory.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Authentication/AuthenticationClientFactory.h"
#include "LiveSupport/Authentication/WebAuthenticationClient.h"
using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string AuthenticationClientFactory::configElementNameStr =
"authenticationClientFactory";
/*------------------------------------------------------------------------------
* The singleton instance of AuthenticationClientFactory
*----------------------------------------------------------------------------*/
Ptr<AuthenticationClientFactory>::Ref AuthenticationClientFactory::singleton;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return the singleton instance to AuthenticationClientFactory
*----------------------------------------------------------------------------*/
Ptr<AuthenticationClientFactory>::Ref
AuthenticationClientFactory :: getInstance(void) throw ()
{
if (!singleton.get()) {
singleton.reset(new AuthenticationClientFactory());
}
return singleton;
}
/*------------------------------------------------------------------------------
* Configure the test authentication client.
*----------------------------------------------------------------------------*/
void
AuthenticationClientFactory :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
authenticationClient.reset();
// try to look for an WebAuthenticationClient configuration element
xmlpp::Node::NodeList nodes =
element.get_children(WebAuthenticationClient::getConfigElementName());
if (nodes.size() >= 1) {
const xmlpp::Element * configElement =
dynamic_cast<const xmlpp::Element*> (*(nodes.begin()));
Ptr<WebAuthenticationClient>::Ref wac(new WebAuthenticationClient());
wac->configure(*configElement);
authenticationClient = wac;
}
if (!authenticationClient) {
throw std::invalid_argument("no authentication client factories "
"to configure");
}
}

View File

@ -0,0 +1,281 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestRunner.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#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 */
/*------------------------------------------------------------------------------
* Run all tests
*----------------------------------------------------------------------------*/
int
main( int argc,
char * argv[] ) throw ()
{
if (!processArguments(argc, argv)) {
return 0;
}
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
// Add a listener that print dots as test run.
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener( &progress );
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
runner.run( controller );
// Print test in a compiler compatible format.
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);
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;
}

4389
livesupport/modules/authentication/tmp/configure vendored Executable file

File diff suppressed because it is too large Load Diff