diff --git a/akonadi/tests/CMakeLists.txt b/akonadi/tests/CMakeLists.txt index bd021bd44..2f4d7a00a 100644 --- a/akonadi/tests/CMakeLists.txt +++ b/akonadi/tests/CMakeLists.txt @@ -1,126 +1,128 @@ 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} + ${AKONADI_INCLUDE_DIR}/akonadi/private ) # 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 akonadi-${_name} ${_test}) + kde4_add_unit_test(${_name} TESTNAME akonadi-${_name} ${_test} fakesession.cpp fakemonitor.cpp fakeserver.cpp) 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( akonadi-mysql-db-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config-mysql-db.xml ${_executable} ) add_test( akonadi-mysql-fs-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config-mysql-fs.xml ${_executable} ) #add_test( akonadi-postgresql-fs-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config-postgresql-fs.xml ${_executable} ) #add_test( akonadi-postgresql-fs-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config-postgresql-fs.xml ${_executable} ) #add_test( akonadi-sqlite-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config-sqlite.xml ${_executable} ) endmacro(add_akonadi_isolated_test) # demo applications add_akonadi_demo(itemdumper.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(mimetypecheckertest.cpp) add_akonadi_test(protocolhelpertest.cpp) +add_akonadi_test(entitytreemodeltest.cpp) # qtestlib tests that need non-exported stuff from akonadi-kde kde4_add_unit_test(resourceschedulertest TESTNAME akonadi-resourceschedulertest resourceschedulertest.cpp ../resourcescheduler.cpp) target_link_libraries(resourceschedulertest akonadi-kde ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) # testrunner tests add_akonadi_isolated_test(testenvironmenttest.cpp) add_akonadi_isolated_test(autoincrementtest.cpp) add_akonadi_isolated_test(attributefactorytest.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(itemdeletetest.cpp) add_akonadi_isolated_test(entitycachetest.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(collectionmovetest.cpp) add_akonadi_isolated_test(collectionsynctest.cpp) add_akonadi_isolated_test(itemsynctest.cpp) add_akonadi_isolated_test(linktest.cpp) add_akonadi_isolated_test(cachetest.cpp) add_akonadi_isolated_test(servermanagertest.cpp) add_akonadi_isolated_test(collectioncreator.cpp) add_akonadi_isolated_test(itembenchmark.cpp) diff --git a/akonadi/tests/entitytreemodeltest.cpp b/akonadi/tests/entitytreemodeltest.cpp new file mode 100644 index 000000000..c1be6034e --- /dev/null +++ b/akonadi/tests/entitytreemodeltest.cpp @@ -0,0 +1,81 @@ +/* + Copyright (c) 2009 Stephen Kelly + + 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 +#include "fakeserver.h" +#include "fakesession.h" +#include "fakemonitor.h" +// #include "modelspy.h" + +#include "entitytreemodel.h" + +using namespace Akonadi; + +class EntityTreeModelTest : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + + void init(); + + void testCollectionFetch(); + +private: + EntityTreeModel *m_model; +// ModelSpy *m_modelSpy; + FakeAkonadiServer *m_fakeServer; + FakeSession *m_fakeSession; + FakeMonitor *m_fakeMonitor; +}; + + +void EntityTreeModelTest::initTestCase() +{ + m_fakeServer = new FakeAkonadiServer(); + m_fakeServer->start(); + +} + +void EntityTreeModelTest::init() +{ + FakeSession *fakeSession = new FakeSession( "EntityTreeModelTest fake session", this); + FakeMonitor *fakeMonitor = new FakeMonitor(this); + m_model = new EntityTreeModel(fakeSession, fakeMonitor); +// m_modelSpy = new ModelSpy(this); +// m_modelSpy->setModel(m_model); + +} + +void EntityTreeModelTest::testCollectionFetch() +{ + kDebug() << 2; + QTest::qWait(1000); +// sleep(10); +// QList collectionChunks; +// m_fakeSession->firstListJobResult(collectionChunks); +} + + +// #endif +#include "entitytreemodeltest.moc" + +QTEST_KDEMAIN(EntityTreeModelTest, NoGUI) + diff --git a/akonadi/tests/fakemonitor.cpp b/akonadi/tests/fakemonitor.cpp new file mode 100644 index 000000000..61cc54d20 --- /dev/null +++ b/akonadi/tests/fakemonitor.cpp @@ -0,0 +1,27 @@ +/* + Copyright (c) 2009 Stephen Kelly + + 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 "fakemonitor.h" + + +FakeMonitor::FakeMonitor(QObject* parent): Monitor(parent) +{ + +} diff --git a/akonadi/tests/fakemonitor.h b/akonadi/tests/fakemonitor.h new file mode 100644 index 000000000..91920ad65 --- /dev/null +++ b/akonadi/tests/fakemonitor.h @@ -0,0 +1,34 @@ +/* + Copyright (c) 2009 Stephen Kelly + + 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 FAKEMONITOR_H +#define FAKEMONITOR_H + +#include "monitor.h" + +class FakeMonitor : public Akonadi::Monitor +{ + Q_OBJECT +public: + FakeMonitor(QObject* parent = 0); + +}; + +#endif + diff --git a/akonadi/tests/fakeserver.cpp b/akonadi/tests/fakeserver.cpp new file mode 100644 index 000000000..805fed345 --- /dev/null +++ b/akonadi/tests/fakeserver.cpp @@ -0,0 +1,102 @@ +/* + Copyright (C) 2008 Omat Holding B.V. + Copyright (C) 2009 Stephen Kelly + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +// Own +#include "fakeserver.h" + +// Qt +#include + +// KDE +#include + +// For unlink +# include + +FakeAkonadiServer::FakeAkonadiServer( QObject* parent ) : QThread( parent ) +{ + moveToThread(this); +} + + +FakeAkonadiServer::~FakeAkonadiServer() +{ + quit(); + wait(); +} + +void FakeAkonadiServer::dataAvailable() +{ + QMutexLocker locker(&m_mutex); + + QByteArray data = m_localSocket->readAll(); + + if (data.startsWith("0 LOGIN")) + { + m_localSocket->write( "0 OK User logged in\r\n" ); + return; + } + + Q_ASSERT( !m_data.isEmpty() ); + + QByteArray toWrite = QString( m_data.takeFirst() + "\r\n" ).toLatin1(); + + Q_FOREVER { + m_localSocket->write( toWrite ); + if (toWrite.startsWith("* ")) { + toWrite = QString( m_data.takeFirst() + "\r\n" ).toLatin1(); + } else + break; + } +} + +void FakeAkonadiServer::newConnection() +{ + QMutexLocker locker(&m_mutex); + + m_localSocket = m_localServer->nextPendingConnection(); + m_localSocket->write( QByteArray( "* OK Akonadi Fake Server [PROTOCOL 17]\r\n" ) ); + connect(m_localSocket, SIGNAL(readyRead()), this, SLOT(dataAvailable())); +} + +void FakeAkonadiServer::run() +{ + m_localServer = new QLocalServer(); + const QString socketFile = QLatin1String( "/tmp/akonadi-test/fakeakonadiserver.socket" ); + unlink( socketFile.toUtf8().constData() ); + if ( !m_localServer->listen( socketFile ) ) { + kFatal() << "Unable to start the server"; + } + + connect(m_localServer, SIGNAL(newConnection()), this, SLOT(newConnection())); + + m_data += QString("Foo"); + exec(); + disconnect(m_localSocket, SIGNAL(readyRead()), this, SLOT(dataAvailable())); + delete m_localServer; +} + +void FakeAkonadiServer::setResponse( const QStringList& data ) +{ + QMutexLocker locker(&m_mutex); + + m_data+= data; +} + +// #include "fakeserver.moc" diff --git a/akonadi/tests/fakeserver.h b/akonadi/tests/fakeserver.h new file mode 100644 index 000000000..b2b496c5c --- /dev/null +++ b/akonadi/tests/fakeserver.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2008 Omat Holding B.V. + Copyright (C) 2009 Stephen Kelly + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef FAKE_AKONADI_SERVER_H +#define FAKE_AKONADI_SERVER_H + +// Renamed and refactored from kdepimlibs/kimap/tests/fakeserver + +#include +#include +#include +#include +#include +#include + +class FakeAkonadiServer : public QThread +{ + Q_OBJECT + +public: + FakeAkonadiServer( QObject* parent = 0 ); + ~FakeAkonadiServer(); + virtual void run(); + void setResponse( const QStringList& data ); + +private Q_SLOTS: + void newConnection(); + void dataAvailable(); + +private: + QStringList m_data; + QLocalServer *m_localServer; + QMutex m_mutex; + QLocalSocket* m_localSocket; +}; + +#endif + diff --git a/akonadi/tests/fakesession.cpp b/akonadi/tests/fakesession.cpp new file mode 100644 index 000000000..52efb8f57 --- /dev/null +++ b/akonadi/tests/fakesession.cpp @@ -0,0 +1,39 @@ +/* + Copyright (c) 2009 Stephen Kelly + + 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 "fakesession.h" +#include "session_p.h" + +#include + +FakeSession::FakeSession(const QByteArray& sessionId, QObject* parent) + : Session(sessionId, parent) +{ + +} + +void FakeSession::firstListJobResult(QList collectionChunks) +{ + // write the collection chunks to the socket. +} + + + diff --git a/akonadi/tests/fakesession.h b/akonadi/tests/fakesession.h new file mode 100755 index 000000000..1d1fab1c1 --- /dev/null +++ b/akonadi/tests/fakesession.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2009 Stephen Kelly + + 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 FAKESESSION_H +#define FAKESESSION_H + +#include "session.h" +#include "collection.h" + + +using namespace Akonadi; + +class FakeSession : public Session +{ + Q_OBJECT +public: + explicit FakeSession(const QByteArray& sessionId = QByteArray(), QObject* parent = 0); + + void firstListJobResult(QList collectionChunks); + +}; + +#endif