File indexing completed on 2025-01-05 04:47:12
0001 /* 0002 SPDX-FileCopyrightText: Igor Trindade Oliveira <igor_trindade@yahoo.com.br> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collectiontest.h" 0008 #include "xmlreader.h" 0009 #include "xmlwriter.h" 0010 0011 #include "entitydisplayattribute.h" 0012 0013 #include <QStringList> 0014 #include <QTest> 0015 using namespace Akonadi; 0016 0017 QTEST_MAIN(CollectionTest) 0018 0019 // NOTE: XML element attributes are stored in QHash, which means that there are 0020 // always in random order when converting to string. This test has QT_HASH_SEED 0021 // always set to 0, but it appears that it has different effect on my computer 0022 // and on Jenkins. This order of attributes is the order that passes on Jenkis, 0023 // so if it fails for you locally because of different order of arguments, 0024 // please make sure that your fix won't break the test on Jenkins. 0025 0026 QByteArray collection1(R"r(<test> 0027 <collection content="inode/directory,message/rfc822" name="Inbox" rid="c11"> 0028 <attribute type="ENTITYDISPLAY">("Posteingang" "mail-folder-inbox" "" ())</attribute> 0029 </collection> 0030 </test> 0031 )r"); 0032 0033 QByteArray collection2(R"r(<test> 0034 <collection content="inode/directory,message/rfc822" name="Inbox" rid="c11"> 0035 <attribute type="ENTITYDISPLAY" >("Posteingang" "mail-folder-inbox" false)</attribute> 0036 <collection rid="c111" name="KDE PIM" content="inode/directory,message/rfc822"> 0037 </collection> 0038 <collection rid="c112" name="Akonadi" content="inode/directory,message/rfc822"> 0039 <attribute type="AccessRights">wcW</attribute> 0040 </collection> 0041 </collection> 0042 <test> 0043 )r"); 0044 0045 void CollectionTest::testBuildCollection() 0046 { 0047 QDomDocument mDocument; 0048 0049 mDocument.setContent(collection1, true, nullptr); 0050 Collection::List colist = XmlReader::readCollections(mDocument.documentElement()); 0051 0052 const QStringList mimeType{QStringLiteral("inode/directory"), QStringLiteral("message/rfc822")}; 0053 QCOMPARE(colist.size(), 1); 0054 verifyCollection(colist, 0, QStringLiteral("c11"), QStringLiteral("Inbox"), mimeType); 0055 0056 mDocument.setContent(collection2, true, nullptr); 0057 colist = XmlReader::readCollections(mDocument.documentElement()); 0058 0059 QCOMPARE(colist.size(), 3); 0060 verifyCollection(colist, 0, QStringLiteral("c11"), QStringLiteral("Inbox"), mimeType); 0061 verifyCollection(colist, 1, QStringLiteral("c111"), QStringLiteral("KDE PIM"), mimeType); 0062 verifyCollection(colist, 2, QStringLiteral("c112"), QStringLiteral("Akonadi"), mimeType); 0063 0064 QVERIFY(colist.at(0).hasAttribute<EntityDisplayAttribute>()); 0065 const auto attr = colist.at(0).attribute<EntityDisplayAttribute>(); 0066 QCOMPARE(attr->displayName(), QStringLiteral("Posteingang")); 0067 } 0068 0069 void CollectionTest::serializeCollection() 0070 { 0071 Collection c; 0072 c.setRemoteId(QStringLiteral("c11")); 0073 c.setName(QStringLiteral("Inbox")); 0074 c.setContentMimeTypes(QStringList() << Collection::mimeType() << QStringLiteral("message/rfc822")); 0075 c.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setDisplayName(QStringLiteral("Posteingang")); 0076 c.attribute<EntityDisplayAttribute>()->setIconName(QStringLiteral("mail-folder-inbox")); 0077 0078 QDomDocument doc; 0079 QDomElement root = doc.createElement(QStringLiteral("test")); 0080 doc.appendChild(root); 0081 XmlWriter::writeCollection(c, root); 0082 0083 QCOMPARE(doc.toString(), QString::fromUtf8(collection1)); 0084 } 0085 0086 void CollectionTest::verifyCollection(const Collection::List &colist, 0087 int listPosition, 0088 const QString &remoteId, 0089 const QString &name, 0090 const QStringList &mimeType) 0091 { 0092 QVERIFY(colist.at(listPosition).name() == name); 0093 QVERIFY(colist.at(listPosition).remoteId() == remoteId); 0094 QVERIFY(colist.at(listPosition).contentMimeTypes() == mimeType); 0095 } 0096 0097 #include "moc_collectiontest.cpp"