diff --git a/akonadi/tests/testrunner/CMakeLists.txt b/akonadi/tests/testrunner/CMakeLists.txt index f40e2f8e0..e4ed024a6 100644 --- a/akonadi/tests/testrunner/CMakeLists.txt +++ b/akonadi/tests/testrunner/CMakeLists.txt @@ -1,47 +1,46 @@ project (akonaditest) include_directories( ${CMAKE_SOURCE_DIR}/kabc ${CMAKE_SOURCE_DIR}/kcal ${CMAKE_SOURCE_DIR}/akonadi ${CMAKE_BINARY_DIR}/kabc ${CMAKE_BINARY_DIR}/kcal ${CMAKE_BINARY_DIR}/akonadi ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ${KDE4_INCLUDES} ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) set(akonaditest_SRCS main.cpp setup.cpp - configreader.cpp config.cpp shellscript.cpp symbols.cpp testrunner.cpp ) kde4_add_executable(akonaditest NOGUI ${akonaditest_SRCS}) target_link_libraries(akonaditest akonadi-kde kabc kcal syndication ${KDE4_KDEUI_LIBS} ${Boost_LIBRARIES} ${KDE4_AKONADI_LIBS} ${KDE4_KABC_LIBS} ${KDE4_KCAL_LIBS} ${KDE4_SYNDICATION_LIBS} ${KDE4_KDECORE_LIBS} ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTDBUS_LIBRARY} ) install(TARGETS akonaditest ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/akonadi/tests/testrunner/config.cpp b/akonadi/tests/testrunner/config.cpp index bf89c6dc9..c4031eb39 100644 --- a/akonadi/tests/testrunner/config.cpp +++ b/akonadi/tests/testrunner/config.cpp @@ -1,102 +1,137 @@ /* * Copyright (c) 2008 Igor Trindade Oliveira * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "config.h" -#include "configreader.h" #include #include #include +#include +#include +#include +#include +#include -Config* Config::mInstance = 0; + +Q_GLOBAL_STATIC(Config, globalConfig) Config::Config() { } -Config *Config::instance( const QString& pathToConfig ) +Config::~Config() { - if ( mInstance == 0 ) { - QString cfgFile = pathToConfig; - if ( cfgFile.isEmpty() ) - cfgFile = KStandardDirs::locate( "config", "akonaditest.xml" ); +} - mInstance = new ConfigReader( cfgFile ); - } +Config *Config::instance(const QString &pathToConfig) +{ + if ( !pathToConfig.isEmpty() ) + globalConfig()->readConfiguration(pathToConfig); - return mInstance; + return globalConfig(); } - -void Config::destroyInstance() +void Config::readConfiguration(const QString &configfile) { - delete mInstance; + QDomDocument doc; + QFile file( configfile ); + + if ( !file.open( QIODevice::ReadOnly ) ) + qFatal( "error reading file: %s", qPrintable( configfile ) ); + + QString errorMsg; + if ( !doc.setContent( &file, &errorMsg ) ) + qFatal( "unable to parse config file: %s", qPrintable( errorMsg ) ); + + const QDomElement root = doc.documentElement(); + if ( root.tagName() != "config" ) + qFatal( "could not file root tag" ); + + const QString basePath = QFileInfo( configfile ).absolutePath() + "/"; + + QDomNode node = root.firstChild(); + while ( !node.isNull() ) { + const QDomElement element = node.toElement(); + if ( !element.isNull() ) { + if ( element.tagName() == "kdehome" ) { + setKdeHome( basePath + element.text() ); + } else if ( element.tagName() == "confighome" ) { + setXdgConfigHome( basePath + element.text() ); + } else if ( element.tagName() == "datahome" ) { + setXdgDataHome( basePath + element.text() ); + } else if ( element.tagName() == "agent" ) { + insertAgent( element.text(), element.attribute( "synchronize", "false" ) == QLatin1String("true") ); + } + } + + node = node.nextSibling(); + } } QString Config::kdeHome() const { return mKdeHome; } QString Config::xdgDataHome() const { return mXdgDataHome; } QString Config::xdgConfigHome() const { return mXdgConfigHome; } void Config::setKdeHome( const QString &home ) { const QDir kdeHomeDir( home ); mKdeHome = kdeHomeDir.absolutePath(); } void Config::setXdgDataHome( const QString &dataHome ) { const QDir dataHomeDir( dataHome ); mXdgDataHome = dataHomeDir.absolutePath(); } void Config::setXdgConfigHome( const QString &configHome ) { const QDir configHomeDir( configHome ); mXdgConfigHome = configHomeDir.absolutePath(); } void Config::insertItemConfig( const QString &itemName, const QString &collectionName ) { mItemConfig.append( qMakePair( itemName, collectionName ) ); } QList< QPair > Config::itemConfig() const { return mItemConfig; } void Config::insertAgent( const QString &agent, bool sync ) { mAgents.append( qMakePair( agent, sync ) ); } QList > Config::agents() const { return mAgents; } diff --git a/akonadi/tests/testrunner/config.h b/akonadi/tests/testrunner/config.h index adc96d3cd..0f564e809 100644 --- a/akonadi/tests/testrunner/config.h +++ b/akonadi/tests/testrunner/config.h @@ -1,53 +1,56 @@ /* * Copyright (c) 2008 Igor Trindade Oliveira * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef CONFIG_H #define CONFIG_H #include #include #include class Config { public: + Config(); + ~Config(); static Config *instance( const QString &pathToConfig = QString() ); static void destroyInstance(); QString kdeHome() const; QString xdgDataHome() const; QString xdgConfigHome() const; QList > itemConfig() const; QList > agents() const; protected: - Config(); void setKdeHome( const QString &home ); void setXdgDataHome( const QString &dataHome ); void setXdgConfigHome( const QString &configHome ); void insertItemConfig( const QString &itemName, const QString &collectionName ); void insertAgent( const QString &agent, bool sync ); + private: + void readConfiguration(const QString &configFile); + private: QString mKdeHome; QString mXdgDataHome; QString mXdgConfigHome; QList > mItemConfig; QList > mAgents; - static Config *mInstance; }; #endif diff --git a/akonadi/tests/testrunner/configreader.cpp b/akonadi/tests/testrunner/configreader.cpp deleted file mode 100644 index 5c65f6448..000000000 --- a/akonadi/tests/testrunner/configreader.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008 Igor Trindade Oliveira - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#include "configreader.h" -#include "config.h" -#include "symbols.h" - -#include -#include -#include -#include -#include - -ConfigReader::ConfigReader( const QString &configfile ) -{ - QDomDocument doc; - QFile file( configfile ); - - if ( !file.open( QIODevice::ReadOnly ) ) - qFatal( "error reading file: %s", qPrintable( configfile ) ); - - QString errorMsg; - if ( !doc.setContent( &file, &errorMsg ) ) - qFatal( "unable to parse config file: %s", qPrintable( errorMsg ) ); - - const QDomElement root = doc.documentElement(); - if ( root.tagName() != "config" ) - qFatal( "could not file root tag" ); - - const QString basePath = QFileInfo( configfile ).absolutePath() + "/"; - - QDomNode node = root.firstChild(); - while ( !node.isNull() ) { - const QDomElement element = node.toElement(); - if ( !element.isNull() ) { - if ( element.tagName() == "kdehome" ) { - setKdeHome( basePath + element.text() ); - } else if ( element.tagName() == "confighome" ) { - setXdgConfigHome( basePath + element.text() ); - } else if ( element.tagName() == "datahome" ) { - setXdgDataHome( basePath + element.text() ); - } else if ( element.tagName() == "item" ) { - insertItemConfig( element.attribute( "location" ), element.attribute( "collection" ) ); - } else if ( element.tagName() == "agent" ) { - insertAgent( element.text(), element.attribute( "synchronize", "false" ) == QLatin1String("true") ); - } - } - - node = node.nextSibling(); - } -} diff --git a/akonadi/tests/testrunner/configreader.h b/akonadi/tests/testrunner/configreader.h deleted file mode 100644 index db1e88d51..000000000 --- a/akonadi/tests/testrunner/configreader.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2008 Igor Trindade Oliveira - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -#ifndef CONFIGREADER_H -#define CONFIGREADER_H - -#include "config.h" - -class QString; - -class ConfigReader : public Config -{ - public: - ConfigReader( const QString &configfile ); -}; - -#endif diff --git a/akonadi/tests/testrunner/main.cpp b/akonadi/tests/testrunner/main.cpp index 71ba226b5..fbdb4e907 100644 --- a/akonadi/tests/testrunner/main.cpp +++ b/akonadi/tests/testrunner/main.cpp @@ -1,117 +1,116 @@ /* * * Copyright (c) 2008 Igor Trindade Oliveira * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "config.h" #include "setup.h" #include "shellscript.h" #include "testrunner.h" #include #include #include #include #include static SetupTest *setup = 0; static TestRunner *runner = 0; void sigHandler( int signal ) { kDebug() << "Received signal" << signal; static int sigCounter = 0; if ( sigCounter == 0 ) { // try clean shutdown if ( runner ) runner->terminate(); if ( setup ) setup->shutdown(); } else if ( sigCounter == 1 ) { // force shutdown if ( setup ) setup->shutdownHarder(); } else { // give up and just exit exit( 255 ); } ++sigCounter; } int main( int argc, char **argv ) { KAboutData aboutdata( "akonadi-TES", 0, ki18n( "Akonadi Testing Environment Setup" ), "1.0", ki18n( "Setup Environmnet" ), KAboutData::License_GPL, ki18n( "(c) 2008 Igor Trindade Oliveira" ) ); KCmdLineArgs::init( argc, argv, &aboutdata ); KCmdLineOptions options; options.add( "c" ).add( "config ", ki18n( "Configuration file to open" ), "config.xml" ); options.add( "!+[test]", ki18n( "Test to run automatically, interactive if none specified" ) ); options.add("testenv ", ki18n("Path where testenvironment would be saved")); KCmdLineArgs::addCmdLineOptions( options ); KApplication app; const KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->isSet( "config" ) ) Config::instance( args->getOption( "config" ) ); #ifdef Q_OS_UNIX signal( SIGINT, sigHandler ); signal( SIGQUIT, sigHandler ); #endif setup = new SetupTest(); if ( !setup->startAkonadiDaemon() ) { delete setup; return 1; } ShellScript *sh = new ShellScript(); if( args->isSet("testenv")) sh->makeShellScript( args->getOption("testenv")); else sh->makeShellScript( setup->basePath() + "testenvironment.sh" ); if ( args->count() > 0 ) { QStringList testArgs; for ( int i = 0; i < args->count(); ++i ) testArgs << args->arg( i ); runner = new TestRunner( testArgs ); QObject::connect( setup, SIGNAL( setupDone() ), runner, SLOT( run() ) ); QObject::connect( runner, SIGNAL( finished() ), setup, SLOT( shutdown() ) ); } int exitCode = app.exec(); if ( runner ) { exitCode += runner->exitCode(); delete runner; } - Config::destroyInstance(); delete setup; setup = 0; delete sh; return exitCode; }