| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | //TESTED_COMPONENT=src/versit |
| 35 | |
| 36 | #include "tst_qversitproperty.h" |
| 37 | #include <QtVersit/qversitproperty.h> |
| 38 | #include <QtVersit/private/qversitproperty_p.h> |
| 39 | #include <QtVersit/qversitdocument.h> |
| 40 | #include <QtTest/QtTest> |
| 41 | |
| 42 | QTVERSIT_USE_NAMESPACE |
| 43 | |
| 44 | void tst_QVersitProperty::init() |
| 45 | { |
| 46 | mVersitProperty = new QVersitProperty(); |
| 47 | QVERIFY(mVersitProperty); |
| 48 | } |
| 49 | |
| 50 | void tst_QVersitProperty::cleanup() |
| 51 | { |
| 52 | delete mVersitProperty; |
| 53 | } |
| 54 | |
| 55 | void tst_QVersitProperty::testGroup() |
| 56 | { |
| 57 | // One group |
| 58 | QStringList group(QStringLiteral("GROUP_NAME" )); |
| 59 | mVersitProperty->setGroups(group); |
| 60 | QCOMPARE(mVersitProperty->groups(), group); |
| 61 | |
| 62 | // Several groups |
| 63 | QStringList groupList; |
| 64 | groupList.append(QStringLiteral("GROUP1" )); |
| 65 | groupList.append(QStringLiteral("Group2" )); |
| 66 | groupList.append(QStringLiteral("group3" )); |
| 67 | mVersitProperty->setGroups(groupList); |
| 68 | QCOMPARE(mVersitProperty->groups(), groupList); |
| 69 | } |
| 70 | |
| 71 | void tst_QVersitProperty::testName() |
| 72 | { |
| 73 | // Name in upper case |
| 74 | QString name(QStringLiteral("TEL" )); |
| 75 | mVersitProperty->setName(name); |
| 76 | QCOMPARE(mVersitProperty->name(), name); |
| 77 | |
| 78 | // Name in lower case, converted automatically to upper case |
| 79 | mVersitProperty->setName(QStringLiteral("tel" )); |
| 80 | QCOMPARE(mVersitProperty->name(), name); |
| 81 | } |
| 82 | |
| 83 | void tst_QVersitProperty::testParameters() |
| 84 | { |
| 85 | QString typeParameterName(QStringLiteral("TYPE" )); |
| 86 | |
| 87 | QString name(QStringLiteral("type" )); |
| 88 | QString value1(QStringLiteral("home" )); |
| 89 | mVersitProperty->insertParameter(name,value: value1); |
| 90 | QMultiHash<QString,QString> parameters = mVersitProperty->parameters(); |
| 91 | QCOMPARE(parameters.count(), 1); |
| 92 | QVERIFY(parameters.contains(typeParameterName,QStringLiteral("home" ))); |
| 93 | |
| 94 | QString value2(QStringLiteral("voice" )); |
| 95 | mVersitProperty->insertParameter(name,value: value2); |
| 96 | parameters = mVersitProperty->parameters(); |
| 97 | QCOMPARE(parameters.count(), 2); |
| 98 | QVERIFY(parameters.contains(typeParameterName,QStringLiteral("home" ))); |
| 99 | QVERIFY(parameters.contains(typeParameterName,QStringLiteral("voice" ))); |
| 100 | |
| 101 | mVersitProperty->removeParameter(name,value: value1); |
| 102 | QCOMPARE(mVersitProperty->parameters().count(), 1); |
| 103 | QVERIFY(parameters.contains(typeParameterName,QStringLiteral("home" ))); |
| 104 | |
| 105 | mVersitProperty->removeParameter(name,value: value2); |
| 106 | QCOMPARE(mVersitProperty->parameters().count(), 0); |
| 107 | |
| 108 | mVersitProperty->insertParameter(name, value: value1); |
| 109 | mVersitProperty->insertParameter(name, value: value2); |
| 110 | QCOMPARE(mVersitProperty->parameters().count(), 2); |
| 111 | mVersitProperty->removeParameters(name); |
| 112 | QCOMPARE(mVersitProperty->parameters().count(), 0); |
| 113 | } |
| 114 | |
| 115 | void tst_QVersitProperty::testValue() |
| 116 | { |
| 117 | QString value(QStringLiteral("050484747" )); |
| 118 | mVersitProperty->setValue(value); |
| 119 | QCOMPARE(mVersitProperty->value(), value); |
| 120 | } |
| 121 | |
| 122 | void tst_QVersitProperty::testEmbeddedDocument() |
| 123 | { |
| 124 | QVersitDocument document; |
| 125 | QVersitProperty property; |
| 126 | property.setName(QStringLiteral("X-tension" )); |
| 127 | document.addProperty(property); |
| 128 | mVersitProperty->setValue(QVariant::fromValue(value: document)); |
| 129 | QList<QVersitProperty> embeddedDocumentProperties = |
| 130 | mVersitProperty->value<QVersitDocument>().properties(); |
| 131 | QCOMPARE(embeddedDocumentProperties.count(),1); |
| 132 | QCOMPARE(embeddedDocumentProperties[0].name(),QStringLiteral("X-TENSION" )); |
| 133 | } |
| 134 | |
| 135 | void tst_QVersitProperty::testEquality() |
| 136 | { |
| 137 | QVersitProperty property1; |
| 138 | QVersitProperty property2; |
| 139 | QVERIFY(property1.isEmpty()); |
| 140 | QVERIFY(property1 == property2); |
| 141 | QVERIFY(!(property1 != property2)); |
| 142 | property2.setName(QStringLiteral("FN" )); |
| 143 | property2.setValue(QStringLiteral("John Citizen" )); |
| 144 | QVERIFY(!(property1 == property2)); |
| 145 | QVERIFY(property1 != property2); |
| 146 | QVERIFY(!property2.isEmpty()); |
| 147 | |
| 148 | property1.setName(QStringLiteral("FN" )); |
| 149 | property1.setValue(QStringLiteral("John Citizen" )); |
| 150 | QVERIFY(property1 == property2); |
| 151 | QVERIFY(!(property1 != property2)); |
| 152 | |
| 153 | property2.clear(); |
| 154 | QVERIFY(property2.isEmpty()); |
| 155 | |
| 156 | property1.clear(); |
| 157 | QVERIFY(property1 == property2); |
| 158 | QVERIFY(!(property1 != property2)); |
| 159 | } |
| 160 | |
| 161 | void tst_QVersitProperty::testHash() |
| 162 | { |
| 163 | QVersitProperty property1; |
| 164 | property1.setGroups(QStringList() << QStringLiteral("group1" ) << QStringLiteral("group2" )); |
| 165 | property1.setName(QStringLiteral("name" )); |
| 166 | property1.setValue(QStringLiteral("value" )); |
| 167 | property1.insertParameter(QStringLiteral("param" ), QStringLiteral("value" )); |
| 168 | QVersitProperty property2; |
| 169 | property2.setGroups(QStringList() << QStringLiteral("group1" ) << QStringLiteral("group2" )); |
| 170 | property2.setName(QStringLiteral("name" )); |
| 171 | property2.setValue(QStringLiteral("value" )); |
| 172 | property2.insertParameter(QStringLiteral("param" ), QStringLiteral("value" )); |
| 173 | QVersitProperty property3; // no groups |
| 174 | property3.setName(QStringLiteral("name" )); |
| 175 | property3.setValue(QStringLiteral("value" )); |
| 176 | property3.insertParameter(QStringLiteral("param" ), QStringLiteral("value" )); |
| 177 | QVersitProperty property4; // no params |
| 178 | property4.setGroups(QStringList() << QStringLiteral("group1" ) << QStringLiteral("group2" )); |
| 179 | property4.setName(QStringLiteral("name" )); |
| 180 | property4.setValue(QStringLiteral("value" )); |
| 181 | |
| 182 | QVERIFY(qHash(property1) == qHash(property2)); |
| 183 | QVERIFY(qHash(property1) != qHash(property3)); |
| 184 | QVERIFY(qHash(property1) != qHash(property4)); |
| 185 | QVERIFY(qHash(property3) != qHash(property4)); |
| 186 | QSet<QVersitProperty> set; |
| 187 | set.insert(value: property1); |
| 188 | set.insert(value: property2); |
| 189 | set.insert(value: property3); |
| 190 | set.insert(value: property4); |
| 191 | QCOMPARE(set.size(), 3); |
| 192 | } |
| 193 | |
| 194 | QTEST_MAIN(tst_QVersitProperty) |
| 195 | |
| 196 | |