From dcdc95b6d709616498de00389bd19926625b20f2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 7 Jun 2016 09:16:04 +0200 Subject: An imap accounts plugin --- accounts/imap/tests/CMakeLists.txt | 6 +++ accounts/imap/tests/settingstest.cpp | 87 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 accounts/imap/tests/CMakeLists.txt create mode 100644 accounts/imap/tests/settingstest.cpp (limited to 'accounts/imap/tests') diff --git a/accounts/imap/tests/CMakeLists.txt b/accounts/imap/tests/CMakeLists.txt new file mode 100644 index 00000000..9c914370 --- /dev/null +++ b/accounts/imap/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(../) +cmake_policy(SET CMP0063 NEW) +add_executable(imapsettingstest settingstest.cpp) +add_test(imapsettingstest settingstest) +qt5_use_modules(imapsettingstest Core Test Concurrent) +target_link_libraries(imapsettingstest sink imapaccount_static) 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 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "imapsettings.h" + +class SettingsTest : public QObject +{ + Q_OBJECT +private slots: + + void initTestCase() + { + Sink::Test::initTest(); + } + + void testLoad() + { + auto accountId = "accountid"; + auto imapServer = QString("imapserver"); + auto imapUsername = QString("username"); + auto imapPassword = QString("password"); + auto smtpServer = QString("smtpserver"); + auto smtpUsername = QString("username"); + auto smtpPassword = QString("password"); + auto username = QString("username"); + auto emailAddress = QString("emailAddress"); + + ImapSettings settings; + settings.setAccountIdentifier(accountId); + settings.setProperty("imapServer", imapServer); + settings.setProperty("imapUsername", imapUsername); + settings.setProperty("imapPassword", imapPassword); + settings.setProperty("smtpServer", smtpServer); + settings.setProperty("smtpUsername", smtpUsername); + settings.setProperty("smtpPassword", smtpPassword); + settings.setProperty("userName", username); + settings.setProperty("emailAddress", emailAddress); + settings.save(); + + Sink::Store::fetchAll(Sink::Query()).then>([](const QList &resources) { + QCOMPARE(resources.size(), 2); + }) + .exec().waitForFinished(); + + //Ensure we can read back all the information using the accountid + { + ImapSettings readSettings; + QSignalSpy spy(&readSettings, &ImapSettings::imapResourceChanged); + QSignalSpy spy1(&readSettings, &ImapSettings::smtpResourceChanged); + readSettings.setAccountIdentifier(accountId); + //Once for clear and once for the new setting + QTRY_COMPARE(spy.count(), 2); + QTRY_COMPARE(spy1.count(), 2); + QVERIFY(!readSettings.accountIdentifier().isEmpty()); + QCOMPARE(readSettings.property("imapServer").toString(), imapServer); + QCOMPARE(readSettings.property("imapUsername").toString(), imapUsername); + QCOMPARE(readSettings.property("imapPassword").toString(), imapPassword); + QCOMPARE(readSettings.property("smtpServer").toString(), smtpServer); + QCOMPARE(readSettings.property("smtpUsername").toString(), smtpUsername); + QCOMPARE(readSettings.property("smtpPassword").toString(), smtpPassword); + QCOMPARE(readSettings.property("userName").toString(), smtpUsername); + QCOMPARE(readSettings.property("emailAddress").toString(), emailAddress); + } + + { + ImapSettings settings; + QSignalSpy spy(&settings, &ImapSettings::imapResourceChanged); + settings.setAccountIdentifier(accountId); + QTRY_COMPARE(spy.count(), 2); + settings.remove(); + } + + Sink::Store::fetchAll(Sink::Query()).then>([](const QList &resources) { + QCOMPARE(resources.size(), 0); + }) + .exec().waitForFinished(); + } +}; + +QTEST_GUILESS_MAIN(SettingsTest) +#include "settingstest.moc" -- cgit v1.2.3