qtmobility/tests/auto/qversitdocument/ut_qversitdocument.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "ut_qversitdocument.h"
       
    43 #include "qversitdocument.h"
       
    44 #include "qversitproperty.h"
       
    45 #include <QString>
       
    46 #include <QtTest/QtTest>
       
    47 
       
    48 QTM_USE_NAMESPACE
       
    49 
       
    50 void UT_QVersitDocument::init()
       
    51 {
       
    52     mVersitDocument = new QVersitDocument();
       
    53     QVERIFY(mVersitDocument);
       
    54 }
       
    55 
       
    56 void UT_QVersitDocument::cleanup()
       
    57 {
       
    58     delete mVersitDocument;
       
    59 }
       
    60 
       
    61 
       
    62 void UT_QVersitDocument::testConstructor()
       
    63 {
       
    64     QCOMPARE(QVersitDocument::InvalidType, mVersitDocument->type());
       
    65 }
       
    66 
       
    67 void UT_QVersitDocument::testType()
       
    68 {
       
    69     mVersitDocument->setType(QVersitDocument::VCard21Type);
       
    70     QCOMPARE(QVersitDocument::VCard21Type, mVersitDocument->type());
       
    71 
       
    72     mVersitDocument->setType(QVersitDocument::VCard30Type);
       
    73     QCOMPARE(QVersitDocument::VCard30Type, mVersitDocument->type());
       
    74 }
       
    75 
       
    76 void UT_QVersitDocument::testAddProperty()
       
    77 {
       
    78     QCOMPARE(0, mVersitDocument->properties().count());
       
    79     QVersitProperty property;
       
    80     mVersitDocument->addProperty(property);
       
    81     QCOMPARE(1, mVersitDocument->properties().count());
       
    82 }
       
    83 
       
    84 void UT_QVersitDocument::testRemoveProperty()
       
    85 {
       
    86     // Remove an empty property.
       
    87     QCOMPARE(mVersitDocument->properties().count(), 0);
       
    88     QVersitProperty property;
       
    89     mVersitDocument->addProperty(property);
       
    90     mVersitDocument->removeProperty(property);
       
    91     QCOMPARE(mVersitDocument->properties().count(), 0);
       
    92 
       
    93     // A full property.
       
    94     property.setName(QLatin1String("TEL"));
       
    95     property.setGroups(QStringList(QLatin1String("HOME")));
       
    96     QMultiHash<QString, QString> params;
       
    97     params.insert(QLatin1String("TYPE"), QLatin1String("HOME"));
       
    98     property.setParameters(params);
       
    99     property.setValue(QLatin1String("123"));
       
   100     mVersitDocument->addProperty(property);
       
   101     QCOMPARE(mVersitDocument->properties().count(), 1);
       
   102     QVersitProperty property2;
       
   103     property2.setName(QLatin1String("TEL"));
       
   104     // Remove with a partial property fails.
       
   105     mVersitDocument->removeProperty(property2);
       
   106     QCOMPARE(mVersitDocument->properties().count(), 1);
       
   107     property2.setGroups(QStringList(QLatin1String("HOME")));
       
   108     property2.setParameters(params);
       
   109     property2.setValue(QLatin1String("123"));
       
   110     // Remove with a fully specified property succeeds.
       
   111     mVersitDocument->removeProperty(property2);
       
   112     QCOMPARE(mVersitDocument->properties().count(), 0);
       
   113 }
       
   114 
       
   115 void UT_QVersitDocument::testRemoveAllProperties()
       
   116 {
       
   117     QString name(QString::fromAscii("FN"));
       
   118 
       
   119     // Try to remove from an empty document
       
   120     QCOMPARE(0, mVersitDocument->properties().count());
       
   121     mVersitDocument->removeProperties(name);
       
   122     QCOMPARE(0, mVersitDocument->properties().count());
       
   123 
       
   124     // Try to remove from a non-empty document, name does not match
       
   125     QVersitProperty property;
       
   126     property.setName(QString::fromAscii("TEL"));
       
   127     mVersitDocument->addProperty(property);
       
   128     QCOMPARE(1, mVersitDocument->properties().count());
       
   129     mVersitDocument->removeProperties(name);
       
   130     QCOMPARE(1, mVersitDocument->properties().count());
       
   131 
       
   132     // Remove from a non-empty document, name matches
       
   133     mVersitDocument->removeProperties(QString::fromAscii("TEL"));
       
   134     QCOMPARE(0, mVersitDocument->properties().count());
       
   135 
       
   136     // Remove from a document with two properties, first matches
       
   137     property.setName(name);
       
   138     mVersitDocument->addProperty(property);
       
   139     property.setName(QString::fromAscii("TEL"));
       
   140     mVersitDocument->addProperty(property);
       
   141     QCOMPARE(2, mVersitDocument->properties().count());
       
   142     mVersitDocument->removeProperties(name);
       
   143     QCOMPARE(1, mVersitDocument->properties().count());
       
   144 
       
   145     // Remove from a document with two properties, second matches
       
   146     property.setName(name);
       
   147     mVersitDocument->addProperty(property);
       
   148     QCOMPARE(2, mVersitDocument->properties().count());
       
   149     mVersitDocument->removeProperties(name);
       
   150     QCOMPARE(1, mVersitDocument->properties().count());
       
   151 }
       
   152 
       
   153 void UT_QVersitDocument::testEquality()
       
   154 {
       
   155     QVersitDocument document1;
       
   156     QVersitDocument document2;
       
   157     QVERIFY(document1.isEmpty());
       
   158     QVERIFY(document1 == document2);
       
   159     QVERIFY(!(document1 != document2));
       
   160     QVersitProperty property;
       
   161     property.setName(QLatin1String("FN"));
       
   162     property.setValue(QLatin1String("John Citizen"));
       
   163     document2.addProperty(property);
       
   164     QVERIFY(!(document1 == document2));
       
   165     QVERIFY(document1 != document2);
       
   166     QVERIFY(!document2.isEmpty());
       
   167 
       
   168     document1.addProperty(property);
       
   169     QVERIFY(document1 == document2);
       
   170     QVERIFY(!(document1 != document2));
       
   171 
       
   172     document2.clear();
       
   173     QVERIFY(document2.isEmpty());
       
   174 
       
   175     document1.clear();
       
   176     QVERIFY(document1 == document2);
       
   177     QVERIFY(!(document1 != document2));
       
   178 
       
   179     document2.setType(QVersitDocument::VCard21Type);
       
   180     QVERIFY(!(document1 == document2));
       
   181     QVERIFY(document1 != document2);
       
   182     QVERIFY(!document2.isEmpty());
       
   183 }
       
   184 
       
   185 QTEST_MAIN(UT_QVersitDocument)
       
   186