File indexing completed on 2024-11-10 04:40:09

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <Akonadi/CollectionAnnotationsAttribute>
0008 
0009 #include <QTest>
0010 
0011 using Annotation = QMap<QByteArray, QByteArray>;
0012 Q_DECLARE_METATYPE(Annotation)
0013 
0014 using namespace Akonadi;
0015 
0016 class CollectionAnnotationsAttributeTest : public QObject
0017 {
0018     Q_OBJECT
0019 private Q_SLOTS:
0020     void testSerializeDeserialize_data()
0021     {
0022         QTest::addColumn<Annotation>("annotation");
0023 
0024         Annotation a;
0025         QTest::newRow("empty") << a;
0026 
0027         a.insert("/vendor/cmu/cyrus-imapd/lastpop", "");
0028         QTest::newRow("empty value, single key") << a;
0029 
0030         a.insert("/vendor/cmu/cyrus-imapd/condstore", "false");
0031         QTest::newRow("empty value, two keys") << a;
0032 
0033         a.insert("/vendor/cmu/cyrus-imapd/sharedseen", "false");
0034         QTest::newRow("empty value, three keys") << a;
0035 
0036         a.clear();
0037         a.insert("vendor/cmu/cyrus-imapd/lastpop", " ");
0038         QTest::newRow("space value, single key") << a;
0039 
0040         a.insert("/vendor/cmu/cyrus-imapd/condstore", "false");
0041         QTest::newRow("space value, two keys") << a;
0042 
0043         a.insert("/vendor/cmu/cyrus-imapd/sharedseen", "false");
0044         QTest::newRow("space value, three keys") << a;
0045     }
0046 
0047     void testSerializeDeserialize()
0048     {
0049         QFETCH(Annotation, annotation);
0050         auto attr1 = new CollectionAnnotationsAttribute();
0051         attr1->setAnnotations(annotation);
0052         QCOMPARE(attr1->annotations(), annotation);
0053 
0054         auto attr2 = new CollectionAnnotationsAttribute();
0055         attr2->deserialize(attr1->serialized());
0056         QCOMPARE(attr2->annotations(), annotation);
0057 
0058         auto attr3 = new CollectionAnnotationsAttribute();
0059         attr3->setAnnotations(attr2->annotations());
0060         QCOMPARE(attr3->serialized(), attr1->serialized());
0061 
0062         delete attr1;
0063         delete attr2;
0064         delete attr3;
0065     }
0066 
0067     void shouldHaveDefaultValue()
0068     {
0069         CollectionAnnotationsAttribute attr;
0070         QVERIFY(attr.annotations().isEmpty());
0071     }
0072 
0073     void shouldAssignAttribute()
0074     {
0075         QMap<QByteArray, QByteArray> annotations;
0076         annotations.insert("foo", "foo");
0077         annotations.insert("bla", "bla");
0078         annotations.insert("foo2", "bli");
0079         CollectionAnnotationsAttribute attr(annotations);
0080         QCOMPARE(attr.annotations(), annotations);
0081     }
0082 
0083     void shouldDeserializedAttribute()
0084     {
0085         QMap<QByteArray, QByteArray> annotations;
0086         annotations.insert("foo", "foo");
0087         annotations.insert("bla", "bla");
0088         annotations.insert("foo2", "bli");
0089         CollectionAnnotationsAttribute attr(annotations);
0090         const QByteArray ba = attr.serialized();
0091         CollectionAnnotationsAttribute result;
0092         result.deserialize(ba);
0093         QVERIFY(attr == result);
0094     }
0095 
0096     void shouldCloneAttribute()
0097     {
0098         QMap<QByteArray, QByteArray> annotations;
0099         annotations.insert("foo", "foo");
0100         annotations.insert("bla", "bla");
0101         annotations.insert("foo2", "bli");
0102         CollectionAnnotationsAttribute attr(annotations);
0103         CollectionAnnotationsAttribute *result = attr.clone();
0104         QVERIFY(attr == *result);
0105         delete result;
0106     }
0107 
0108     void shouldHaveType()
0109     {
0110         CollectionAnnotationsAttribute attr;
0111         QCOMPARE(attr.type(), QByteArray("collectionannotations"));
0112     }
0113 };
0114 
0115 QTEST_GUILESS_MAIN(CollectionAnnotationsAttributeTest)
0116 
0117 #include "collectionannotationsattributetest.moc"