diff --git a/akonadi/tests/testrunner/CMakeLists.txt b/akonadi/tests/testrunner/CMakeLists.txt new file mode 100644 index 000000000..f831fa93d --- /dev/null +++ b/akonadi/tests/testrunner/CMakeLists.txt @@ -0,0 +1,11 @@ +project (akonaditest) + +include_directories(${KDE4_INCLUDES}) +include_directories (${Boost_INCLUDE_DIR}) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) + +set(akonaditest_SRCS main.cpp akonaditesting.cpp dao.cpp item.cpp itemfactory.cpp calitem.cpp vcarditem.cpp feeditem.cpp setup.cpp configreader.cpp config.cpp shellscript.cpp symbols.cpp) + +kde4_add_executable(akonaditest ${akonaditest_SRCS}) +target_link_libraries(akonaditest ${KDE4_KDEUI_LIB} ${Boost_LIBRARIES} ${KDE4_AKONADI_LIBS} ${KDE4_KABC_LIBS} ${KDE4_KCAL_LIBS} ${KDE4_SYNDICATION_LIBS} ) +install(TARGETS akonaditest ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/akonadi/tests/testrunner/akonaditesting.cpp b/akonadi/tests/testrunner/akonaditesting.cpp new file mode 100644 index 000000000..06f0636e6 --- /dev/null +++ b/akonadi/tests/testrunner/akonaditesting.cpp @@ -0,0 +1,73 @@ +/* + * 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 "akonaditesting.h" +#include "itemfactory.h" +#include "config.h" +#include +#include +#include +#include + +AkonadiTesting::AkonadiTesting( const QString &configfilename ) +{ + +} + +AkonadiTesting::AkonadiTesting() +{ +} +void AkonadiTesting::insertItem(const QString &filename, const QString &colname) +{ + ItemFactory factory; + DAO dao; + + Akonadi::Collection collection = dao.getCollectionByName(colname); + + QFile *file = new QFile(filename); + qDebug()<fileName(); + file->open(QFile::ReadOnly); + + Item *item = factory.createItem(file); + + foreach(const Akonadi::Item &akonaditem, item->getItem()){ + if( dao.insertItem(akonaditem, collection ) ){ + qDebug()<<"Item loaded to Akonadi"; + } else { + qDebug()<<"Item can not be loaded"; + } + } + + delete file; +} + +void AkonadiTesting::insertItemFromList() +{ + Config *config = Config::getInstance(); + QPair confitem; + + foreach(confitem, config->getItemConfig() ){ + insertItem(confitem.first, confitem.second); + } + + //delete config; +} +AkonadiTesting::~AkonadiTesting() +{ +} + + diff --git a/akonadi/tests/testrunner/akonaditesting.h b/akonadi/tests/testrunner/akonaditesting.h new file mode 100644 index 000000000..64acb1c89 --- /dev/null +++ b/akonadi/tests/testrunner/akonaditesting.h @@ -0,0 +1,36 @@ +/* + * 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 AKONADITESTING_H +#define AKONADITESTING_H + +#include "item.h" +#include "dao.h" +#include +#include + +class AkonadiTesting{ + +public: + void insertItem(const QString &filename, const QString &colname); + void insertItemFromList(); + AkonadiTesting(const QString &filename); + AkonadiTesting(); + ~AkonadiTesting(); +}; + +#endif diff --git a/akonadi/tests/testrunner/calitem.cpp b/akonadi/tests/testrunner/calitem.cpp new file mode 100644 index 000000000..fdf35a80e --- /dev/null +++ b/akonadi/tests/testrunner/calitem.cpp @@ -0,0 +1,42 @@ +/* + * 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 "calitem.h" +#include "item.h" +#include +#include +#include +#include + +typedef boost::shared_ptr IncidencePtr; + +CalItem::CalItem( QFile *file, const QString &mimetype) +:Item(mimetype) { + KCal::CalendarLocal calendarlocal(KDateTime::UTC); + + if( calendarlocal.load(file->fileName() )){ + KCal::Incidence::List incidence = calendarlocal.rawIncidences(); + for(int i = 0; i < incidence.size(); i++){ + Akonadi::Item itemtmp; + itemtmp.setMimeType(mimetype); + itemtmp.setPayload(IncidencePtr( incidence.at(i)->clone() )); + item.append(itemtmp); + } + } +} + diff --git a/akonadi/tests/testrunner/calitem.h b/akonadi/tests/testrunner/calitem.h new file mode 100644 index 000000000..b158efffa --- /dev/null +++ b/akonadi/tests/testrunner/calitem.h @@ -0,0 +1,39 @@ +/* + * 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 CALITEM_H +#define CALITEM_H + +#include "item.h" +#include +#include +#include +#include +#include + + + +class CalItem: public Item{ +private: + void insertTodo( KCal::Todo::List todolist ); + void insertEvent(KCal::Event::List eventlist); +public: + CalItem(QFile *file, const QString &mimetype); +}; + +#endif diff --git a/akonadi/tests/testrunner/config.cpp b/akonadi/tests/testrunner/config.cpp new file mode 100644 index 000000000..0f84b52d6 --- /dev/null +++ b/akonadi/tests/testrunner/config.cpp @@ -0,0 +1,99 @@ +/* + * 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 + + +Config* Config::instance = 0; + +Config::Config() +{ +} + +Config *Config::getInstance() +{ + if(instance == 0){ + const QString pathToConfig = KStandardDirs::locate("config","akonaditest.xml"); + instance = new ConfigReader(pathToConfig); + //instance= new ConfigReader("/home/igor/codes/kde/tests/test_akonadi/config.xml"); + } + return instance; +} + +void Config::destroyInstance() +{ + delete instance; +} + +QString Config::getKdeHome() const +{ + return kdehome; +} + +QString Config::getXdgDataHome() const +{ + return xdgdatahome; +} + +QString Config::getXdgConfigHome() const +{ + return xdgconfighome; +} + +void Config::setKdeHome(const QString &home) +{ + QDir kdeHomeDir( home ); + kdehome = kdeHomeDir.absolutePath(); +} + +void Config::setXdgDataHome(const QString &datahome) +{ + QDir dataHomeDir( datahome ); + xdgdatahome = dataHomeDir.absolutePath(); +} + +void Config::setXdgConfigHome(const QString &confighome) +{ + QDir configHomeDir( confighome ); + xdgconfighome = configHomeDir.absolutePath(); +} + +void Config::insertItemConfig(const QString &itemname, const QString &colname) +{ + itemconfig.append( qMakePair(itemname, colname) ); +} + +QList< QPair > Config::getItemConfig() +{ + return itemconfig; +} + +void Config::insertAgent(QString agent) +{ + mAgents << agent; +} + +QStringList Config::getAgents() +{ + return mAgents; +} diff --git a/akonadi/tests/testrunner/config.h b/akonadi/tests/testrunner/config.h new file mode 100644 index 000000000..438d70f51 --- /dev/null +++ b/akonadi/tests/testrunner/config.h @@ -0,0 +1,54 @@ +/* + * 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 +{ + private: + QString kdehome; + QString xdgdatahome; + QString xdgconfighome; + QList > itemconfig; + QStringList mAgents; + static Config *instance; + + public: + static Config *getInstance(); + static void destroyInstance(); + QString getKdeHome() const; + QString getXdgDataHome() const; + QString getXdgConfigHome() const; + QList > getItemConfig(); + QStringList getAgents(); + + protected: + Config(); + void setKdeHome(const QString &home); + void setXdgDataHome(const QString &datahome); + void setXdgConfigHome(const QString &confighome); + void insertItemConfig(const QString &itemname, const QString &colname); + void insertAgent(QString agent); + +}; + +#endif diff --git a/akonadi/tests/testrunner/config.xml b/akonadi/tests/testrunner/config.xml new file mode 100644 index 000000000..86e5a2ec0 --- /dev/null +++ b/akonadi/tests/testrunner/config.xml @@ -0,0 +1,6 @@ + + kde + config + local/share + + diff --git a/akonadi/tests/testrunner/configreader.cpp b/akonadi/tests/testrunner/configreader.cpp new file mode 100644 index 000000000..5b1c7cc3b --- /dev/null +++ b/akonadi/tests/testrunner/configreader.cpp @@ -0,0 +1,74 @@ +/* + * 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 ) ){ + qDebug()<<"error reading file:"< + * + * 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 CONFIGHEADER_H + +#include +#include "config.h" + +class ConfigReader:public Config +{ + public: + ConfigReader(const QString &configfile); +}; + +#endif diff --git a/akonadi/tests/testrunner/dao.cpp b/akonadi/tests/testrunner/dao.cpp new file mode 100644 index 000000000..7ee60c616 --- /dev/null +++ b/akonadi/tests/testrunner/dao.cpp @@ -0,0 +1,45 @@ +/* + * 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 "dao.h" +#include +#include +#include + +Akonadi::Collection::List DAO::showCollections(){ + Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( + Akonadi::Collection::root(), + Akonadi::CollectionFetchJob::Recursive); + + job->exec(); + Akonadi::Collection::List collections = job->collections(); + return collections; +} + +Akonadi::Collection DAO::getCollectionByName(const QString &colname){ + Akonadi::Collection::List colist = showCollections(); + + foreach(const Akonadi::Collection &col, colist){ + if( colname == col.name() ) return col; + } +} + +bool DAO::insertItem(Akonadi::Item item, Akonadi::Collection collection){ + Akonadi::ItemCreateJob *ijob = new Akonadi::ItemCreateJob(item, collection); + + return ijob->exec(); +} diff --git a/akonadi/tests/testrunner/dao.h b/akonadi/tests/testrunner/dao.h new file mode 100644 index 000000000..d827f4149 --- /dev/null +++ b/akonadi/tests/testrunner/dao.h @@ -0,0 +1,18 @@ +#ifndef DAO_H +#define DAO_H + +#include +#include +#include +#include + +class DAO{ + + +public: + bool insertItem(Akonadi::Item item, Akonadi::Collection collection); + Akonadi::Collection::List showCollections(); + Akonadi::Collection getCollectionByName(const QString &colname); +}; + +#endif diff --git a/akonadi/tests/testrunner/feeditem.cpp b/akonadi/tests/testrunner/feeditem.cpp new file mode 100644 index 000000000..543c22157 --- /dev/null +++ b/akonadi/tests/testrunner/feeditem.cpp @@ -0,0 +1,60 @@ +/* + * 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 "feeditem.h" +#include +#include +#include +#include +#include +#include +#include + + +FeedItem::FeedItem(QFile *file, const QString &mimetype) +:Item(mimetype) +{ + KUrl kurl; + if (!KUrl::isRelativeUrl( file->fileName() )) + kurl = KUrl( file->fileName() ); + else + kurl = KUrl("file://" + QDir::currentPath() + '/', file->fileName() ); + + Syndication::Loader* loader = Syndication::Loader::create(this, + SLOT(feedLoaded(Syndication::Loader*, + Syndication::FeedPtr, + Syndication::ErrorCode))); + loader->loadFrom(kurl); + + QEventLoop *test = new QEventLoop(this); + while(test->processEvents(QEventLoop::WaitForMoreEvents)); //workaround +} + +void FeedItem::feedLoaded(Syndication::Loader* loader, + Syndication::FeedPtr feed, + Syndication::ErrorCode error) +{ + if( error != Syndication::Success) + return; + + foreach(const Syndication::ItemPtr &itemptr, feed->items()){ + Akonadi::Item i; + i.setMimeType(mimetype); + i.setPayload( itemptr ); + item.append( i ); + } +} diff --git a/akonadi/tests/testrunner/feeditem.h b/akonadi/tests/testrunner/feeditem.h new file mode 100644 index 000000000..a76700ddb --- /dev/null +++ b/akonadi/tests/testrunner/feeditem.h @@ -0,0 +1,40 @@ +/* + * 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 FEEDITEM_H +#define FEEDITEM_H + +#include "item.h" +#include +#include +#include + +class FeedItem : public QObject, public Item +{ + Q_OBJECT + + public: + FeedItem(QFile *file, const QString &mimetype); + + private Q_SLOTS: + void feedLoaded(Syndication::Loader* loader, + Syndication::FeedPtr feed, + Syndication::ErrorCode error); + +}; + +#endif diff --git a/akonadi/tests/testrunner/item.cpp b/akonadi/tests/testrunner/item.cpp new file mode 100644 index 000000000..0a188df6c --- /dev/null +++ b/akonadi/tests/testrunner/item.cpp @@ -0,0 +1,28 @@ +/* + * 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 "item.h" + + +Item::Item(QString mimetype){ + this->mimetype = mimetype; +} + +QList Item::getItem() const { + return item; +} + diff --git a/akonadi/tests/testrunner/item.h b/akonadi/tests/testrunner/item.h new file mode 100644 index 000000000..3c0aa573c --- /dev/null +++ b/akonadi/tests/testrunner/item.h @@ -0,0 +1,38 @@ +/* + * 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 ITEM_H +#define ITEM_H + +#include +#include +#include +#include + +class Item{ +protected: + QList item; + QString mimetype; + Akonadi::Collection collection; + +public: + + Item(QString mimetype); + QList getItem() const; +}; + +#endif diff --git a/akonadi/tests/testrunner/itemfactory.cpp b/akonadi/tests/testrunner/itemfactory.cpp new file mode 100644 index 000000000..292b7e0af --- /dev/null +++ b/akonadi/tests/testrunner/itemfactory.cpp @@ -0,0 +1,39 @@ +/* + * 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 "vcarditem.h" +#include "calitem.h" +#include "itemfactory.h" +#include +#include "feeditem.h" + +Item *ItemFactory::createItem( QFile *file ){ + if( file->fileName().endsWith(".vcf") ){ + return new VCardItem(file, QString("text/vcard") ); + } else { + if( file->fileName().endsWith(".ics") ){ + return new CalItem( file, QString("text/calendar") ); + } else { + if( file->fileName().endsWith(".xml") ){ + return new FeedItem( file, QString("application/rss+xml") ); + } + } + } + + return 0; +} + diff --git a/akonadi/tests/testrunner/itemfactory.h b/akonadi/tests/testrunner/itemfactory.h new file mode 100644 index 000000000..5fd251c26 --- /dev/null +++ b/akonadi/tests/testrunner/itemfactory.h @@ -0,0 +1,28 @@ +/* + * 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 ITEMFACTORY_H +#define ITEMFACTORY_H + +#include "item.h" + +class ItemFactory{ +public: + Item * createItem(QFile *file); +}; + +#endif diff --git a/akonadi/tests/testrunner/main.cpp b/akonadi/tests/testrunner/main.cpp new file mode 100644 index 000000000..668b81909 --- /dev/null +++ b/akonadi/tests/testrunner/main.cpp @@ -0,0 +1,66 @@ +/*people + * + * 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 +#include +#include +#include +#include "akonaditesting.h" +#include "setup.h" +#include "config.h" +#include "shellscript.h" + +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; + + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + SetupTest *setup = new SetupTest(); + + setup->startAkonadiDaemon(); + + AkonadiTesting *testing = new AkonadiTesting(); + + testing->insertItemFromList(); + + shellScript *sh = new shellScript(); + sh->makeShellScript(); + + int result = app.exec(); + + Config::destroyInstance(); + delete testing; + delete setup; + delete sh; + + return result; +} + diff --git a/akonadi/tests/testrunner/setup.cpp b/akonadi/tests/testrunner/setup.cpp new file mode 100644 index 000000000..d36d6c3a8 --- /dev/null +++ b/akonadi/tests/testrunner/setup.cpp @@ -0,0 +1,207 @@ +/* + * 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 "setup.h" +#include "config.h" +#include "symbols.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +QMap SetupTest::getEnvironment() +{ + QMap env; + + foreach (const QString& val, QProcess::systemEnvironment()) { + int p = val.indexOf('='); + if (p > 0) { + env[val.left(p).toUpper()] = val.mid(p+1); + } + } + return env; +} + + +bool SetupTest::clearEnvironment() +{ + QMap environment = getEnvironment(); + + foreach(const QString& s, environment.keys()) { + if (s != "HOME") { + if ( !unsetenv( s.toAscii() )) { + return false; + } + } + } + + return true; +} + +int SetupTest::addDBusToEnvironment(QIODevice& io) { + QByteArray data = io.readLine(); + int pid = -1; + Symbols *symbol = Symbols::getInstance(); + + while (data.size()) { + if (data[data.size()-1] == '\n') { + data.resize(data.size()-1); + } + QString val(data); + int p = val.indexOf('='); + if (p > 0) { + QString name = val.left(p).toUpper(); + val = val.mid(p+1); + if (name == "DBUS_SESSION_BUS_PID") { + pid = val.toInt(); + setenv(name.toAscii(), val.toAscii(), 1); + symbol->insertSymbol(name, val); + } else if (name == "DBUS_SESSION_BUS_ADDRESS") { + setenv(name.toAscii(), val.toAscii(), 1); + symbol->insertSymbol(name, val); + } + } + data = io.readLine(); + } + return pid; +} + +int SetupTest::startDBusDaemon() +{ + + QProcess dbusprocess; + QStringList dbusargs; + + dbusprocess.start("/usr/bin/dbus-launch", dbusargs); + bool ok = dbusprocess.waitForStarted() && dbusprocess.waitForFinished(); + if (!ok) { + kDebug() << "error starting dbus-launch"; + dbusprocess.kill(); + return -1; + } + + int dbuspid = addDBusToEnvironment(dbusprocess); + return dbuspid; +} + +void SetupTest::stopDBusDaemon(int dbuspid) +{ + kDebug() << dbuspid; + if (dbuspid) kill(dbuspid, 15); + sleep(1); + + if (dbuspid) kill(dbuspid, 9); +} + +void SetupTest::registerWithInternalDBus( const QString &address ) +{ + mInternalBus = new QDBusConnection( QDBusConnection::connectToBus( address, QLatin1String( "InternalBus" ) ) ); + mInternalBus->registerService( QLatin1String( "org.kde.Akonaditest" ) ); + mInternalBus->registerObject(QLatin1String("/MainApplication"), + KApplication::kApplication(), + QDBusConnection::ExportScriptableSlots | + QDBusConnection::ExportScriptableProperties | + QDBusConnection::ExportAdaptors); + + QDBusConnectionInterface *busInterface = mInternalBus->interface(); + connect( busInterface, SIGNAL( serviceOwnerChanged( QString, QString, QString ) ), + this, SLOT( dbusNameOwnerChanged( QString, QString, QString ) ) ); +} + +void SetupTest::startAkonadiDaemon() +{ + QString akonadiDaemon = "akonadi_control"; + QStringList args; + akonadiDaemonProcess->start(akonadiDaemon, args); + akonadiDaemonProcess->waitForStarted(5000); + kDebug()<pid(); +} + +void SetupTest::stopAkonadiDaemon() +{ + akonadiDaemonProcess->terminate(); + if (!akonadiDaemonProcess->waitForFinished(5000)) { + kDebug() << "Problem finishing process."; + } + akonadiDaemonProcess->close(); +} + +void SetupTest::setupAgents() +{ + Config *config = Config::getInstance(); + QDBusInterface agentDBus( "org.freedesktop.Akonadi.Control", "/AgentManager", + "org.freedesktop.Akonadi.AgentManager", *mInternalBus ); + + kDebug() << "available agent types:" << agentDBus.call( QLatin1String( "agentTypes" ) ); + + kDebug() << config->getAgents(); + foreach(const QString &agent, config->getAgents()){ + kDebug() << "inserting resource:"<getKdeHome().toAscii() , 1 ); + setenv("XDG_DATA_HOME", config->getXdgDataHome().toAscii() , 1 ); + setenv("XDG_CONFIG_HOME", config->getXdgConfigHome().toAscii() , 1 ); + + Symbols *symbol = Symbols::getInstance(); + symbol->insertSymbol("KDEHOME", config->getKdeHome()); + symbol->insertSymbol("XDG_DATA_HOME", config->getXdgDataHome()); + symbol->insertSymbol("XDG_CONFIG_HOME", config->getXdgConfigHome()); + + dpid = startDBusDaemon(); + +#if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 2)) + const QString dbusAddress = symbol->getSymbols()[ "DBUS_SESSION_BUS_ADDRESS" ]; + registerWithInternalDBus( dbusAddress ); +#endif + + akonadiDaemonProcess = new QProcess(); +} + +SetupTest::~SetupTest() +{ + stopAkonadiDaemon(); + stopDBusDaemon(dpid); + + delete akonadiDaemonProcess; +} diff --git a/akonadi/tests/testrunner/setup.h b/akonadi/tests/testrunner/setup.h new file mode 100644 index 000000000..7171dee8f --- /dev/null +++ b/akonadi/tests/testrunner/setup.h @@ -0,0 +1,49 @@ +/* + * 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 SETUP_H +#define SETUP_H + +#include +#include + +class SetupTest : public QObject +{ + Q_OBJECT + private: + QProcess *akonadiDaemonProcess; + int dpid; + bool clearEnvironment(); + QMap getEnvironment(); + QDBusConnection *mInternalBus; + int addDBusToEnvironment(QIODevice& io); + int startDBusDaemon(); + void stopDBusDaemon(int dbuspid); + void registerWithInternalDBus( const QString &address ); + void setupAgents(); + + private Q_SLOTS: + void dbusNameOwnerChanged( const QString &name, const QString &oldOwner, const QString &newOwner ); + + public: + void startAkonadiDaemon(); + void stopAkonadiDaemon(); + SetupTest(); + ~SetupTest(); +}; + +#endif diff --git a/akonadi/tests/testrunner/shellscript.cpp b/akonadi/tests/testrunner/shellscript.cpp new file mode 100644 index 000000000..1d25b4799 --- /dev/null +++ b/akonadi/tests/testrunner/shellscript.cpp @@ -0,0 +1,62 @@ +/* + * 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 "shellscript.h" +#include +#include +#include + +shellScript::shellScript() +{ + symbol = Symbols::getInstance(); +} + +void shellScript::writeEnvironmentVariables() +{ + QHashIterator i( symbol->getSymbols() ); + + while( i.hasNext() ) + { + i.next(); + script.append( i.key() ); + script.append( "=" ); + script.append( i.value() ); + script.append( "\n" ); + + script.append("export "); + script.append( i.key() ); + script.append("\n"); + } + script.append("\n\n"); +} + +void shellScript::makeShellScript() +{ + QFile file("testenvironment.sh"); //can user define the file name/location? + + file.open( QIODevice::WriteOnly ); + + writeEnvironmentVariables(); + + //script.append("exec /usr/bin/dbus-launch \n"); + //script.append("exec akonadiconsole\n"); + file.write(script.toAscii(), qstrlen(script.toAscii()) ); + file.close(); +} + + diff --git a/akonadi/tests/testrunner/shellscript.h b/akonadi/tests/testrunner/shellscript.h new file mode 100644 index 000000000..f202c1682 --- /dev/null +++ b/akonadi/tests/testrunner/shellscript.h @@ -0,0 +1,33 @@ +/* + * 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 +#include "symbols.h" + +class shellScript +{ + private: + Symbols *symbol; + QString script; + + void writeEnvironmentVariables(); + + public: + shellScript(); + void makeShellScript(); + +}; + diff --git a/akonadi/tests/testrunner/symbols.cpp b/akonadi/tests/testrunner/symbols.cpp new file mode 100644 index 000000000..6557e223d --- /dev/null +++ b/akonadi/tests/testrunner/symbols.cpp @@ -0,0 +1,29 @@ +#include "symbols.h" +#include + +Symbols* Symbols::instance = 0; + +Symbols *Symbols::getInstance() +{ + if(instance == 0){ + + instance= new Symbols(); + } + return instance; +} + +void Symbols::destroyInstance() +{ + delete instance; +} + +void Symbols::insertSymbol(QString key, QString item) +{ + symbols.insert(key, item); +} + +QHash Symbols::getSymbols() +{ + return symbols; +} + diff --git a/akonadi/tests/testrunner/symbols.h b/akonadi/tests/testrunner/symbols.h new file mode 100644 index 000000000..49b33df1f --- /dev/null +++ b/akonadi/tests/testrunner/symbols.h @@ -0,0 +1,19 @@ +#ifndef SYMBOLS_H +#define SYMBOLS_H + +#include + +class Symbols +{ + private: + QHash symbols; + static Symbols *instance; + + public: + static Symbols *getInstance(); + static void destroyInstance(); + QHash getSymbols(); + void insertSymbol(QString key, QString item); +}; + +#endif diff --git a/akonadi/tests/testrunner/vcarditem.cpp b/akonadi/tests/testrunner/vcarditem.cpp new file mode 100644 index 000000000..736d68f1e --- /dev/null +++ b/akonadi/tests/testrunner/vcarditem.cpp @@ -0,0 +1,43 @@ +/* + * 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 "vcarditem.h" +#include +#include +#include +#include +#include +#include + +VCardItem::VCardItem(QFile *file, const QString &mimetype) +:Item(mimetype) { + KABC::VCardConverter converter; + + QByteArray data = file->readAll(); + vcardlist = converter.parseVCards( data ); + + foreach(const KABC::Addressee &tmp, vcardlist){ + Akonadi::Item tmpitem; + tmpitem.setMimeType(mimetype); + tmpitem.setPayload( tmp ); + item.append( tmpitem ); + } + +} + + diff --git a/akonadi/tests/testrunner/vcarditem.h b/akonadi/tests/testrunner/vcarditem.h new file mode 100644 index 000000000..6a7a7281b --- /dev/null +++ b/akonadi/tests/testrunner/vcarditem.h @@ -0,0 +1,34 @@ +/* + * 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 VCARDITEM_H +#define VCARDITEM_H + +#include "item.h" +#include +#include +#include + +class VCardItem: public Item { +private: + KABC::Addressee::List vcardlist; + +public: + VCardItem( QFile *file, const QString &mimetype ); +}; + +#endif