qtmobility/tests/auto/qversitproperty/ut_qversitproperty.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_qversitproperty.h"
       
    43 #include "qversitproperty.h"
       
    44 #include "qversitproperty_p.h"
       
    45 #include "qversitdocument.h"
       
    46 #include <QtTest/QtTest>
       
    47 
       
    48 QTM_USE_NAMESPACE
       
    49 
       
    50 void UT_QVersitProperty::init()
       
    51 {
       
    52     mVersitProperty = new QVersitProperty();
       
    53     QVERIFY(mVersitProperty);
       
    54 }
       
    55 
       
    56 void UT_QVersitProperty::cleanup()
       
    57 {
       
    58    delete mVersitProperty;
       
    59 }
       
    60 
       
    61 void UT_QVersitProperty::testGroup()
       
    62 {
       
    63     // One group
       
    64     QStringList group(QString::fromAscii("GROUP_NAME"));
       
    65     mVersitProperty->setGroups(group);
       
    66     QCOMPARE(mVersitProperty->groups(), group);
       
    67 
       
    68     // Several groups
       
    69     QStringList groupList;
       
    70     groupList.append(QString::fromAscii("GROUP1"));
       
    71     groupList.append(QString::fromAscii("Group2"));
       
    72     groupList.append(QString::fromAscii("group3"));
       
    73     mVersitProperty->setGroups(groupList);
       
    74     QCOMPARE(mVersitProperty->groups(), groupList);
       
    75 }
       
    76 
       
    77 void UT_QVersitProperty::testName()
       
    78 {
       
    79     // Name in upper case
       
    80     QString name(QString::fromAscii("TEL"));
       
    81     mVersitProperty->setName(name);
       
    82     QCOMPARE(mVersitProperty->name(), name);
       
    83 
       
    84     // Name in lower case, converted automatically to upper case
       
    85     mVersitProperty->setName(QString::fromAscii("tel"));
       
    86     QCOMPARE(mVersitProperty->name(), name);
       
    87 }
       
    88 
       
    89 void UT_QVersitProperty::testParameters()
       
    90 {
       
    91     QString typeParameterName(QString::fromAscii("TYPE"));
       
    92 
       
    93     QString name(QString::fromAscii("type"));
       
    94     QString value1(QString::fromAscii("home"));
       
    95     mVersitProperty->insertParameter(name,value1);
       
    96     QMultiHash<QString,QString> parameters = mVersitProperty->parameters();
       
    97     QCOMPARE(parameters.count(), 1);
       
    98     QVERIFY(parameters.contains(typeParameterName,QString::fromAscii("HOME")));
       
    99 
       
   100     QString value2(QString::fromAscii("voice"));
       
   101     mVersitProperty->insertParameter(name,value2);
       
   102     parameters = mVersitProperty->parameters();
       
   103     QCOMPARE(parameters.count(), 2);
       
   104     QVERIFY(parameters.contains(typeParameterName,QString::fromAscii("HOME")));
       
   105     QVERIFY(parameters.contains(typeParameterName,QString::fromAscii("VOICE")));
       
   106 
       
   107     mVersitProperty->removeParameter(name,value1);
       
   108     QCOMPARE(mVersitProperty->parameters().count(), 1);
       
   109     QVERIFY(parameters.contains(typeParameterName,QString::fromAscii("HOME")));
       
   110 
       
   111     mVersitProperty->removeParameter(name,value2);
       
   112     QCOMPARE(mVersitProperty->parameters().count(), 0);
       
   113 
       
   114     mVersitProperty->insertParameter(name, value1);
       
   115     mVersitProperty->insertParameter(name, value2);
       
   116     QCOMPARE(mVersitProperty->parameters().count(), 2);
       
   117     mVersitProperty->removeParameters(name);
       
   118     QCOMPARE(mVersitProperty->parameters().count(), 0);
       
   119 }
       
   120 
       
   121 void UT_QVersitProperty::testValue()
       
   122 {
       
   123     QString value(QString::fromAscii("050484747"));
       
   124     mVersitProperty->setValue(value);
       
   125     QCOMPARE(mVersitProperty->value(), value);
       
   126 }
       
   127 
       
   128 void UT_QVersitProperty::testEmbeddedDocument()
       
   129 {
       
   130     QVersitDocument document;
       
   131     QVersitProperty property;
       
   132     property.setName(QString::fromAscii("X-tension"));
       
   133     document.addProperty(property);
       
   134     mVersitProperty->setValue(QVariant::fromValue(document));
       
   135     QList<QVersitProperty> embeddedDocumentProperties =
       
   136         mVersitProperty->value<QVersitDocument>().properties();
       
   137     QCOMPARE(embeddedDocumentProperties.count(),1);
       
   138     QCOMPARE(embeddedDocumentProperties[0].name(),QString::fromAscii("X-TENSION"));
       
   139 }
       
   140 
       
   141 void UT_QVersitProperty::testEquality()
       
   142 {
       
   143     QVersitProperty property1;
       
   144     QVersitProperty property2;
       
   145     QVERIFY(property1.isEmpty());
       
   146     QVERIFY(property1 == property2);
       
   147     QVERIFY(!(property1 != property2));
       
   148     property2.setName(QLatin1String("FN"));
       
   149     property2.setValue(QLatin1String("John Citizen"));
       
   150     QVERIFY(!(property1 == property2));
       
   151     QVERIFY(property1 != property2);
       
   152     QVERIFY(!property2.isEmpty());
       
   153 
       
   154     property1.setName(QLatin1String("FN"));
       
   155     property1.setValue(QLatin1String("John Citizen"));
       
   156     QVERIFY(property1 == property2);
       
   157     QVERIFY(!(property1 != property2));
       
   158 
       
   159     property2.clear();
       
   160     QVERIFY(property2.isEmpty());
       
   161 
       
   162     property1.clear();
       
   163     QVERIFY(property1 == property2);
       
   164     QVERIFY(!(property1 != property2));
       
   165 }
       
   166 
       
   167 QTEST_MAIN(UT_QVersitProperty)
       
   168