2
* Copyright (C) 2015 Canonical, Ltd.
4
* This file is part of history-service.
6
* history-service is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* history-service is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include <QtCore/QObject>
20
#include <QtTest/QtTest>
22
#include "participant.h"
25
Q_DECLARE_METATYPE(History::Participant)
27
class ParticipantTest : public QObject
33
void testConstructor();
34
void testNullParticipant();
35
void testIsNull_data();
37
void testCopyConstructor();
38
void testAssignmentOperator();
39
void testEqualsOperator_data();
40
void testEqualsOperator();
41
void testProperties();
42
void testFromProperties();
43
void testIdentifiers();
44
void testFromVariantList();
45
void testToVariantList();
46
void testFromVariantWithVariantList();
49
void ParticipantTest::initTestCase()
51
qRegisterMetaType<History::Participant>();
54
void ParticipantTest::testConstructor()
56
QString accountId("theAccountId");
57
QString identifier("theParticipantId");
58
QString contactId("theContactId");
59
QString alias("theAlias");
60
QString avatar("theAvatar");
61
QVariantMap detailProperties;
62
detailProperties["someProperty"] = "someValue";
65
History::Participant participant(accountId, identifier, contactId, alias, avatar, detailProperties);
66
QCOMPARE(participant.accountId(), accountId);
67
QCOMPARE(participant.identifier(), identifier);
68
QCOMPARE(participant.contactId(), contactId);
69
QCOMPARE(participant.alias(), alias);
70
QCOMPARE(participant.avatar(), avatar);
71
QCOMPARE(participant.detailProperties(), detailProperties);
74
void ParticipantTest::testNullParticipant()
76
// check that a null participant returns true
77
History::Participant nullParticipant;
78
QVERIFY(nullParticipant.isNull());
81
void ParticipantTest::testIsNull_data()
83
QTest::addColumn<QString>("accountId");
84
QTest::addColumn<QString>("identifier");
85
QTest::addColumn<bool>("isNull");
87
QTest::newRow("all null") << QString() << QString() << true;
88
QTest::newRow("null accountId") << QString() << "some identifier" << true;
89
QTest::newRow("null identifier") << "some account ID" << QString() << true;
90
QTest::newRow("valid account and identifier") << "theAccountId" << "theIdentifier" << false;
93
void ParticipantTest::testIsNull()
95
QFETCH(QString, accountId);
96
QFETCH(QString, identifier);
99
History::Participant participant(accountId, identifier);
100
QCOMPARE(participant.isNull(), isNull);
104
void ParticipantTest::testCopyConstructor()
106
QVariantMap detailProperties;
107
detailProperties["theProperty"] = "theValue";
108
History::Participant original("accountId", "identifier", "contactId", "alias", "avatar", detailProperties);
110
History::Participant copy(original);
112
QCOMPARE(copy.accountId(), original.accountId());
113
QCOMPARE(copy.identifier(), original.identifier());
114
QCOMPARE(copy.contactId(), original.contactId());
115
QCOMPARE(copy.alias(), original.alias());
116
QCOMPARE(copy.avatar(), original.avatar());
117
QCOMPARE(copy.detailProperties(), original.detailProperties());
120
void ParticipantTest::testAssignmentOperator()
122
QVariantMap detailProperties;
123
detailProperties["theProperty2"] = "theValue2";
124
History::Participant original("accountId2", "identifier2", "contactId2", "alias2", "avatar2", detailProperties);
126
History::Participant copy;
129
QCOMPARE(copy.accountId(), original.accountId());
130
QCOMPARE(copy.identifier(), original.identifier());
131
QCOMPARE(copy.contactId(), original.contactId());
132
QCOMPARE(copy.alias(), original.alias());
133
QCOMPARE(copy.avatar(), original.avatar());
134
QCOMPARE(copy.detailProperties(), original.detailProperties());
137
void ParticipantTest::testEqualsOperator_data()
139
QTest::addColumn<QString>("accountId1");
140
QTest::addColumn<QString>("identifier1");
141
QTest::addColumn<QString>("accountId2");
142
QTest::addColumn<QString>("identifier2");
143
QTest::addColumn<bool>("equals");
145
QTest::newRow("same participant") << "theAccountId" << "theIdentifier" << "theAccountId" << "theIdentifier" << true;
146
QTest::newRow("different identifiers") << "theAccountId" << "theIdentifier1" << "theAccountId" << "theIdentifier2" << false;
147
QTest::newRow("different accounts") << "theAccountId1" << "theIdentifier" << "theAccountId2" << "theIdentifier" << false;
148
QTest::newRow("all different") << "theAccountId" << "theIdentifier" << "theAccountId2" << "theIdentifier2" << false;
151
void ParticipantTest::testEqualsOperator()
153
QFETCH(QString, accountId1);
154
QFETCH(QString, identifier1);
155
QFETCH(QString, accountId2);
156
QFETCH(QString, identifier2);
157
QFETCH(bool, equals);
159
History::Participant participant1(accountId1, identifier1);
160
History::Participant participant2(accountId2, identifier2);
161
QCOMPARE((participant1 == participant2), equals);
164
void ParticipantTest::testProperties()
166
QVariantMap detailProperties;
167
detailProperties["someDetailProperty"] = "someValue";
169
History::Participant participant("theAccountId", "theIdentifier", "theContactId", "theAlias", "theAvatar", detailProperties);
170
QVariantMap properties = participant.properties();
171
QCOMPARE(properties[History::FieldAccountId].toString(), participant.accountId());
172
QCOMPARE(properties[History::FieldIdentifier].toString(), participant.identifier());
173
QCOMPARE(properties[History::FieldContactId].toString(), participant.contactId());
174
QCOMPARE(properties[History::FieldAlias].toString(), participant.alias());
175
QCOMPARE(properties[History::FieldAvatar].toString(), participant.avatar());
176
QCOMPARE(properties[History::FieldDetailProperties].toMap(), participant.detailProperties());
179
void ParticipantTest::testFromProperties()
181
QVariantMap properties;
182
QVariantMap detailProperties;
184
properties[History::FieldAccountId] = "someAccountId";
185
properties[History::FieldIdentifier] = "someIdentifier";
186
properties[History::FieldContactId] = "someContactId";
187
properties[History::FieldAlias] = "someAlias";
188
properties[History::FieldAvatar] = "someAvatar";
189
detailProperties["someDetailProperty"] = "someValue";
190
properties[History::FieldDetailProperties] = detailProperties;
192
History::Participant participant = History::Participant::fromProperties(properties);
193
QCOMPARE(participant.accountId(), properties[History::FieldAccountId].toString());
194
QCOMPARE(participant.identifier(), properties[History::FieldIdentifier].toString());
195
QCOMPARE(participant.contactId(), properties[History::FieldContactId].toString());
196
QCOMPARE(participant.alias(), properties[History::FieldAlias].toString());
197
QCOMPARE(participant.avatar(), properties[History::FieldAvatar].toString());
198
QCOMPARE(participant.detailProperties(), properties[History::FieldDetailProperties].toMap());
201
void ParticipantTest::testIdentifiers()
203
QStringList identifiers;
204
identifiers << "firstId" << "secondId" << "thirdId";
205
History::Participants participants;
206
Q_FOREACH(const QString &identifier, identifiers) {
207
participants << History::Participant("theAccountId", identifier);
209
QCOMPARE(participants.identifiers(), identifiers);
212
void ParticipantTest::testFromVariantList()
215
for (int i = 0; i < 10; ++i) {
216
list << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i))).properties();
219
History::Participants participants = History::Participants::fromVariantList(list);
220
QCOMPARE(participants.count(), list.count());
221
for (int i = 0; i < participants.count(); ++i) {
222
QCOMPARE(participants[i].properties(), list[i].toMap());
226
void ParticipantTest::testToVariantList()
228
History::Participants participants;
229
for (int i = 0; i < 10; ++i) {
230
participants << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i)));
233
QVariantList list = participants.toVariantList();
234
QCOMPARE(list.count(), participants.count());
235
for (int i = 0; i < list.count(); ++i) {
236
QCOMPARE(list[i].toMap(), participants[i].properties());
240
void ParticipantTest::testFromVariantWithVariantList()
243
for (int i = 0; i < 10; ++i) {
244
list << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i))).properties();
247
History::Participants participants = History::Participants::fromVariant(list);
248
QCOMPARE(participants.count(), list.count());
249
for (int i = 0; i < participants.count(); ++i) {
250
QCOMPARE(participants[i].properties(), list[i].toMap());
254
QTEST_MAIN(ParticipantTest)
255
#include "ParticipantTest.moc"