collectionannotationattributetest.cpp 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
    Copyright (C) 2009 Volker Krause <vkrause@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#include <QtTest>
Laurent Montel's avatar
Laurent Montel committed
21
#include <qtest.h>
Laurent Montel's avatar
Laurent Montel committed
22
#include "../collectionannotationsattribute.h"
23 24

typedef QMap<QByteArray, QByteArray> Annotation;
Laurent Montel's avatar
Laurent Montel committed
25
Q_DECLARE_METATYPE(Annotation)
26 27 28 29 30

using namespace Akonadi;

class CollectionAnnotationAttributeTest : public QObject
{
Laurent Montel's avatar
Laurent Montel committed
31
    Q_OBJECT
Laurent Montel's avatar
Laurent Montel committed
32
private Q_SLOTS:
33 34
    void testSerializeDeserialize_data()
    {
Laurent Montel's avatar
Laurent Montel committed
35
        QTest::addColumn<Annotation>("annotation");
36

Laurent Montel's avatar
Laurent Montel committed
37 38
        Annotation a;
        QTest::newRow("empty") << a;
39

Laurent Montel's avatar
Laurent Montel committed
40 41
        a.insert("/vendor/cmu/cyrus-imapd/lastpop", "");
        QTest::newRow("empty value, single key") << a;
42

Laurent Montel's avatar
Laurent Montel committed
43 44
        a.insert("/vendor/cmu/cyrus-imapd/condstore", "false");
        QTest::newRow("empty value, two keys") << a;
45

Laurent Montel's avatar
Laurent Montel committed
46 47
        a.insert("/vendor/cmu/cyrus-imapd/sharedseen", "false");
        QTest::newRow("empty value, three keys") << a;
48

Laurent Montel's avatar
Laurent Montel committed
49 50 51
        a.clear();
        a.insert("vendor/cmu/cyrus-imapd/lastpop", " ");
        QTest::newRow("space value, single key") << a;
52

Laurent Montel's avatar
Laurent Montel committed
53 54
        a.insert("/vendor/cmu/cyrus-imapd/condstore", "false");
        QTest::newRow("space value, two keys") << a;
55

Laurent Montel's avatar
Laurent Montel committed
56 57
        a.insert("/vendor/cmu/cyrus-imapd/sharedseen", "false");
        QTest::newRow("space value, three keys") << a;
58 59 60 61
    }

    void testSerializeDeserialize()
    {
Laurent Montel's avatar
Laurent Montel committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        QFETCH(Annotation, annotation);
        CollectionAnnotationsAttribute *attr1 = new CollectionAnnotationsAttribute();
        attr1->setAnnotations(annotation);
        QCOMPARE(attr1->annotations(), annotation);

        CollectionAnnotationsAttribute *attr2 = new CollectionAnnotationsAttribute();
        attr2->deserialize(attr1->serialized());
        QCOMPARE(attr2->annotations(), annotation);

        CollectionAnnotationsAttribute *attr3 = new CollectionAnnotationsAttribute();
        attr3->setAnnotations(attr2->annotations());
        QCOMPARE(attr3->serialized(), attr1->serialized());

        delete attr1;
        delete attr2;
        delete attr3;
78 79 80 81
    }

};

Laurent Montel's avatar
Laurent Montel committed
82
QTEST_MAIN(CollectionAnnotationAttributeTest)
83 84 85

#include "collectionannotationattributetest.moc"