File indexing completed on 2024-11-10 04:40:13
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "itemtest.h" 0008 #include "collection.h" 0009 #include "item.h" 0010 #include "testattribute.h" 0011 0012 #include <QTest> 0013 0014 #include <memory> 0015 0016 QTEST_MAIN(ItemTest) 0017 0018 using namespace Akonadi; 0019 0020 void ItemTest::testMultipart() 0021 { 0022 Item item; 0023 item.setMimeType(QStringLiteral("application/octet-stream")); 0024 0025 QSet<QByteArray> parts; 0026 QCOMPARE(item.loadedPayloadParts(), parts); 0027 0028 QByteArray bodyData = "bodydata"; 0029 item.setPayload<QByteArray>(bodyData); 0030 parts << Item::FullPayload; 0031 QCOMPARE(item.loadedPayloadParts(), parts); 0032 QCOMPARE(item.payload<QByteArray>(), bodyData); 0033 0034 QByteArray myData = "mypartdata"; 0035 item.attribute<TestAttribute>(Item::AddIfMissing)->data = myData; 0036 0037 QCOMPARE(item.loadedPayloadParts(), parts); 0038 QCOMPARE(item.attributes().count(), 1); 0039 QVERIFY(item.hasAttribute<TestAttribute>()); 0040 QCOMPARE(item.attribute<TestAttribute>()->data, myData); 0041 } 0042 0043 void ItemTest::testInheritance() 0044 { 0045 Item a; 0046 0047 a.setRemoteId(QStringLiteral("Hello World")); 0048 a.setSize(10); 0049 0050 Item b(a); 0051 b.setFlag("\\send"); 0052 QCOMPARE(b.remoteId(), QStringLiteral("Hello World")); 0053 QCOMPARE(b.size(), (qint64)10); 0054 } 0055 0056 void ItemTest::testParentCollection() 0057 { 0058 Item a; 0059 QVERIFY(!a.parentCollection().isValid()); 0060 0061 a.setParentCollection(Collection::root()); 0062 QCOMPARE(a.parentCollection(), Collection::root()); 0063 Item b = a; 0064 QCOMPARE(b.parentCollection(), Collection::root()); 0065 0066 Item c; 0067 c.parentCollection().setRemoteId(QStringLiteral("foo")); 0068 QCOMPARE(c.parentCollection().remoteId(), QStringLiteral("foo")); 0069 const Item d = c; 0070 QCOMPARE(d.parentCollection().remoteId(), QStringLiteral("foo")); 0071 0072 const Item e; 0073 QVERIFY(!e.parentCollection().isValid()); 0074 0075 Collection col(5); 0076 Item f; 0077 f.setParentCollection(col); 0078 QCOMPARE(f.parentCollection(), col); 0079 Item g = f; 0080 QCOMPARE(g.parentCollection(), col); 0081 b = g; 0082 QCOMPARE(b.parentCollection(), col); 0083 } 0084 0085 void ItemTest::testComparison_data() 0086 { 0087 QTest::addColumn<Akonadi::Item>("itemA"); 0088 QTest::addColumn<Akonadi::Item>("itemB"); 0089 QTest::addColumn<bool>("match"); 0090 0091 QTest::newRow("both invalid, same invalid IDs") << Item(-10) << Item(-10) << true; 0092 QTest::newRow("both invalid, different invalid IDs") << Item(-11) << Item(-12) << true; 0093 QTest::newRow("one valid") << Item(1) << Item() << false; 0094 QTest::newRow("both valid, same IDs") << Item(2) << Item(2) << true; 0095 QTest::newRow("both valid, different IDs") << Item(3) << Item(4) << false; 0096 } 0097 0098 void ItemTest::testComparison() 0099 { 0100 QFETCH(Akonadi::Item, itemA); 0101 QFETCH(Akonadi::Item, itemB); 0102 QFETCH(bool, match); 0103 0104 if (match) { 0105 QVERIFY(itemA == itemB); 0106 QVERIFY(!(itemA != itemB)); 0107 } else { 0108 QVERIFY(itemA != itemB); 0109 QVERIFY(!(itemA == itemB)); 0110 } 0111 } 0112 0113 #include "moc_itemtest.cpp"