File indexing completed on 2024-11-24 04:44:08
0001 /* 0002 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0003 SPDX-FileContributor: Kevin Ottens <kevin@kdab.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "imaptestbase.h" 0009 0010 ImapTestBase::ImapTestBase(QObject *parent) 0011 : QObject(parent) 0012 { 0013 } 0014 0015 QString ImapTestBase::defaultUserName() const 0016 { 0017 return QLatin1StringView("test@kdab.com"); 0018 } 0019 0020 QString ImapTestBase::defaultPassword() const 0021 { 0022 return QLatin1StringView("foobar"); 0023 } 0024 0025 ImapAccount *ImapTestBase::createDefaultAccount() const 0026 { 0027 ImapAccount *account = new ImapAccount; 0028 0029 account->setServer(QLatin1StringView("127.0.0.1")); 0030 account->setPort(5989); 0031 account->setUserName(defaultUserName()); 0032 account->setSubscriptionEnabled(true); 0033 account->setEncryptionMode(KIMAP::LoginJob::Unencrypted); 0034 account->setAuthenticationMode(KIMAP::LoginJob::ClearText); 0035 0036 return account; 0037 } 0038 0039 DummyPasswordRequester *ImapTestBase::createDefaultRequester() 0040 { 0041 DummyPasswordRequester *requester = new DummyPasswordRequester(this); 0042 requester->setPassword(defaultPassword()); 0043 return requester; 0044 } 0045 0046 void ImapTestBase::setupTestCase() 0047 { 0048 qRegisterMetaType<ImapAccount *>(); 0049 qRegisterMetaType<DummyPasswordRequester *>(); 0050 qRegisterMetaType<DummyResourceState::Ptr>(); 0051 qRegisterMetaType<KIMAP::Session *>(); 0052 } 0053 0054 QList<QByteArray> ImapTestBase::defaultAuthScenario() const 0055 { 0056 QList<QByteArray> scenario; 0057 0058 scenario << FakeServer::greeting() << "C: A000001 LOGIN \"test@kdab.com\" \"foobar\"" 0059 << "S: A000001 OK User Logged in"; 0060 0061 return scenario; 0062 } 0063 0064 QList<QByteArray> ImapTestBase::defaultPoolConnectionScenario(const QList<QByteArray> &customCapabilities) const 0065 { 0066 QList<QByteArray> scenario; 0067 0068 QByteArray caps = "S: * CAPABILITY IMAP4 IMAP4rev1 UIDPLUS IDLE"; 0069 for (const QByteArray &cap : customCapabilities) { 0070 caps += " " + cap; 0071 } 0072 0073 scenario << defaultAuthScenario() << "C: A000002 CAPABILITY" << caps << "S: A000002 OK Completed"; 0074 0075 return scenario; 0076 } 0077 0078 bool ImapTestBase::waitForSignal(QObject *obj, const char *member, int timeout) const 0079 { 0080 QEventLoop loop; 0081 QTimer timer; 0082 0083 connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); 0084 0085 QSignalSpy spy(obj, member); 0086 connect(obj, member, &loop, SLOT(quit())); 0087 0088 timer.setSingleShot(true); 0089 timer.start(timeout); 0090 loop.exec(); 0091 timer.stop(); 0092 0093 return spy.count() == 1; 0094 } 0095 0096 Akonadi::Collection ImapTestBase::createCollectionChain(const QString &remoteId) const 0097 { 0098 QChar separator = remoteId.length() > 0 ? remoteId.at(0) : QLatin1Char('/'); 0099 0100 Akonadi::Collection parent(1); 0101 parent.setRemoteId(QLatin1StringView("root-id")); 0102 parent.setParentCollection(Akonadi::Collection::root()); 0103 Akonadi::Entity::Id id = 2; 0104 0105 Akonadi::Collection collection = parent; 0106 0107 const QStringList collections = remoteId.split(separator, Qt::SkipEmptyParts); 0108 for (const QString &colId : collections) { 0109 collection = Akonadi::Collection(id); 0110 collection.setRemoteId(separator + colId); 0111 collection.setParentCollection(parent); 0112 0113 parent = collection; 0114 id++; 0115 } 0116 0117 return collection; 0118 } 0119 0120 #include "moc_imaptestbase.cpp"