|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 "tst_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 tst_QVersitProperty::init() |
|
51 { |
|
52 mVersitProperty = new QVersitProperty(); |
|
53 QVERIFY(mVersitProperty); |
|
54 } |
|
55 |
|
56 void tst_QVersitProperty::cleanup() |
|
57 { |
|
58 delete mVersitProperty; |
|
59 } |
|
60 |
|
61 void tst_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 tst_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 tst_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 tst_QVersitProperty::testValue() |
|
122 { |
|
123 QString value(QString::fromAscii("050484747")); |
|
124 mVersitProperty->setValue(value); |
|
125 QCOMPARE(mVersitProperty->value(), value); |
|
126 } |
|
127 |
|
128 void tst_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 tst_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 void tst_QVersitProperty::testHash() |
|
168 { |
|
169 QVersitProperty property1; |
|
170 property1.setGroups(QStringList() << QLatin1String("group1") << QLatin1String("group2")); |
|
171 property1.setName(QLatin1String("name")); |
|
172 property1.setValue(QLatin1String("value")); |
|
173 property1.insertParameter(QLatin1String("param"), QLatin1String("value")); |
|
174 QVersitProperty property2; |
|
175 property2.setGroups(QStringList() << QLatin1String("group1") << QLatin1String("group2")); |
|
176 property2.setName(QLatin1String("name")); |
|
177 property2.setValue(QLatin1String("value")); |
|
178 property2.insertParameter(QLatin1String("param"), QLatin1String("value")); |
|
179 QVersitProperty property3; // no groups |
|
180 property3.setName(QLatin1String("name")); |
|
181 property3.setValue(QLatin1String("value")); |
|
182 property3.insertParameter(QLatin1String("param"), QLatin1String("value")); |
|
183 QVersitProperty property4; // no params |
|
184 property4.setGroups(QStringList() << QLatin1String("group1") << QLatin1String("group2")); |
|
185 property4.setName(QLatin1String("name")); |
|
186 property4.setValue(QLatin1String("value")); |
|
187 |
|
188 QVERIFY(qHash(property1) == qHash(property2)); |
|
189 QVERIFY(qHash(property1) != qHash(property3)); |
|
190 QVERIFY(qHash(property1) != qHash(property4)); |
|
191 QVERIFY(qHash(property3) != qHash(property4)); |
|
192 QSet<QVersitProperty> set; |
|
193 set.insert(property1); |
|
194 set.insert(property2); |
|
195 set.insert(property3); |
|
196 set.insert(property4); |
|
197 QCOMPARE(set.size(), 3); |
|
198 } |
|
199 |
|
200 QTEST_MAIN(tst_QVersitProperty) |
|
201 |