collectionannotationattributetest.cpp 2.76 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>
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include "../collectionannotationsattribute.cpp"

typedef QMap<QByteArray, QByteArray> Annotation;
Q_DECLARE_METATYPE( Annotation )

using namespace Akonadi;

class CollectionAnnotationAttributeTest : public QObject
{
  Q_OBJECT
  private slots:
    void testSerializeDeserialize_data()
    {
      QTest::addColumn<Annotation>( "annotation" );

      Annotation a;
      QTest::newRow( "empty" ) << a;

      a.insert( "/vendor/cmu/cyrus-imapd/lastpop", "" );
      QTest::newRow( "empty value, single key" ) << a;

      a.insert( "/vendor/cmu/cyrus-imapd/condstore", "false" );
      QTest::newRow( "empty value, two keys" ) << a;

      a.insert( "/vendor/cmu/cyrus-imapd/sharedseen", "false" );
      QTest::newRow( "empty value, three keys" ) << a;
48 49 50 51 52 53 54 55 56 57

      a.clear();
      a.insert( "vendor/cmu/cyrus-imapd/lastpop", " " );
      QTest::newRow( "space value, single key" ) << a;

      a.insert( "/vendor/cmu/cyrus-imapd/condstore", "false" );
      QTest::newRow( "space value, two keys" ) << a;

      a.insert( "/vendor/cmu/cyrus-imapd/sharedseen", "false" );
      QTest::newRow( "space value, three keys" ) << a;
58 59 60 61 62 63 64 65 66 67 68 69 70
    }

    void testSerializeDeserialize()
    {
      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 );

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

75 76
      delete attr1;
      delete attr2;
77
      delete attr3;
78 79 80 81
    }

};

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

#include "collectionannotationattributetest.moc"