~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/versit/qversitdocument/tst_qversitdocument.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
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.
 
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 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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
//TESTED_COMPONENT=src/versit
 
43
 
 
44
#include "tst_qversitdocument.h"
 
45
#include "qversitdocument.h"
 
46
#include "qversitproperty.h"
 
47
#include <QString>
 
48
#include <QtTest/QtTest>
 
49
 
 
50
QTVERSIT_USE_NAMESPACE
 
51
 
 
52
void tst_QVersitDocument::init()
 
53
{
 
54
    mVersitDocument = new QVersitDocument();
 
55
    QVERIFY(mVersitDocument);
 
56
}
 
57
 
 
58
void tst_QVersitDocument::cleanup()
 
59
{
 
60
    delete mVersitDocument;
 
61
}
 
62
 
 
63
 
 
64
void tst_QVersitDocument::testConstructor()
 
65
{
 
66
    QCOMPARE(QVersitDocument::InvalidType, mVersitDocument->type());
 
67
}
 
68
 
 
69
void tst_QVersitDocument::testType()
 
70
{
 
71
    mVersitDocument->setType(QVersitDocument::VCard21Type);
 
72
    QCOMPARE(QVersitDocument::VCard21Type, mVersitDocument->type());
 
73
 
 
74
    mVersitDocument->setType(QVersitDocument::VCard30Type);
 
75
    QCOMPARE(QVersitDocument::VCard30Type, mVersitDocument->type());
 
76
}
 
77
 
 
78
void tst_QVersitDocument::testAddProperty()
 
79
{
 
80
    QCOMPARE(0, mVersitDocument->properties().count());
 
81
    QVersitProperty property;
 
82
    mVersitDocument->addProperty(property);
 
83
    QCOMPARE(1, mVersitDocument->properties().count());
 
84
}
 
85
 
 
86
void tst_QVersitDocument::testRemoveProperty()
 
87
{
 
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);
 
94
 
 
95
    // A full property.
 
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);
 
115
}
 
116
 
 
117
void tst_QVersitDocument::testRemoveAllProperties()
 
118
{
 
119
    QString name(QStringLiteral("FN"));
 
120
 
 
121
    // Try to remove from an empty document
 
122
    QCOMPARE(0, mVersitDocument->properties().count());
 
123
    mVersitDocument->removeProperties(name);
 
124
    QCOMPARE(0, mVersitDocument->properties().count());
 
125
 
 
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());
 
133
 
 
134
    // Remove from a non-empty document, name matches
 
135
    mVersitDocument->removeProperties(QStringLiteral("TEL"));
 
136
    QCOMPARE(0, mVersitDocument->properties().count());
 
137
 
 
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());
 
146
 
 
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());
 
153
}
 
154
 
 
155
void tst_QVersitDocument::testEquality()
 
156
{
 
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());
 
169
 
 
170
    document1.addProperty(property);
 
171
    QVERIFY(document1 == document2);
 
172
    QVERIFY(!(document1 != document2));
 
173
 
 
174
    document2.clear();
 
175
    QVERIFY(document2.isEmpty());
 
176
 
 
177
    document1.clear();
 
178
    QVERIFY(document1 == document2);
 
179
    QVERIFY(!(document1 != document2));
 
180
 
 
181
    document2.setType(QVersitDocument::VCard21Type);
 
182
    QVERIFY(!(document1 == document2));
 
183
    QVERIFY(document1 != document2);
 
184
    QVERIFY(!document2.isEmpty());
 
185
 
 
186
    document2 = document1;
 
187
    QVERIFY(document1 == document2);
 
188
}
 
189
 
 
190
void tst_QVersitDocument::testHash()
 
191
{
 
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);
 
198
 
 
199
    QVersitDocument document2;
 
200
    document2.setType(QVersitDocument::VCard30Type);
 
201
    document2.addProperty(property1);
 
202
 
 
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);
 
209
 
 
210
    QVersitDocument document4; // no properties
 
211
    document4.setType(QVersitDocument::VCard30Type);
 
212
 
 
213
    QVersitDocument document5 = document1;
 
214
    document5.addSubDocument(document4);
 
215
 
 
216
    QVersitDocument document6 = document1;
 
217
    document6.setComponentType(QStringLiteral("VEVENT"));
 
218
 
 
219
    QVersitDocument document7 = document1;
 
220
    document7.addProperty(QVersitProperty());
 
221
 
 
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));
 
228
}
 
229
 
 
230
QTEST_MAIN(tst_QVersitDocument)
 
231