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 ++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'common') 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: -- cgit v1.2.3