File indexing completed on 2025-01-19 04:46:43
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "confirmaddresscheckjobtest.h" 0008 #include "../confirmaddresscheckjob.h" 0009 #include <QTest> 0010 0011 ConfirmAddressCheckJobTest::ConfirmAddressCheckJobTest(QObject *parent) 0012 : QObject(parent) 0013 { 0014 } 0015 0016 ConfirmAddressCheckJobTest::~ConfirmAddressCheckJobTest() = default; 0017 0018 void ConfirmAddressCheckJobTest::shouldHaveEmptyResultByDefault() 0019 { 0020 ConfirmAddressCheckJob job; 0021 job.start(); 0022 QVERIFY(job.invalidEmails().isEmpty()); 0023 QVERIFY(job.validEmails().isEmpty()); 0024 } 0025 0026 void ConfirmAddressCheckJobTest::shouldReturnEmptyResultWhenNoAddress() 0027 { 0028 ConfirmAddressCheckJob job; 0029 const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")}; 0030 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0031 job.setCheckSettings(domains, whiteList, false); 0032 job.start(); 0033 QVERIFY(job.invalidEmails().isEmpty()); 0034 QVERIFY(job.validEmails().isEmpty()); 0035 0036 job.setCheckSettings(domains, whiteList, true); 0037 job.start(); 0038 QVERIFY(job.invalidEmails().isEmpty()); 0039 QVERIFY(job.validEmails().isEmpty()); 0040 } 0041 0042 void ConfirmAddressCheckJobTest::shouldReturnAllValidEmailsDomain() 0043 { 0044 ConfirmAddressCheckJob job; 0045 const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")}; 0046 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0047 const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")}; 0048 job.setCheckSettings(domains, whiteList, false); 0049 job.setAddressList(emails); 0050 job.start(); 0051 QVERIFY(job.invalidEmails().isEmpty()); 0052 QVERIFY(!job.validEmails().isEmpty()); 0053 QCOMPARE(job.validEmails(), emails); 0054 } 0055 0056 void ConfirmAddressCheckJobTest::shouldReturnAllValidEmailsDomainRejectedDomain() 0057 { 0058 ConfirmAddressCheckJob job; 0059 const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")}; 0060 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0061 const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")}; 0062 job.setCheckSettings(domains, whiteList, true); 0063 job.setAddressList(emails); 0064 job.start(); 0065 QVERIFY(!job.invalidEmails().isEmpty()); 0066 QCOMPARE(job.invalidEmails(), emails); 0067 QVERIFY(job.validEmails().isEmpty()); 0068 } 0069 0070 void ConfirmAddressCheckJobTest::shouldReturnAllInValidEmailsDomain() 0071 { 0072 ConfirmAddressCheckJob job; 0073 const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")}; 0074 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0075 const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")}; 0076 job.setCheckSettings(domains, whiteList, false); 0077 job.setAddressList(emails); 0078 job.start(); 0079 QVERIFY(!job.invalidEmails().isEmpty()); 0080 QVERIFY(job.validEmails().isEmpty()); 0081 QCOMPARE(job.invalidEmails(), emails); 0082 } 0083 0084 void ConfirmAddressCheckJobTest::shouldReturnAllInValidEmailsDomainReject() 0085 { 0086 ConfirmAddressCheckJob job; 0087 const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")}; 0088 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0089 const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")}; 0090 job.setCheckSettings(domains, whiteList, true); 0091 job.setAddressList(emails); 0092 job.start(); 0093 QVERIFY(job.invalidEmails().isEmpty()); 0094 QVERIFY(!job.validEmails().isEmpty()); 0095 QCOMPARE(job.validEmails(), emails); 0096 } 0097 0098 void ConfirmAddressCheckJobTest::shouldReturnValidAndInvalid() 0099 { 0100 ConfirmAddressCheckJob job; 0101 const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")}; 0102 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0103 const QStringList emails{QStringLiteral("toto@bla.com"), QStringLiteral("blabla@foo.com")}; 0104 job.setCheckSettings(domains, whiteList, false); 0105 job.setAddressList(emails); 0106 job.start(); 0107 QVERIFY(!job.invalidEmails().isEmpty()); 0108 QVERIFY(!job.validEmails().isEmpty()); 0109 QCOMPARE(job.invalidEmails(), QStringList() << QStringLiteral("blabla@foo.com")); 0110 QCOMPARE(job.validEmails(), QStringList() << QStringLiteral("toto@bla.com")); 0111 } 0112 0113 void ConfirmAddressCheckJobTest::shouldNotDuplicateValue() 0114 { 0115 ConfirmAddressCheckJob job; 0116 const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")}; 0117 const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")}; 0118 const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")}; 0119 job.setCheckSettings(domains, whiteList, false); 0120 job.setAddressList(QStringList() << emails << emails); 0121 job.start(); 0122 QVERIFY(job.invalidEmails().isEmpty()); 0123 QVERIFY(!job.validEmails().isEmpty()); 0124 QCOMPARE(job.validEmails(), emails); 0125 0126 job.setCheckSettings(domains, whiteList, true); 0127 job.setAddressList(QStringList() << emails << emails); 0128 job.start(); 0129 QVERIFY(!job.invalidEmails().isEmpty()); 0130 QVERIFY(job.validEmails().isEmpty()); 0131 QCOMPARE(job.invalidEmails(), emails); 0132 } 0133 0134 QTEST_MAIN(ConfirmAddressCheckJobTest) 0135 0136 #include "moc_confirmaddresscheckjobtest.cpp"