diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-23 14:43:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-23 14:43:26 +0200 |
commit | c9f26c4cbca654417d304c9214aa3a7709631159 (patch) | |
tree | fd19cab23dbea2364f6c381d67d68fdd943f63a2 | |
parent | 422950c63f830e4d01315afc37d0144f79bf10db (diff) | |
download | sink-c9f26c4cbca654417d304c9214aa3a7709631159.tar.gz sink-c9f26c4cbca654417d304c9214aa3a7709631159.zip |
Propagate test-mode to resources.
This way we can run tests in completely separate data-directories.
-rw-r--r-- | common/resourceaccess.cpp | 4 | ||||
-rw-r--r-- | common/test.cpp | 16 | ||||
-rw-r--r-- | common/test.h | 2 | ||||
-rw-r--r-- | examples/imapresource/tests/imapresourcetest.cpp | 5 | ||||
-rw-r--r-- | 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 @@ | |||
33 | #include "common/inspection_generated.h" | 33 | #include "common/inspection_generated.h" |
34 | #include "common/entitybuffer.h" | 34 | #include "common/entitybuffer.h" |
35 | #include "common/bufferutils.h" | 35 | #include "common/bufferutils.h" |
36 | #include "common/test.h" | ||
36 | #include "log.h" | 37 | #include "log.h" |
37 | 38 | ||
38 | #include <QCoreApplication> | 39 | #include <QCoreApplication> |
@@ -204,6 +205,9 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
204 | TracePrivate() << "Failed to connect, starting resource"; | 205 | TracePrivate() << "Failed to connect, starting resource"; |
205 | // We failed to connect, so let's start the resource | 206 | // We failed to connect, so let's start the resource |
206 | QStringList args; | 207 | QStringList args; |
208 | if (Sink::Test::testModeEnabled()) { | ||
209 | args << "--test"; | ||
210 | } | ||
207 | args << resourceInstanceIdentifier << resourceName; | 211 | args << resourceInstanceIdentifier << resourceName; |
208 | qint64 pid = 0; | 212 | qint64 pid = 0; |
209 | if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { | 213 | 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; | |||
32 | 32 | ||
33 | void Sink::Test::initTest() | 33 | void Sink::Test::initTest() |
34 | { | 34 | { |
35 | QStandardPaths::setTestModeEnabled(true); | 35 | setTestModeEnabled(true); |
36 | // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); | 36 | // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); |
37 | QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); | 37 | QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); |
38 | // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::DataLocation); | 38 | // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::DataLocation); |
@@ -47,6 +47,20 @@ void Sink::Test::initTest() | |||
47 | QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); | 47 | QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); |
48 | } | 48 | } |
49 | 49 | ||
50 | void Sink::Test::setTestModeEnabled(bool enabled) | ||
51 | { | ||
52 | QStandardPaths::setTestModeEnabled(enabled); | ||
53 | if (enabled) { | ||
54 | qputenv("SINK_TESTMODE", "TRUE"); | ||
55 | } else { | ||
56 | qunsetenv("SINK_TESTMODE"); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | bool Sink::Test::testModeEnabled() | ||
61 | { | ||
62 | return !qEnvironmentVariableIsEmpty("SINK_TESTMODE"); | ||
63 | } | ||
50 | 64 | ||
51 | template <typename T> | 65 | template <typename T> |
52 | class TestFacade : public Sink::StoreFacade<T> | 66 | class TestFacade : public Sink::StoreFacade<T> |
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 { | |||
34 | * and clears all data directories. | 34 | * and clears all data directories. |
35 | */ | 35 | */ |
36 | void SINK_EXPORT initTest(); | 36 | void SINK_EXPORT initTest(); |
37 | void SINK_EXPORT setTestModeEnabled(bool); | ||
38 | bool SINK_EXPORT testModeEnabled(); | ||
37 | 39 | ||
38 | class SINK_EXPORT TestAccount { | 40 | class SINK_EXPORT TestAccount { |
39 | public: | 41 | 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 | |||
53 | private slots: | 53 | private slots: |
54 | void initTestCase() | 54 | void initTestCase() |
55 | { | 55 | { |
56 | 56 | Sink::Test::initTest(); | |
57 | //FIXME initTest only works for the current process, | ||
58 | //we also have to start resources in test-mode | ||
59 | // Sink::Test::initTest(); | ||
60 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); | 57 | Sink::Log::setDebugOutputLevel(Sink::Log::Trace); |
61 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); | 58 | ::ImapResource::removeFromDisk("org.kde.imap.instance1"); |
62 | system("resetmailbox.sh"); | 59 | 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 @@ | |||
28 | 28 | ||
29 | #include "listener.h" | 29 | #include "listener.h" |
30 | #include "log.h" | 30 | #include "log.h" |
31 | #include "test.h" | ||
31 | 32 | ||
32 | #undef DEBUG_AREA | 33 | #undef DEBUG_AREA |
33 | #define DEBUG_AREA "resource" | 34 | #define DEBUG_AREA "resource" |
@@ -123,13 +124,23 @@ int main(int argc, char *argv[]) | |||
123 | 124 | ||
124 | QCoreApplication app(argc, argv); | 125 | QCoreApplication app(argc, argv); |
125 | 126 | ||
126 | if (argc < 3) { | 127 | QByteArrayList arguments; |
128 | for (int i = 0; i < argc; i++) { | ||
129 | arguments << argv[i]; | ||
130 | } | ||
131 | if (arguments.contains("--test")) { | ||
132 | Log() << "Running in test-mode"; | ||
133 | arguments.removeAll("--test"); | ||
134 | Sink::Test::setTestModeEnabled(true); | ||
135 | } | ||
136 | |||
137 | if (arguments.count() < 3) { | ||
127 | Warning() << "Not enough args passed, no resource loaded."; | 138 | Warning() << "Not enough args passed, no resource loaded."; |
128 | return app.exec(); | 139 | return app.exec(); |
129 | } | 140 | } |
130 | 141 | ||
131 | const QByteArray instanceIdentifier = argv[1]; | 142 | const QByteArray instanceIdentifier = arguments.at(1); |
132 | const QByteArray resourceType = argv[2]; | 143 | const QByteArray resourceType = arguments.at(2); |
133 | app.setApplicationName(instanceIdentifier); | 144 | app.setApplicationName(instanceIdentifier); |
134 | 145 | ||
135 | QLockFile lockfile(instanceIdentifier + ".lock"); | 146 | QLockFile lockfile(instanceIdentifier + ".lock"); |