10#include "agentinstance.h"
11#include "agentmanager.h"
12#include "collectionfetchscope.h"
13#include "collectionpathresolver.h"
14#include "itemfetchscope.h"
16#include "servermanager.h"
18#include <QDBusConnection>
19#include <QDBusInterface>
41#define QTEST_AKONADIMAIN(TestObject) \
42 int main(int argc, char *argv[]) \
44 qputenv("LC_ALL", "C"); \
45 qunsetenv("KDE_COLOR_DEBUG"); \
46 QApplication app(argc, argv); \
47 app.setApplicationName(QStringLiteral("qttest")); \
48 app.setOrganizationDomain(QStringLiteral("kde.org")); \
49 app.setOrganizationName(QStringLiteral("KDE")); \
50 QGuiApplication::setQuitOnLastWindowClosed(false); \
51 QCoreApplication::setQuitLockEnabled(false); \
52 qRegisterMetaType<QList<QUrl>>(); \
54 QTimer::singleShot(0, &app, [argc, argv, &result]() { \
56 result = QTest::qExec(&tc, argc, argv); \
68void checkTestIsIsolated()
70 if (qEnvironmentVariableIsEmpty(
"TESTRUNNER_DB_ENVIRONMENT"))
71 qFatal(
"This test must be run using ctest, in order to use the testrunner environment. Aborting, to avoid messing up your real akonadi");
72 if (!qgetenv(
"XDG_DATA_HOME").contains(
"testrunner"))
73 qFatal(
"Did you forget to run the test using QTEST_AKONADIMAIN?");
79void setAllResourcesOffline()
84 agent.setIsOnline(
false);
88template<
typename Object,
typename Func>
89bool akWaitForSignal(Object sender, Func member,
int timeout = 1000)
100bool akWaitForSignal(
const QObject *sender,
const char *member,
int timeout = 1000)
111qint64 collectionIdFromPath(
const QString &path)
114 bool success = resolver->exec();
116 qDebug() <<
"path resolution for " <<
path <<
" failed: " << resolver->errorText();
119 qint64
id = resolver->collection();
127 return QStringLiteral(
"org.kde.Akonadi.Testrunner-") + pid;
130bool restartAkonadiServer()
133 if (!testrunnerIface.isValid()) {
134 qWarning() <<
"Unable to get a dbus interface to the testrunner!";
137 QDBusReply<void> reply = testrunnerIface.call(QStringLiteral(
"restartAkonadiServer"));
139 qWarning() << reply.
error();
154bool trackAkonadiProcess(
bool track)
157 if (!testrunnerIface.isValid()) {
158 qWarning() <<
"Unable to get a dbus interface to the testrunner!";
161 QDBusReply<void> reply = testrunnerIface.call(QStringLiteral(
"trackAkonadiProcess"), track);
163 qWarning() << reply.
error();
170std::unique_ptr<Akonadi::Monitor> getTestMonitor()
173 m->fetchCollection(
true);
175 m->setAllMonitored(
true);
176 auto &itemFS = m->itemFetchScope();
178 auto &colFS = m->collectionFetchScope();
181 QSignalSpy readySpy(m, &Akonadi::Monitor::monitorReady);
184 return std::unique_ptr<Akonadi::Monitor>(m);
194#define AKVERIFYEXEC(job) QVERIFY2(job->exec(), job->errorString().toUtf8().constData())
A representation of an agent instance.
static AgentManager * self()
Returns the global instance of the agent manager.
AgentInstance::List instances() const
Returns the list of all available agent instances.
@ All
Retrieve all ancestors, up to Collection::root()
static Collection root()
Returns the root collection.
@ All
Retrieve all ancestors, up to Collection::root()
Monitors an item or collection for changes.
static bool isRunning()
Checks if the server is available currently.
void started()
Emitted whenever the server becomes fully operational.
static ServerManager * self()
Returns the singleton instance of this class, for connecting to its signals.
QString path(const QString &relativePath)
QDBusConnection sessionBus()
const QDBusError & error()
bool isValid() const const
QString fromLocal8Bit(QByteArrayView str)
bool isEmpty() const const
QTRY_VERIFY_WITH_TIMEOUT(condition, timeout)