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

« back to all changes in this revision

Viewing changes to tests/libhistoryservice/TextEventTest.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:
35
35
    void testProperties_data();
36
36
    void testProperties();
37
37
    void testSetProperties();
 
38
 
 
39
private:
 
40
    History::Participants participantsFromIdentifiers(const QString &accountId, const QStringList &identifiers);
38
41
};
39
42
 
40
43
void TextEventTest::testCreateNewEvent_data()
50
53
    QTest::addColumn<int>("messageStatus");
51
54
    QTest::addColumn<QDateTime>("readTimestamp");
52
55
    QTest::addColumn<QString>("subject");
 
56
    QTest::addColumn<QStringList>("participants");
53
57
 
54
58
    QTest::newRow("unread message") << "testAccountId" << "testThreadId" << "testEventId"
55
59
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
56
60
                                    << true << "One Test Message" << (int)History::MessageTypeText
57
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject";
58
 
    QTest::newRow("read message") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
61
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject"
 
62
                                    << (QStringList() << "testParticipant");
 
63
    QTest::newRow("read message")   << "testAccountId2" << "testThreadId2" << "testEventId2"
59
64
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-10)
60
65
                                    << false << "One Test Message" << (int)History::MessageTypeText
61
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2";
 
66
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2"
 
67
                                    << (QStringList() << "testParticipant2");
62
68
    QTest::newRow("message status") << "testAccountId" << "testThreadId" << "testEventId"
63
69
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
64
70
                                    << true << "One Test Message" << (int)History::MessageTypeText
65
71
                                    << (int)History::MessageStatusAccepted
66
 
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3";
 
72
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3"
 
73
                                    << (QStringList() << "testParticipant");
67
74
    QTest::newRow("multi party message") << "testAccountId" << "testThreadId" << "testEventId"
68
75
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
69
76
                                    << true << "One Test Message" << (int)History::MessageTypeMultiPart
70
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString();
 
77
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString()
 
78
                                    << (QStringList() << "testParticipant");
 
79
    QTest::newRow("multiple participants") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
80
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-7)
 
81
                                    << true << "One Test Message 2" << (int)History::MessageTypeText
 
82
                                    << 0 << QDateTime::currentDateTime().addDays(-4) << QString()
 
83
                                    << (QStringList() << "one" << "two" << "three" << "four");
71
84
}
72
85
 
73
86
void TextEventTest::testCreateNewEvent()
83
96
    QFETCH(int, messageStatus);
84
97
    QFETCH(QDateTime, readTimestamp);
85
98
    QFETCH(QString, subject);
 
99
    QFETCH(QStringList, participants);
86
100
    History::TextEvent event(accountId, threadId, eventId, senderId, timestamp, newEvent,
87
101
                             message, (History::MessageType)messageType, (History::MessageStatus)messageStatus,
88
 
                             readTimestamp, subject);
 
102
                             readTimestamp, subject, History::TextEventAttachments(),
 
103
                             participantsFromIdentifiers(accountId, participants));
89
104
 
90
105
    // check that the values are properly set
91
106
    QCOMPARE(event.accountId(), accountId);
99
114
    QCOMPARE(event.messageStatus(), (History::MessageStatus)messageStatus);
100
115
    QCOMPARE(event.readTimestamp(), readTimestamp);
101
116
    QCOMPARE(event.subject(), subject);
 
117
    QCOMPARE(event.participants().identifiers(), participants);
102
118
}
103
119
 
104
120
void TextEventTest::testCastToEventAndBack()
134
150
    QTest::addColumn<int>("messageStatus");
135
151
    QTest::addColumn<QDateTime>("readTimestamp");
136
152
    QTest::addColumn<QString>("subject");
 
153
    QTest::addColumn<QStringList>("participants");
137
154
 
138
155
    QTest::newRow("unread message") << "testAccountId" << "testThreadId" << "testEventId"
139
156
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
140
157
                                    << true << "One Test Message" << (int)History::MessageTypeText
141
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject";
142
 
    QTest::newRow("read message") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
158
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject"
 
159
                                    << (QStringList() << "testParticipant");
 
160
    QTest::newRow("read message")   << "testAccountId2" << "testThreadId2" << "testEventId2"
143
161
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-10)
144
162
                                    << false << "One Test Message" << (int)History::MessageTypeText
145
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2";
 
163
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2"
 
164
                                    << (QStringList() << "testParticipant2");
146
165
    QTest::newRow("message status") << "testAccountId" << "testThreadId" << "testEventId"
147
166
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
148
167
                                    << true << "One Test Message" << (int)History::MessageTypeText
149
 
                                    << (int)History::MessageStatusDelivered
150
 
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3";
 
168
                                    << (int)History::MessageStatusAccepted
 
169
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3"
 
170
                                    << (QStringList() << "testParticipant");
151
171
    QTest::newRow("multi party message") << "testAccountId" << "testThreadId" << "testEventId"
152
172
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
153
173
                                    << true << "One Test Message" << (int)History::MessageTypeMultiPart
154
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString();
 
174
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString()
 
175
                                    << (QStringList() << "testParticipant");
 
176
    QTest::newRow("multiple participants") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
177
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-7)
 
178
                                    << true << "One Test Message 2" << (int)History::MessageTypeText
 
179
                                    << 0 << QDateTime::currentDateTime().addDays(-4) << QString()
 
180
                                    << (QStringList() << "one" << "two" << "three" << "four");
155
181
}
156
182
 
157
183
void TextEventTest::testFromProperties()
167
193
    QFETCH(int, messageStatus);
