From c9f26c4cbca654417d304c9214aa3a7709631159 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 23 May 2016 14:43:26 +0200 Subject: Propagate test-mode to resources. This way we can run tests in completely separate data-directories. --- common/resourceaccess.cpp | 4 ++++ common/test.cpp | 16 +++++++++++++++- common/test.h | 2 ++ examples/imapresource/tests/imapresourcetest.cpp | 5 +---- synchronizer/main.cpp | 17 ++++++++++++++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index b294221..6dcc898 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -33,6 +33,7 @@ #include "common/inspection_generated.h" #include "common/entitybuffer.h" #include "common/bufferutils.h" +#include "common/test.h" #include "log.h" #include @@ -204,6 +205,9 @@ KAsync::Job ResourceAccess::Private::initializeSocket() TracePrivate() << "Failed to connect, starting resource"; // We failed to connect, so let's start the resource QStringList args; + if (Sink::Test::testModeEnabled()) { + args << "--test"; + } args << resourceInstanceIdentifier << resourceName; qint64 pid = 0; if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { diff --git a/common/test.cpp b/common/test.cpp index 1062e21..59ad9ec 100644 --- a/common/test.cpp +++ b/common/test.cpp @@ -32,7 +32,7 @@ using namespace Sink; void Sink::Test::initTest() { - QStandardPaths::setTestModeEnabled(true); + setTestModeEnabled(true); // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::DataLocation); @@ -47,6 +47,20 @@ void Sink::Test::initTest() QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); } +void Sink::Test::setTestModeEnabled(bool enabled) +{ + QStandardPaths::setTestModeEnabled(enabled); + if (enabled) { + qputenv("SINK_TESTMODE", "TRUE"); + } else { + qunsetenv("SINK_TESTMODE"); + } +} + +bool Sink::Test::testModeEnabled() +{ + return !qEnvironmentVariableIsEmpty("SINK_TESTMODE"); +} template class TestFacade : public Sink::StoreFacade diff --git a/common/test.h b/common/test.h index e2bd1ea..bb505b6 100644 --- a/common/test.h +++ b/common/test.h @@ -34,6 +34,8 @@ namespace Test { * and clears all data directories. */ void SINK_EXPORT initTest(); +void SINK_EXPORT setTestModeEnabled(bool); +bool SINK_EXPORT testModeEnabled(); class SINK_EXPORT TestAccount { public: diff --git a/examples/imapresource/tests/imapresourcetest.cpp b/examples/imapresource/tests/imapresourcetest.cpp index 7d4453b..fa3caa7 100644 --- a/examples/imapresource/tests/imapresourcetest.cpp +++ b/examples/imapresource/tests/imapresourcetest.cpp @@ -53,10 +53,7 @@ class ImapResourceTest : public QObject private slots: void initTestCase() { - - //FIXME initTest only works for the current process, - //we also have to start resources in test-mode - // Sink::Test::initTest(); + Sink::Test::initTest(); Sink::Log::setDebugOutputLevel(Sink::Log::Trace); ::ImapResource::removeFromDisk("org.kde.imap.instance1"); system("resetmailbox.sh"); diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index e000e03..8335e67 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp @@ -28,6 +28,7 @@ #include "listener.h" #include "log.h" +#include "test.h" #undef DEBUG_AREA #define DEBUG_AREA "resource" @@ -123,13 +124,23 @@ int main(int argc, char *argv[]) QCoreApplication app(argc, argv); - if (argc < 3) { + QByteArrayList arguments; + for (int i = 0; i < argc; i++) { + arguments << argv[i]; + } + if (arguments.contains("--test")) { + Log() << "Running in test-mode"; + arguments.removeAll("--test"); + Sink::Test::setTestModeEnabled(true); + } + + if (arguments.count() < 3) { Warning() << "Not enough args passed, no resource loaded."; return app.exec(); } - const QByteArray instanceIdentifier = argv[1]; - const QByteArray resourceType = argv[2]; + const QByteArray instanceIdentifier = arguments.at(1); + const QByteArray resourceType = arguments.at(2); app.setApplicationName(instanceIdentifier); QLockFile lockfile(instanceIdentifier + ".lock"); -- cgit v1.2.3