summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-08 11:01:48 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-08 11:01:48 +0200
commit9317fbffeab4a8c258acb1116eb12fbded7053d8 (patch)
treeb1f00b8ee96e222c16d25d02b49ade1ef3aee8ae
parent1b6439215fa0bb6ac1e191c2ffc992e815a53199 (diff)
downloadsink-9317fbffeab4a8c258acb1116eb12fbded7053d8.tar.gz
sink-9317fbffeab4a8c258acb1116eb12fbded7053d8.zip
Control debugoutput during tests with sinksh.
-rw-r--r--common/test.cpp28
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp1
-rw-r--r--examples/mailtransportresource/tests/mailtransporttest.cpp1
-rw-r--r--sinksh/syntax_modules/sink_trace.cpp21
-rw-r--r--tests/accountstest.cpp1
-rw-r--r--tests/clientapitest.cpp1
-rw-r--r--tests/dummyresourcetest.cpp1
-rw-r--r--tests/genericfacadetest.cpp6
-rw-r--r--tests/genericresourcetest.cpp1
-rw-r--r--tests/inspectiontest.cpp1
-rw-r--r--tests/maildirsyncbenchmark.cpp1
-rw-r--r--tests/mailsynctest.cpp1
-rw-r--r--tests/mailtest.cpp1
-rw-r--r--tests/messagequeuetest.cpp3
-rw-r--r--tests/modelinteractivitytest.cpp1
-rw-r--r--tests/pipelinetest.cpp1
-rw-r--r--tests/querytest.cpp1
-rw-r--r--tests/resourceconfigtest.cpp1
-rw-r--r--tests/testaccounttest.cpp1
19 files changed, 45 insertions, 28 deletions
diff --git a/common/test.cpp b/common/test.cpp
index 99e51c8..5b4c899 100644
--- a/common/test.cpp
+++ b/common/test.cpp
@@ -27,6 +27,7 @@
27#include "facadefactory.h" 27#include "facadefactory.h"
28#include "query.h" 28#include "query.h"
29#include "resourceconfig.h" 29#include "resourceconfig.h"
30#include "definitions.h"
30 31
31SINK_DEBUG_AREA("test") 32SINK_DEBUG_AREA("test")
32 33
@@ -34,6 +35,9 @@ using namespace Sink;
34 35
35void Sink::Test::initTest() 36void Sink::Test::initTest()
36{ 37{
38 auto logIniFile = Sink::configLocation() + "/log.ini";
39 auto areaAutocompletionFile = Sink::dataLocation() + "/debugAreas.ini";
40
37 setTestModeEnabled(true); 41 setTestModeEnabled(true);
38 // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); 42 // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
39 QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); 43 QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively();
@@ -48,6 +52,30 @@ void Sink::Test::initTest()
48 // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); 52 // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
49 QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); 53 QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively();
50 Log::setPrimaryComponent("test"); 54 Log::setPrimaryComponent("test");
55
56 //We copy those files so we can control debug output from outside the test with sinksh
57 {
58 QFile file(logIniFile);
59 if (!file.open(QIODevice::ReadOnly)) {
60 qWarning() << "Failed to open the file: " << logIniFile;
61 }
62 QDir dir;
63 dir.mkpath(Sink::configLocation());
64 if (!file.copy(Sink::configLocation() + "/log.ini")) {
65 qWarning() << "Failed to move the file: " << Sink::configLocation() + "/log.ini";
66 }
67 }
68 {
69 QFile file(areaAutocompletionFile);
70 if (!file.open(QIODevice::ReadOnly)) {
71 qWarning() << "Failed to open the file: " << logIniFile;
72 }
73 QDir dir;
74 dir.mkpath(Sink::dataLocation());
75 if (!file.copy(Sink::dataLocation() + "/debugAreas.ini")) {
76 qWarning() << "Failed to move the file: " << Sink::configLocation() + "/log.ini";
77 }
78 }
51} 79}
52 80
53void Sink::Test::setTestModeEnabled(bool enabled) 81void Sink::Test::setTestModeEnabled(bool enabled)
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index d9af453..ef695b3 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -28,7 +28,6 @@ private slots:
28 QTcpSocket socket; 28 QTcpSocket socket;
29 socket.connectToHost("localhost", 993); 29 socket.connectToHost("localhost", 993);
30 QVERIFY(socket.waitForConnected(200)); 30 QVERIFY(socket.waitForConnected(200));
31 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
32 system("resetmailbox.sh"); 31 system("resetmailbox.sh");
33 } 32 }
34 33
diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp
index 3ce5f82..fdd591b 100644
--- a/examples/mailtransportresource/tests/mailtransporttest.cpp
+++ b/examples/mailtransportresource/tests/mailtransporttest.cpp
@@ -33,7 +33,6 @@ private slots:
33 void initTestCase() 33 void initTestCase()
34 { 34 {
35 Test::initTest(); 35 Test::initTest();
36 Log::setDebugOutputLevel(Sink::Log::Trace);
37 auto resource = createResource(); 36 auto resource = createResource();
38 QVERIFY(!resource.identifier().isEmpty()); 37 QVERIFY(!resource.identifier().isEmpty());
39 VERIFYEXEC(Store::create(resource)); 38 VERIFYEXEC(Store::create(resource));
diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp
index d480254..8bd52a0 100644
--- a/sinksh/syntax_modules/sink_trace.cpp
+++ b/sinksh/syntax_modules/sink_trace.cpp
@@ -31,6 +31,7 @@
31#include "sinksh_utils.h" 31#include "sinksh_utils.h"
32#include "state.h" 32#include "state.h"
33#include "syntaxtree.h" 33#include "syntaxtree.h"
34#include "iostream"
34 35
35namespace SinkTrace 36namespace SinkTrace
36{ 37{
@@ -38,22 +39,24 @@ namespace SinkTrace
38bool traceOff(const QStringList &args, State &state) 39bool traceOff(const QStringList &args, State &state)
39{ 40{
40 Sink::Log::setDebugOutputLevel(Sink::Log::Log); 41 Sink::Log::setDebugOutputLevel(Sink::Log::Log);
41 qDebug() << "Turned trace off: " << args; 42 std::cout << "Turned trace off." << std::endl;
42 return true; 43 return true;
43} 44}
44 45
45bool traceOn(const QStringList &args, State &state) 46bool traceOn(const QStringList &args, State &state)
46{ 47{
47 if (args.isEmpty()) {
48 state.printError(QObject::tr("Specifiy a debug area to trace: ") + Sink::Log::debugAreas().toList().join(", "));
49 return false;
50 }
51 Sink::Log::setDebugOutputLevel(Sink::Log::Trace); 48 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
52 QByteArrayList filter; 49 if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) {
53 for (const auto &arg : args) { 50 Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList());
54 filter << arg.toLatin1(); 51 std::cout << "Set trace filter to: *" << std::endl;
52 } else {
53 QByteArrayList filter;
54 for (const auto &arg : args) {
55 filter << arg.toLatin1();
56 }
57 Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter);
58 std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl;
55 } 59 }
56 Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter);
57 return true; 60 return true;
58} 61}
59 62
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp
index 5a66305..d12e7f4 100644
--- a/tests/accountstest.cpp
+++ b/tests/accountstest.cpp
@@ -17,7 +17,6 @@ private slots:
17 void initTestCase() 17 void initTestCase()
18 { 18 {
19 Sink::Test::initTest(); 19 Sink::Test::initTest();
20 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
21 } 20 }
22 21
23 void init() 22 void init()
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index ec74cbd..ed5a9b5 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -93,7 +93,6 @@ private slots:
93 { 93 {
94 Sink::FacadeFactory::instance().resetFactory(); 94 Sink::FacadeFactory::instance().resetFactory();
95 ResourceConfig::clear(); 95 ResourceConfig::clear();
96 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
97 } 96 }
98 97
99 void testLoad() 98 void testLoad()
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp
index d41f235..0907b1d 100644
--- a/tests/dummyresourcetest.cpp
+++ b/tests/dummyresourcetest.cpp
@@ -30,7 +30,6 @@ private slots:
30 void initTestCase() 30 void initTestCase()
31 { 31 {
32 Sink::Test::initTest(); 32 Sink::Test::initTest();
33 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
34 auto factory = Sink::ResourceFactory::load("org.kde.dummy"); 33 auto factory = Sink::ResourceFactory::load("org.kde.dummy");
35 QVERIFY(factory); 34 QVERIFY(factory);
36 DummyResource::removeFromDisk("org.kde.dummy.instance1"); 35 DummyResource::removeFromDisk("org.kde.dummy.instance1");
diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp
index 8336875..0267dac 100644
--- a/tests/genericfacadetest.cpp
+++ b/tests/genericfacadetest.cpp
@@ -8,6 +8,7 @@
8#include <common/domainadaptor.h> 8#include <common/domainadaptor.h>
9#include <common/resultprovider.h> 9#include <common/resultprovider.h>
10#include <common/synclistresult.h> 10#include <common/synclistresult.h>
11#include <common/test.h>
11 12
12// Replace with something different 13// Replace with something different
13#include "event_generated.h" 14#include "event_generated.h"
@@ -23,10 +24,9 @@ class GenericFacadeTest : public QObject
23{ 24{
24 Q_OBJECT 25 Q_OBJECT
25private slots: 26private slots:
26 27 void initTestCase()
27 void init()
28 { 28 {
29 Sink::Log::setDebugOutputLevel(Sink::Log::Trace); 29 Sink::Test::initTest();
30 } 30 }
31 31
32 void testLoad() 32 void testLoad()
diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp
index 7474cbf..fe2c146 100644
--- a/tests/genericresourcetest.cpp
+++ b/tests/genericresourcetest.cpp
@@ -27,7 +27,6 @@ private slots:
27 void init() 27 void init()
28 { 28 {
29 Sink::GenericResource::removeFromDisk("org.kde.test.instance1"); 29 Sink::GenericResource::removeFromDisk("org.kde.test.instance1");
30 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
31 } 30 }
32 31
33 /// Ensure the resource can process messages 32 /// Ensure the resource can process messages
diff --git a/tests/inspectiontest.cpp b/tests/inspectiontest.cpp
index 38bf23d..8f2c50f 100644
--- a/tests/inspectiontest.cpp
+++ b/tests/inspectiontest.cpp
@@ -19,7 +19,6 @@ class InspectionTest : public QObject
19private slots: 19private slots:
20 void initTestCase() 20 void initTestCase()
21 { 21 {
22 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
23 auto factory = Sink::ResourceFactory::load("org.kde.dummy"); 22 auto factory = Sink::ResourceFactory::load("org.kde.dummy");
24 QVERIFY(factory); 23 QVERIFY(factory);
25 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); 24 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy");
diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp
index 06c5ab1..8b1a9d7 100644
--- a/tests/maildirsyncbenchmark.cpp
+++ b/tests/maildirsyncbenchmark.cpp
@@ -61,7 +61,6 @@ private slots:
61 { 61 {
62 targetPath = tempDir.path() + "/maildir1"; 62 targetPath = tempDir.path() + "/maildir1";
63 63
64 Sink::Log::setDebugOutputLevel(Sink::Log::Log);
65 MaildirResource::removeFromDisk("org.kde.maildir.test1"); 64 MaildirResource::removeFromDisk("org.kde.maildir.test1");
66 Sink::ApplicationDomain::SinkResource resource; 65 Sink::ApplicationDomain::SinkResource resource;
67 resource.setProperty("identifier", "org.kde.maildir.test1"); 66 resource.setProperty("identifier", "org.kde.maildir.test1");
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp
index 4401f27..4b797c8 100644
--- a/tests/mailsynctest.cpp
+++ b/tests/mailsynctest.cpp
@@ -37,7 +37,6 @@ void MailSyncTest::initTestCase()
37{ 37{
38 Test::initTest(); 38 Test::initTest();
39 QVERIFY(isBackendAvailable()); 39 QVERIFY(isBackendAvailable());
40 Log::setDebugOutputLevel(Sink::Log::Trace);
41 resetTestEnvironment(); 40 resetTestEnvironment();
42 auto resource = createResource(); 41 auto resource = createResource();
43 QVERIFY(!resource.identifier().isEmpty()); 42 QVERIFY(!resource.identifier().isEmpty());
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp
index 0537175..2547536 100644
--- a/tests/mailtest.cpp
+++ b/tests/mailtest.cpp
@@ -37,7 +37,6 @@ void MailTest::initTestCase()
37{ 37{
38 Test::initTest(); 38 Test::initTest();
39 QVERIFY(isBackendAvailable()); 39 QVERIFY(isBackendAvailable());
40 Log::setDebugOutputLevel(Sink::Log::Trace);
41 resetTestEnvironment(); 40 resetTestEnvironment();
42 auto resource = createResource(); 41 auto resource = createResource();
43 QVERIFY(!resource.identifier().isEmpty()); 42 QVERIFY(!resource.identifier().isEmpty());
diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp
index a8d0d4d..27dd12b 100644
--- a/tests/messagequeuetest.cpp
+++ b/tests/messagequeuetest.cpp
@@ -7,6 +7,7 @@
7#include "storage.h" 7#include "storage.h"
8#include "messagequeue.h" 8#include "messagequeue.h"
9#include "log.h" 9#include "log.h"
10#include "test.h"
10 11
11SINK_DEBUG_AREA("messagequeuetest") 12SINK_DEBUG_AREA("messagequeuetest")
12 13
@@ -19,7 +20,7 @@ class MessageQueueTest : public QObject
19private slots: 20private slots:
20 void initTestCase() 21 void initTestCase()
21 { 22 {
22 Sink::Log::setDebugOutputLevel(Sink::Log::Trace); 23 Sink::Test::initTest();
23 Sink::Storage store(Sink::Store::storageLocation(), "org.kde.dummy.testqueue", Sink::Storage::ReadWrite); 24 Sink::Storage store(Sink::Store::storageLocation(), "org.kde.dummy.testqueue", Sink::Storage::ReadWrite);
24 store.removeFromDisk(); 25 store.removeFromDisk();
25 } 26 }
diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp
index c55a1db..d13cdf7 100644
--- a/tests/modelinteractivitytest.cpp
+++ b/tests/modelinteractivitytest.cpp
@@ -51,7 +51,6 @@ private slots:
51 void initTestCase() 51 void initTestCase()
52 { 52 {
53 Sink::Test::initTest(); 53 Sink::Test::initTest();
54 Sink::Log::setDebugOutputLevel(Sink::Log::Warning);
55 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); 54 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy");
56 Sink::Store::removeDataFromDisk(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); 55 Sink::Store::removeDataFromDisk(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished();
57 } 56 }
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp
index fc23cc9..65d4b49 100644
--- a/tests/pipelinetest.cpp
+++ b/tests/pipelinetest.cpp
@@ -190,7 +190,6 @@ class PipelineTest : public QObject
190private slots: 190private slots:
191 void initTestCase() 191 void initTestCase()
192 { 192 {
193 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
194 Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Event, TestEventAdaptorFactory>("test"); 193 Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Event, TestEventAdaptorFactory>("test");
195 } 194 }
196 195
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index 6d7746e..95c22b3 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -23,7 +23,6 @@ private slots:
23 void initTestCase() 23 void initTestCase()
24 { 24 {
25 Sink::Test::initTest(); 25 Sink::Test::initTest();
26 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
27 auto factory = Sink::ResourceFactory::load("org.kde.dummy"); 26 auto factory = Sink::ResourceFactory::load("org.kde.dummy");
28 QVERIFY(factory); 27 QVERIFY(factory);
29 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); 28 ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy");
diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp
index d5f98d3..021d042 100644
--- a/tests/resourceconfigtest.cpp
+++ b/tests/resourceconfigtest.cpp
@@ -24,7 +24,6 @@ private slots:
24 Sink::Test::initTest(); 24 Sink::Test::initTest();
25 Sink::FacadeFactory::instance().resetFactory(); 25 Sink::FacadeFactory::instance().resetFactory();
26 ResourceConfig::clear(); 26 ResourceConfig::clear();
27 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
28 } 27 }
29 28
30 void resourceManagement() 29 void resourceManagement()
diff --git a/tests/testaccounttest.cpp b/tests/testaccounttest.cpp
index c630846..078e7a0 100644
--- a/tests/testaccounttest.cpp
+++ b/tests/testaccounttest.cpp
@@ -20,7 +20,6 @@ private slots:
20 { 20 {
21 // Sink::FacadeFactory::instance().resetFactory(); 21 // Sink::FacadeFactory::instance().resetFactory();
22 // ResourceConfig::clear(); 22 // ResourceConfig::clear();
23 Log::setDebugOutputLevel(Sink::Log::Trace);
24 Test::initTest(); 23 Test::initTest();
25 } 24 }
26 25