diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-07 09:16:04 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-07 09:16:04 +0200 |
commit | dcdc95b6d709616498de00389bd19926625b20f2 (patch) | |
tree | 46af88a178d02aa8b74341febd77c32df9cd503b /accounts/imap/tests/settingstest.cpp | |
parent | 73c124f646e1b9d35f265706b4e746d682bdad4d (diff) | |
download | kube-dcdc95b6d709616498de00389bd19926625b20f2.tar.gz kube-dcdc95b6d709616498de00389bd19926625b20f2.zip |
An imap accounts plugin
Diffstat (limited to 'accounts/imap/tests/settingstest.cpp')
-rw-r--r-- | accounts/imap/tests/settingstest.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/accounts/imap/tests/settingstest.cpp b/accounts/imap/tests/settingstest.cpp new file mode 100644 index 00000000..923f7e14 --- /dev/null +++ b/accounts/imap/tests/settingstest.cpp | |||
@@ -0,0 +1,87 @@ | |||
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 | |||
12 | class SettingsTest : public QObject | ||
13 | { | ||
14 | Q_OBJECT | ||
15 | private 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("username"); | ||
27 | auto imapPassword = QString("password"); | ||
28 | auto smtpServer = QString("smtpserver"); | ||
29 | auto smtpUsername = QString("username"); | ||
30 | auto smtpPassword = QString("password"); | ||
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<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &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(), smtpUsername); | ||
68 | QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress); | ||
69 | } | ||
70 | |||
71 | { | ||
72 | ImapSettings settings; | ||
73 | QSignalSpy spy(&settings, &ImapSettings::imapResourceChanged); | ||
74 | settings.setAccountIdentifier(accountId); | ||
75 | QTRY_COMPARE(spy.count(), 2); | ||
76 | settings.remove(); | ||
77 | } | ||
78 | |||
79 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) { | ||
80 | QCOMPARE(resources.size(), 0); | ||
81 | }) | ||
82 | .exec().waitForFinished(); | ||
83 | } | ||
84 | }; | ||
85 | |||
86 | QTEST_GUILESS_MAIN(SettingsTest) | ||
87 | #include "settingstest.moc" | ||