168
194
    QFETCH(QDateTime, readTimestamp);
169
195
    QFETCH(QString, subject);
 
196
    QFETCH(QStringList, participants);
170
197
 
171
198
    QVariantMap properties;
172
199
    properties[History::FieldAccountId] = accountId;
180
207
    properties[History::FieldMessageStatus] = messageStatus;
181
208
    properties[History::FieldReadTimestamp] = readTimestamp.toString("yyyy-MM-ddTHH:mm:ss.zzz");
182
209
    properties[History::FieldSubject] = subject;
 
210
    properties[History::FieldParticipants] = participantsFromIdentifiers(accountId, participants).toVariantList();
183
211
 
184
212
    History::TextEvent textEvent = History::TextEvent::fromProperties(properties);
185
213
    QCOMPARE(textEvent.accountId(), accountId);
193
221
    QCOMPARE(textEvent.messageStatus(), (History::MessageStatus) messageStatus);
194
222
    QCOMPARE(textEvent.readTimestamp().toString(Qt::ISODate), readTimestamp.toString(Qt::ISODate));
195
223
    QCOMPARE(textEvent.subject(), subject);
 
224
    QCOMPARE(textEvent.participants().identifiers(), participants);
196
225
}
197
226
 
198
227
void TextEventTest::testFromNullProperties()
216
245
    QTest::addColumn<int>("messageStatus");
217
246
    QTest::addColumn<QDateTime>("readTimestamp");
218
247
    QTest::addColumn<QString>("subject");
 
248
    QTest::addColumn<QStringList>("participants");
219
249
 
220
250
    QTest::newRow("unread message") << "testAccountId" << "testThreadId" << "testEventId"
221
251
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
222
252
                                    << true << "One Test Message" << (int)History::MessageTypeText
223
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject";
224
 
    QTest::newRow("read message") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
253
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject"
 
254
                                    << (QStringList() << "testParticipant");
 
255
    QTest::newRow("read message")   << "testAccountId2" << "testThreadId2" << "testEventId2"
225
256
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-10)
226
257
                                    << false << "One Test Message" << (int)History::MessageTypeText
227
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2";
 
258
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << "Test Subject 2"
 
259
                                    << (QStringList() << "testParticipant2");
228
260
    QTest::newRow("message status") << "testAccountId" << "testThreadId" << "testEventId"
229
261
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
230
262
                                    << true << "One Test Message" << (int)History::MessageTypeText
231
 
                                    << (int)History::MessageStatusPending
232
 
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3";
 
263
                                    << (int)History::MessageStatusAccepted
 
264
                                    << QDateTime::currentDateTime().addDays(-5) << "Test Subject 3"
 
265
                                    << (QStringList() << "testParticipant");
233
266
    QTest::newRow("multi party message") << "testAccountId" << "testThreadId" << "testEventId"
234
267
                                    << "testSenderId" << QDateTime::currentDateTime().addDays(-10)
235
268
                                    << true << "One Test Message" << (int)History::MessageTypeMultiPart
236
 
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString();
 
269
                                    << 0 << QDateTime::currentDateTime().addDays(-5) << QString()
 
270
                                    << (QStringList() << "testParticipant");
 
271
    QTest::newRow("multiple participants") << "testAccountId2" << "testThreadId2" << "testEventId2"
 
272
                                    << "testSenderId2" << QDateTime::currentDateTime().addDays(-7)
 
273
                                    << true << "One Test Message 2" << (int)History::MessageTypeText
 
274
                                    << 0 << QDateTime::currentDateTime().addDays(-4) << QString()
 
275
                                    << (QStringList() << "one" << "two" << "three" << "four");
237
276
}
238
277
 
239
278
void TextEventTest::testProperties()
249
288
    QFETCH(int, messageStatus);
250
289
    QFETCH(QDateTime, readTimestamp);
251
290
    QFETCH(QString, subject);
 
291
    QFETCH(QStringList, participants);
252
292
    History::TextEvent event(accountId, threadId, eventId, senderId, timestamp, newEvent,
253
293
                             message, (History::MessageType)messageType, (History::MessageStatus)messageStatus,
254
 
                             readTimestamp, subject);
 
294
                             readTimestamp, subject, History::TextEventAttachments(),
 
295
                             participantsFromIdentifiers(accountId, participants));
255
296
 
256
297
    QVariantMap properties = event.properties();
257
298
    QCOMPARE(properties[History::FieldAccountId].toString(), accountId);
265
306
    QCOMPARE(properties[History::FieldMessageStatus].toInt(), messageStatus);
266
307
    QCOMPARE(properties[History::FieldReadTimestamp].toString(), readTimestamp.toString("yyyy-MM-ddTHH:mm:ss.zzz"));
267
308
    QCOMPARE(properties[History::FieldSubject].toString(), subject);
 
309
    QCOMPARE(History::Participants::fromVariantList(properties[History::FieldParticipants].toList()).identifiers(), participants);
268
310
}
269
311
 
270
312
void TextEventTest::testSetProperties()
282
324
    QCOMPARE(textEvent.newEvent(), newEvent);
283
325
}
284
326
 
 
327
History::Participants TextEventTest::participantsFromIdentifiers(const QString &accountId, const QStringList &identifiers)
 
328
{
 
329
    History::Participants participants;
 
330
    Q_FOREACH(const QString &identifier, identifiers) {
 
331
        participants << History::Participant(accountId, identifier);
 
332
    }
 
333
    return participants;
 
334
}
 
335
 
285
336
QTEST_MAIN(TextEventTest)
286
337
#include "TextEventTest.moc"