~ci-train-bot/history-service/history-service-ubuntu-yakkety-landing-052

« back to all changes in this revision

Viewing changes to tests/libhistoryservice/ParticipantTest.cpp

Request contact information for all known participants on history-daemon initialization, and use this cached information on the models.
Approved by: Tiago Salem Herrmann, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical, Ltd.
 
3
 *
 
4
 * This file is part of history-service.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include <QtCore/QObject>
 
20
#include <QtTest/QtTest>
 
21
 
 
22
#include "participant.h"
 
23
#include "types.h"
 
24
 
 
25
Q_DECLARE_METATYPE(History::Participant)
 
26
 
 
27
class ParticipantTest : public QObject
 
28
{
 
29
    Q_OBJECT
 
30
 
 
31
private Q_SLOTS:
 
32
    void initTestCase();
 
33
    void testConstructor();
 
34
    void testNullParticipant();
 
35
    void testIsNull_data();
 
36
    void testIsNull();
 
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();
 
47
};
 
48
 
 
49
void ParticipantTest::initTestCase()
 
50
{
 
51
    qRegisterMetaType<History::Participant>();
 
52
}
 
53
 
 
54
void ParticipantTest::testConstructor()
 
55
{
 
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";
 
63
 
 
64
 
 
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);
 
72
}
 
73
 
 
74
void ParticipantTest::testNullParticipant()
 
75
{
 
76
    // check that a null participant returns true
 
77
    History::Participant nullParticipant;
 
78
    QVERIFY(nullParticipant.isNull());
 
79
}
 
80
 
 
81
void ParticipantTest::testIsNull_data()
 
82
{
 
83
    QTest::addColumn<QString>("accountId");
 
84
    QTest::addColumn<QString>("identifier");
 
85
    QTest::addColumn<bool>("isNull");
 
86
 
 
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;
 
91
}
 
92
 
 
93
void ParticipantTest::testIsNull()
 
94
{
 
95
    QFETCH(QString, accountId);
 
96
    QFETCH(QString, identifier);
 
97
    QFETCH(bool, isNull);
 
98
 
 
99
    History::Participant participant(accountId, identifier);
 
100
    QCOMPARE(participant.isNull(), isNull);
 
101
 
 
102
}
 
103
 
 
104
void ParticipantTest::testCopyConstructor()
 
105
{
 
106
    QVariantMap detailProperties;
 
107
    detailProperties["theProperty"] = "theValue";
 
108
    History::Participant original("accountId", "identifier", "contactId", "alias", "avatar", detailProperties);
 
109
 
 
110
    History::Participant copy(original);
 
111
 
 
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());
 
118
}
 
119
 
 
120
void ParticipantTest::testAssignmentOperator()
 
121
{
 
122
    QVariantMap detailProperties;
 
123
    detailProperties["theProperty2"] = "theValue2";
 
124
    History::Participant original("accountId2", "identifier2", "contactId2", "alias2", "avatar2", detailProperties);
 
125
 
 
126
    History::Participant copy;
 
127
    copy = original;
 
128
 
 
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());
 
135
}
 
136
 
 
137
void ParticipantTest::testEqualsOperator_data()
 
138
{
 
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");
 
144
 
 
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;
 
149
}
 
150
 
 
151
void ParticipantTest::testEqualsOperator()
 
152
{
 
153
    QFETCH(QString, accountId1);
 
154
    QFETCH(QString, identifier1);
 
155
    QFETCH(QString, accountId2);
 
156
    QFETCH(QString, identifier2);
 
157
    QFETCH(bool, equals);
 
158
 
 
159
    History::Participant participant1(accountId1, identifier1);
 
160
    History::Participant participant2(accountId2, identifier2);
 
161
    QCOMPARE((participant1 == participant2), equals);
 
162
}
 
163
 
 
164
void ParticipantTest::testProperties()
 
165
{
 
166
    QVariantMap detailProperties;
 
167
    detailProperties["someDetailProperty"] = "someValue";
 
168
 
 
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());
 
177
}
 
178
 
 
179
void ParticipantTest::testFromProperties()
 
180
{
 
181
    QVariantMap properties;
 
182
    QVariantMap detailProperties;
 
183
 
 
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;
 
191
 
 
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());
 
199
}
 
200
 
 
201
void ParticipantTest::testIdentifiers()
 
202
{
 
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);
 
208
    }
 
209
    QCOMPARE(participants.identifiers(), identifiers);
 
210
}
 
211
 
 
212
void ParticipantTest::testFromVariantList()
 
213
{
 
214
    QVariantList list;
 
215
    for (int i = 0; i < 10; ++i) {
 
216
        list << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i))).properties();
 
217
    }
 
218
 
 
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());
 
223
    }
 
224
}
 
225
 
 
226
void ParticipantTest::testToVariantList()
 
227
{
 
228
    History::Participants participants;
 
229
    for (int i = 0; i < 10; ++i) {
 
230
        participants << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i)));
 
231
    }
 
232
 
 
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());
 
237
    }
 
238
}
 
239
 
 
240
void ParticipantTest::testFromVariantWithVariantList()
 
241
{
 
242
    QVariantList list;
 
243
    for (int i = 0; i < 10; ++i) {
 
244
        list << History::Participant("theAccountId", QString("identifier%1").arg(QString::number(i))).properties();
 
245
    }
 
246
 
 
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());
 
251
    }
 
252
}
 
253
 
 
254
QTEST_MAIN(ParticipantTest)
 
255
#include "ParticipantTest.moc"