summaryrefslogtreecommitdiffstats
path: root/accounts/imap/tests/settingstest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/imap/tests/settingstest.cpp')
-rw-r--r--accounts/imap/tests/settingstest.cpp120
1 files changed, 0 insertions, 120 deletions
diff --git a/accounts/imap/tests/settingstest.cpp b/accounts/imap/tests/settingstest.cpp
deleted file mode 100644
index 386a9082..00000000
--- a/accounts/imap/tests/settingstest.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
1#include <QTest>
2#include <QDebug>
3#include <QSignalSpy>
4#include <functional>
5#include <QStandardPaths>
6#include <QDir>
7#include <sink/test.h>
8#include <sink/store.h>
9
10#include "imapsettings.h"
11
12class SettingsTest : public QObject
13{
14 Q_OBJECT
15private slots:
16
17 void initTestCase()
18 {
19 Sink::Test::initTest();
20 }
21
22 void testLoad()
23 {
24 auto accountId = "accountid";
25 auto imapServer = QString("imapserver");
26 auto imapUsername = QString("imapName");
27 auto imapPassword = QString("imapPw");
28 auto smtpServer = QString("smtpserver");
29 auto smtpUsername = QString("smtpName");
30 auto smtpPassword = QString("smtpPw");
31 auto username = QString("username");
32 auto emailAddress = QString("emailAddress");
33
34 ImapSettings settings;
35 settings.setAccountIdentifier(accountId);
36 settings.setProperty("imapServer", imapServer);
37 settings.setProperty("imapUsername", imapUsername);
38 settings.setProperty("imapPassword", imapPassword);
39 settings.setProperty("smtpServer", smtpServer);
40 settings.setProperty("smtpUsername", smtpUsername);
41 settings.setProperty("smtpPassword", smtpPassword);
42 settings.setProperty("userName", username);
43 settings.setProperty("emailAddress", emailAddress);
44 settings.save();
45
46 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then([](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) {
47 QCOMPARE(resources.size(), 2);
48 })
49 .exec().waitForFinished();
50
51 //Ensure we can read back all the information using the accountid
52 {
53 ImapSettings readSettings;
54 QSignalSpy spy(&readSettings, &ImapSettings::imapResourceChanged);
55 QSignalSpy spy1(&readSettings, &ImapSettings::smtpResourceChanged);
56 readSettings.setAccountIdentifier(accountId);
57 //Once for clear and once for the new setting
58 QTRY_COMPARE(spy.count(), 2);
59 QTRY_COMPARE(spy1.count(), 2);
60 QVERIFY(!readSettings.accountIdentifier().isEmpty());
61 QCOMPARE(readSettings.property("imapServer").toString(), imapServer);
62 QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername);
63 QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword);
64 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer);
65 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername);
66 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword);
67 QCOMPARE(readSettings.property("userName").toString(), username);
68 QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress);
69 }
70
71 //Modify all settings
72 {
73 settings.setProperty("imapServer", imapServer + "mod");
74 settings.setProperty("imapUsername", imapUsername + "mod");
75 settings.setProperty("imapPassword", imapPassword + "mod");
76 settings.setProperty("smtpServer", smtpServer + "mod");
77 settings.setProperty("smtpUsername", smtpUsername + "mod");
78 settings.setProperty("smtpPassword", smtpPassword + "mod");
79 settings.setProperty("userName", username + "mod");
80 settings.setProperty("emailAddress", emailAddress + "mod");
81 settings.save();
82 }
83
84 //Read back settings again
85 {
86 ImapSettings readSettings;
87 QSignalSpy spy(&readSettings, &ImapSettings::imapResourceChanged);
88 QSignalSpy spy1(&readSettings, &ImapSettings::smtpResourceChanged);
89 readSettings.setAccountIdentifier(accountId);
90 //Once for clear and once for the new setting
91 QTRY_COMPARE(spy.count(), 2);
92 QTRY_COMPARE(spy1.count(), 2);
93 QVERIFY(!readSettings.accountIdentifier().isEmpty());
94 QCOMPARE(readSettings.property("imapServer").toString(), imapServer + "mod");
95 QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername + "mod");
96 QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword + "mod");
97 QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer + "mod");
98 QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername + "mod");
99 QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword + "mod");
100 QCOMPARE(readSettings.property("userName").toString(), username + "mod");
101 QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress + "mod");
102 }
103
104 {
105 ImapSettings settings;
106 QSignalSpy spy(&settings, &ImapSettings::imapResourceChanged);
107 settings.setAccountIdentifier(accountId);
108 QTRY_COMPARE(spy.count(), 2);
109 settings.remove();
110 }
111
112 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then([](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) {
113 QCOMPARE(resources.size(), 0);
114 })
115 .exec().waitForFinished();
116 }
117};
118
119QTEST_GUILESS_MAIN(SettingsTest)
120#include "settingstest.moc"