File indexing completed on 2024-11-24 04:49:52

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "sieveaccounttest.h"
0008 #include "../sieveimapaccountsettings.h"
0009 
0010 #include <QTest>
0011 
0012 SieveAccountTest::SieveAccountTest(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 SieveAccountTest::~SieveAccountTest() = default;
0018 
0019 void SieveAccountTest::shouldHaveDefaultValue()
0020 {
0021     KSieveCore::SieveImapAccountSettings account;
0022     QVERIFY(account.password().isEmpty());
0023     QVERIFY(account.serverName().isEmpty());
0024     QVERIFY(account.userName().isEmpty());
0025     QCOMPARE(account.port(), -1);
0026     QCOMPARE(account.authenticationType(), KSieveCore::SieveImapAccountSettings::Plain);
0027     QCOMPARE(account.encryptionMode(), KSieveCore::SieveImapAccountSettings::Unencrypted);
0028 }
0029 
0030 void SieveAccountTest::shouldAssignValue()
0031 {
0032     KSieveCore::SieveImapAccountSettings account;
0033     QString pwd = QStringLiteral("foo");
0034     QString server = QStringLiteral("kde");
0035     QString user = QStringLiteral("bla");
0036     int port = 42;
0037     KSieveCore::SieveImapAccountSettings::AuthenticationMode type = KSieveCore::SieveImapAccountSettings::DigestMD5;
0038     KSieveCore::SieveImapAccountSettings::EncryptionMode mode = KSieveCore::SieveImapAccountSettings::SSLorTLS;
0039     account.setPassword(pwd);
0040     account.setServerName(server);
0041     account.setUserName(user);
0042     account.setPort(port);
0043     account.setAuthenticationType(type);
0044     account.setEncryptionMode(mode);
0045     QCOMPARE(account.password(), pwd);
0046     QCOMPARE(account.serverName(), server);
0047     QCOMPARE(account.userName(), user);
0048     QCOMPARE(account.port(), port);
0049     QCOMPARE(account.authenticationType(), type);
0050     QCOMPARE(account.encryptionMode(), mode);
0051 }
0052 
0053 void SieveAccountTest::shouldBeEqual()
0054 {
0055     KSieveCore::SieveImapAccountSettings account;
0056     QString pwd = QStringLiteral("foo");
0057     QString server = QStringLiteral("kde");
0058     QString user = QStringLiteral("bla");
0059     int port = 42;
0060     KSieveCore::SieveImapAccountSettings::AuthenticationMode type = KSieveCore::SieveImapAccountSettings::DigestMD5;
0061     KSieveCore::SieveImapAccountSettings::EncryptionMode mode = KSieveCore::SieveImapAccountSettings::SSLorTLS;
0062     account.setPassword(pwd);
0063     account.setServerName(server);
0064     account.setUserName(user);
0065     account.setPort(port);
0066     account.setAuthenticationType(type);
0067     account.setEncryptionMode(mode);
0068 
0069     KSieveCore::SieveImapAccountSettings accountB;
0070     accountB = account;
0071     QCOMPARE(account, accountB);
0072 }
0073 
0074 void SieveAccountTest::shouldCreateIdentifier_data()
0075 {
0076     QTest::addColumn<QString>("username");
0077     QTest::addColumn<QString>("servername");
0078     QTest::addColumn<QString>("output");
0079 
0080     QTest::newRow("empty") << QString() << QString() << QStringLiteral("_");
0081     QTest::newRow("test1") << QStringLiteral("foo") << QStringLiteral("bla") << QStringLiteral("foo_bla");
0082 }
0083 
0084 void SieveAccountTest::shouldCreateIdentifier()
0085 {
0086     QFETCH(QString, username);
0087     QFETCH(QString, servername);
0088     QFETCH(QString, output);
0089     KSieveCore::SieveImapAccountSettings account;
0090     account.setServerName(servername);
0091     account.setUserName(username);
0092 
0093     // Identifier doesn't depend on these settings
0094     KSieveCore::SieveImapAccountSettings::AuthenticationMode type = KSieveCore::SieveImapAccountSettings::DigestMD5;
0095     KSieveCore::SieveImapAccountSettings::EncryptionMode mode = KSieveCore::SieveImapAccountSettings::SSLorTLS;
0096     account.setPort(42);
0097     account.setAuthenticationType(type);
0098     account.setEncryptionMode(mode);
0099 
0100     QCOMPARE(account.identifier(), output);
0101 }
0102 
0103 QTEST_MAIN(SieveAccountTest)
0104 
0105 #include "moc_sieveaccounttest.cpp"