1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
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 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
//TESTED_COMPONENT=src/versit
44
#include "tst_qversitdocument.h"
45
#include "qversitdocument.h"
46
#include "qversitproperty.h"
48
#include <QtTest/QtTest>
50
QTVERSIT_USE_NAMESPACE
52
void tst_QVersitDocument::init()
54
mVersitDocument = new QVersitDocument();
55
QVERIFY(mVersitDocument);
58
void tst_QVersitDocument::cleanup()
60
delete mVersitDocument;
64
void tst_QVersitDocument::testConstructor()
66
QCOMPARE(QVersitDocument::InvalidType, mVersitDocument->type());
69
void tst_QVersitDocument::testType()
71
mVersitDocument->setType(QVersitDocument::VCard21Type);
72
QCOMPARE(QVersitDocument::VCard21Type, mVersitDocument->type());
74
mVersitDocument->setType(QVersitDocument::VCard30Type);
75
QCOMPARE(QVersitDocument::VCard30Type, mVersitDocument->type());
78
void tst_QVersitDocument::testAddProperty()
80
QCOMPARE(0, mVersitDocument->properties().count());
81
QVersitProperty property;
82
mVersitDocument->addProperty(property);
83
QCOMPARE(1, mVersitDocument->properties().count());
86
void tst_QVersitDocument::testRemoveProperty()
88
// Remove an empty property.
89
QCOMPARE(mVersitDocument->properties().count(), 0);
90
QVersitProperty property;
91
mVersitDocument->addProperty(property);
92
mVersitDocument->removeProperty(property);
93
QCOMPARE(mVersitDocument->properties().count(), 0);
96
property.setName(QStringLiteral("TEL"));
97
property.setGroups(QStringList(QStringLiteral("HOME")));
98
QMultiHash<QString, QString> params;
99
params.insert(QStringLiteral("TYPE"), QStringLiteral("HOME"));
100
property.setParameters(params);
101
property.setValue(QStringLiteral("123"));
102
mVersitDocument->addProperty(property);
103
QCOMPARE(mVersitDocument->properties().count(), 1);
104
QVersitProperty property2;
105
property2.setName(QStringLiteral("TEL"));
106
// Remove with a partial property fails.
107
mVersitDocument->removeProperty(property2);
108
QCOMPARE(mVersitDocument->properties().count(), 1);
109
property2.setGroups(QStringList(QStringLiteral("HOME")));
110
property2.setParameters(params);
111
property2.setValue(QStringLiteral("123"));
112
// Remove with a fully specified property succeeds.
113
mVersitDocument->removeProperty(property2);
114
QCOMPARE(mVersitDocument->properties().count(), 0);
117
void tst_QVersitDocument::testRemoveAllProperties()
119
QString name(QStringLiteral("FN"));
121
// Try to remove from an empty document
122
QCOMPARE(0, mVersitDocument->properties().count());
123
mVersitDocument->removeProperties(name);
124
QCOMPARE(0, mVersitDocument->properties().count());
126
// Try to remove from a non-empty document, name does not match
127
QVersitProperty property;
128
property.setName(QStringLiteral("TEL"));
129
mVersitDocument->addProperty(property);
130
QCOMPARE(1, mVersitDocument->properties().count());
131
mVersitDocument->removeProperties(name);
132
QCOMPARE(1, mVersitDocument->properties().count());
134
// Remove from a non-empty document, name matches
135
mVersitDocument->removeProperties(QStringLiteral("TEL"));
136
QCOMPARE(0, mVersitDocument->properties().count());
138
// Remove from a document with two properties, first matches
139
property.setName(name);
140
mVersitDocument->addProperty(property);
141
property.setName(QStringLiteral("TEL"));
142
mVersitDocument->addProperty(property);
143
QCOMPARE(2, mVersitDocument->properties().count());
144
mVersitDocument->removeProperties(name);
145
QCOMPARE(1, mVersitDocument->properties().count());
147
// Remove from a document with two properties, second matches
148
property.setName(name);
149
mVersitDocument->addProperty(property);
150
QCOMPARE(2, mVersitDocument->properties().count());
151
mVersitDocument->removeProperties(name);
152
QCOMPARE(1, mVersitDocument->properties().count());
155
void tst_QVersitDocument::testEquality()
157
QVersitDocument document1;
158
QVersitDocument document2;
159
QVERIFY(document1.isEmpty());
160
QVERIFY(document1 == document2);
161
QVERIFY(!(document1 != document2));
162
QVersitProperty property;
163
property.setName(QStringLiteral("FN"));
164
property.setValue(QStringLiteral("John Citizen"));
165
document2.addProperty(property);
166
QVERIFY(!(document1 == document2));
167
QVERIFY(document1 != document2);
168
QVERIFY(!document2.isEmpty());
170
document1.addProperty(property);
171
QVERIFY(document1 == document2);
172
QVERIFY(!(document1 != document2));
175
QVERIFY(document2.isEmpty());
178
QVERIFY(document1 == document2);
179
QVERIFY(!(document1 != document2));
181
document2.setType(QVersitDocument::VCard21Type);
182
QVERIFY(!(document1 == document2));
183
QVERIFY(document1 != document2);
184
QVERIFY(!document2.isEmpty());
186
document2 = document1;
187
QVERIFY(document1 == document2);
190
void tst_QVersitDocument::testHash()
192
QVersitDocument document1;
193
document1.setType(QVersitDocument::VCard30Type);
194
QVersitProperty property1;
195
property1.setName(QStringLiteral("name"));
196
property1.setValue(QStringLiteral("value"));
197
document1.addProperty(property1);
199
QVersitDocument document2;
200
document2.setType(QVersitDocument::VCard30Type);
201
document2.addProperty(property1);
203
QVersitDocument document3;
204
document3.setType(QVersitDocument::VCard30Type);
205
QVersitProperty property3;
206
property3.setName(QStringLiteral("name"));
207
property3.setValue(QStringLiteral("another value"));
208
document3.addProperty(property3);
210
QVersitDocument document4; // no properties
211
document4.setType(QVersitDocument::VCard30Type);
213
QVersitDocument document5 = document1;
214
document5.addSubDocument(document4);
216
QVersitDocument document6 = document1;
217
document6.setComponentType(QStringLiteral("VEVENT"));
219
QVersitDocument document7 = document1;
220
document7.addProperty(QVersitProperty());
222
QVERIFY(qHash(document1) == qHash(document2));
223
QVERIFY(qHash(document1) != qHash(document3));
224
QVERIFY(qHash(document1) != qHash(document4));
225
QVERIFY(qHash(document1) != qHash(document5));
226
QVERIFY(qHash(document1) != qHash(document6));
227
QVERIFY(qHash(document1) != qHash(document7));
230
QTEST_MAIN(tst_QVersitDocument)