diff --git a/akonadi/tests/CMakeLists.txt b/akonadi/tests/CMakeLists.txt index e73c5dc30..5d40ce41f 100644 --- a/akonadi/tests/CMakeLists.txt +++ b/akonadi/tests/CMakeLists.txt @@ -1,108 +1,108 @@ if(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH} ) else(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH . ) endif(${EXECUTABLE_OUTPUT_PATH}) set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) include_directories( ${CMAKE_SOURCE_DIR}/akonadi ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ${Boost_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ) # add testrunner (application for managing a self-contained test # environment) add_subdirectory(testrunner) # add benchmarker add_subdirectory(benchmarker) # convenience macro to add akonadi demo application macro(add_akonadi_demo _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS}) endmacro(add_akonadi_demo) # convenience macro to add akonadi qtestlib unit-tests macro(add_akonadi_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_unit_test(${_name} TESTNAME libakonadi-${_name} ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) endmacro(add_akonadi_test) # convenience macro to add akonadi testrunner unit-tests macro(add_akonadi_isolated_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) # based on kde4_add_unit_test if (WIN32) get_target_property( _loc ${_name} LOCATION ) set(_executable ${_loc}.bat) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest.bat) else (WIN32) set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_name}) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest) endif (WIN32) if (UNIX) set(_executable ${_executable}.shell) set(_testrunner ${_testrunner}.shell) endif (UNIX) add_test( libakonadi-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) endmacro(add_akonadi_isolated_test) # demo applications add_akonadi_demo(itemdumper.cpp) -add_akonadi_demo(collectioncreator.cpp) add_akonadi_demo(subscriber.cpp) add_akonadi_demo(headfetcher.cpp) add_akonadi_demo(agentinstancewidgettest.cpp) add_akonadi_demo(agenttypewidgettest.cpp) add_akonadi_demo(pluginloadertest.cpp) add_akonadi_demo(selftester.cpp) kde4_add_executable( akonadi-firstrun TEST ../firstrun.cpp firstrunner.cpp ) target_link_libraries( akonadi-firstrun akonadi-kde ${KDE4_KDEUI_LIBS} ) # qtestlib unit tests add_akonadi_test(imapparsertest.cpp) add_akonadi_test(imapsettest.cpp) add_akonadi_test(itemhydratest.cpp) add_akonadi_test(itemtest.cpp) add_akonadi_test(itemserializertest.cpp) add_akonadi_test(notificationmessagetest.cpp) # testrunner tests add_akonadi_isolated_test(testenvironmenttest.cpp) add_akonadi_isolated_test(collectionjobtest.cpp) add_akonadi_isolated_test(collectionpathresolvertest.cpp) add_akonadi_isolated_test(collectionattributetest.cpp) add_akonadi_isolated_test(itemfetchtest.cpp) add_akonadi_isolated_test(itemappendtest.cpp) add_akonadi_isolated_test(itemstoretest.cpp) add_akonadi_isolated_test(monitortest.cpp) add_akonadi_isolated_test(searchjobtest.cpp) add_akonadi_isolated_test(changerecordertest.cpp) add_akonadi_isolated_test(resourcetest.cpp) add_akonadi_isolated_test(subscriptiontest.cpp) add_akonadi_isolated_test(transactiontest.cpp) add_akonadi_isolated_test(itemcopytest.cpp) add_akonadi_isolated_test(itemmovetest.cpp) add_akonadi_isolated_test(collectioncopytest.cpp) add_akonadi_isolated_test(itemsynctest.cpp) add_akonadi_isolated_test(linktest.cpp) add_akonadi_isolated_test(servermanagertest.cpp) +add_akonadi_isolated_test(collectioncreator.cpp) diff --git a/akonadi/tests/collectioncreator.cpp b/akonadi/tests/collectioncreator.cpp index e39298191..68096b517 100644 --- a/akonadi/tests/collectioncreator.cpp +++ b/akonadi/tests/collectioncreator.cpp @@ -1,73 +1,88 @@ /* - Copyright (c) 2006 Volker Krause + Copyright (c) 2006, 2009 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "collectioncreator.h" +#include "agentinstance.h" +#include "agentmanager.h" #include "collectioncreatejob.h" #include "collectionpathresolver_p.h" +#include "transactionjobs.h" -#include -#include - -#include -#include +#include "qtest_akonadi.h" +#include "test_utils.h" -#define COLLECTION_COUNT 1000 +#include using namespace Akonadi; -CollectionCreator::CollectionCreator( ) +class CollectionCreator : public QObject { - jobCount = 0; - CollectionPathResolver *resolver = new CollectionPathResolver( "res3", this ); - if ( !resolver->exec() ) - qFatal( "Cannot resolve path." ); - int root = resolver->collection(); - startTime.start(); - for ( int i = 0; i < COLLECTION_COUNT; ++i ) { - Collection col; - col.setParent( root ); - col.setName( QLatin1String("col") + QString::number( i ) ); - CollectionCreateJob *job = new CollectionCreateJob( col, this ); - connect( job, SIGNAL(result(KJob*)), SLOT(done(KJob*)) ); - ++jobCount; - } -} + Q_OBJECT + private slots: + void initTestCase() + { + // switch all resources offline to reduce interference from them + foreach ( Akonadi::AgentInstance agent, Akonadi::AgentManager::self()->instances() ) + agent.setIsOnline( false ); + } + + void createCollections_data() + { + QTest::addColumn( "count" ); + QTest::addColumn( "useTransaction" ); -void CollectionCreator::done( KJob * job ) -{ - if ( job->error() ) - qWarning() << "collection creation failed: " << job->errorString(); - --jobCount; - if ( jobCount <= 0 ) { - qDebug() << "creation took: " << startTime.elapsed() << "ms."; - qApp->quit(); - } -} + QList counts = QList() << 1 << 10 << 100 << 1000; + QList transactions = QList() << false << true; + foreach( int count, counts ) + foreach( bool transaction, transactions ) + QTest::newRow( QString::fromLatin1( "%1-%2" ).arg( count ).arg( transaction ? "trans" : "notrans" ).toLatin1().constData() ) + << count << transaction; + } + void createCollections() + { + QFETCH( int, count ); + QFETCH( bool, useTransaction ); -int main( int argc, char** argv ) -{ - KCmdLineArgs::init( argc, argv, "test", 0, ki18n("Test") ,"1.0" ,ki18n("test app") ); - KApplication app; - CollectionCreator *cc = new CollectionCreator(); - return app.exec(); - delete cc; -} + const Collection parent( collectionIdFromPath( "res3" ) ); + QVERIFY( parent.isValid() ); + + static int index = 0; + Job *lastJob = 0; +#if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0)) + QBENCHMARK +#endif + { + if ( useTransaction ) + lastJob = new TransactionBeginJob( this ); + for ( int i = 0; i < count; ++i ) { + Collection col; + col.setParent( parent ); + col.setName( QLatin1String("col") + QString::number( ++index ) ); + lastJob = new CollectionCreateJob( col, this ); + } + if ( useTransaction ) + lastJob = new TransactionCommitJob( this ); + QTest::kWaitForSignal( lastJob, SIGNAL(result(KJob*)) ); + } + } +}; + +QTEST_AKONADIMAIN( CollectionCreator, NoGUI ) #include "collectioncreator.moc" diff --git a/akonadi/tests/collectioncreator.h b/akonadi/tests/collectioncreator.h deleted file mode 100644 index 2f610dd48..000000000 --- a/akonadi/tests/collectioncreator.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 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 Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef COLLECTIONCREATOR_H -#define COLLECTIONCREATOR_H - -#include -#include -#include - -class CollectionCreator : public QObject -{ - Q_OBJECT - public: - CollectionCreator(); - private Q_SLOTS: - void done(KJob *job); - private: - int jobCount; - QTime startTime; -}; - -#endif