170
170
QCOMPARE(receivedIds, messageIds);
173
void ChatManagerTest::testSendMessageWithAttachments_data()
175
QTest::addColumn<QStringList>("recipients");
176
QTest::addColumn<QString>("message");
177
QTest::addColumn<QString>("accountId");
178
QTest::addColumn<bool>("mmsFlag");
180
QTest::newRow("message via the generic account") << (QStringList() << "recipient1") << QString("Hello world") << QString("mock/mock/account0") << false;
181
QTest::newRow("message via the phone account") << (QStringList() << "1234567") << QString("Hello Phone World") << QString("mock/ofono/account0") << true;
185
173
void ChatManagerTest::testSendMessageWithAttachments()
187
QFETCH(QStringList, recipients);
188
QFETCH(QString, message);
189
QFETCH(QString, accountId);
190
QFETCH(bool, mmsFlag);
192
// just to make it easier, sort the recipients
195
MockController *controller = accountId.startsWith("mock/mock") ? mGenericMockController : mPhoneMockController;
175
QStringList recipients = (QStringList() << "1234567");
176
QString message("Hello Phone Attachments World");
177
QString accountId("mock/ofono/account0");
179
MockController *controller = mPhoneMockController;
197
181
QSignalSpy controllerMessageSentSpy(controller, SIGNAL(MessageSent(QString,QVariantList,QVariantMap)));
199
183
QVariantList attachmentList;
200
184
QVariantList attachment;
201
attachment << "id" << "content/type" << "filepath";
185
attachment << "id" << "content/type" << QString("%1/%2").arg(QString(qgetenv("TEST_DATA_DIR"))).arg("dialer-app.png");
202
186
attachmentList << QVariant::fromValue(attachment);
203
187
QVariant attachments = QVariant::fromValue(attachmentList);
207
191
ChatManager::instance()->sendMessage(accountId, message, attachments, properties);
209
193
TRY_COMPARE(controllerMessageSentSpy.count(), 1);
210
195
QString messageText = controllerMessageSentSpy.first()[0].toString();
196
QVariantList messageAttachments = controllerMessageSentSpy.first()[1].toList();
211
197
QVariantMap messageProperties = controllerMessageSentSpy.first()[2].toMap();
212
198
QStringList messageRecipients = messageProperties["Recipients"].toStringList();
213
199
qSort(messageRecipients);
214
200
QCOMPARE(messageText, message);
215
201
QCOMPARE(messageRecipients, recipients);
217
QCOMPARE(messageProperties.contains("x-canonical-mms"), mmsFlag);
218
QCOMPARE(messageProperties["x-canonical-mms"].toBool(), mmsFlag);
202
QCOMPARE(messageAttachments.count(), attachmentList.count());
205
void ChatManagerTest::testSendMessageWithAttachmentsSplitted()
207
// messages sent on accounts other than phone are splitted, so make sure that happens
208
QStringList recipients = (QStringList() << "theattachmentrecipient");
209
QString message("Hello Attachments World");
210
QString accountId("mock/mock/account0");
212
MockController *controller = mGenericMockController;
214
QSignalSpy controllerMessageSentSpy(controller, SIGNAL(MessageSent(QString,QVariantList,QVariantMap)));
216
QVariantList attachmentList;
217
QVariantList attachment;
218
attachment << "id" << "content/type" << QString("%1/%2").arg(QString(qgetenv("TEST_DATA_DIR"))).arg("dialer-app.png");
219
attachmentList << QVariant::fromValue(attachment);
220
QVariant attachments = QVariant::fromValue(attachmentList);
222
QVariantMap properties;
223
properties["participantIds"] = recipients;
224
ChatManager::instance()->sendMessage(accountId, message, attachments, properties);
226
TRY_COMPARE(controllerMessageSentSpy.count(), attachmentList.count() + 1);
229
int attachmentCount = 0;
230
// as the message is splitted, we have to go through all the received messages to find the
231
// text and attachments
232
for (int i = 0; i < controllerMessageSentSpy.count(); ++i) {
233
QList<QVariant> args = controllerMessageSentSpy[i];
234
// validate the recipients on all messages
235
QVariantMap messageProperties = args[2].toMap();
236
QStringList messageRecipients = messageProperties["Recipients"].toStringList();
237
qSort(messageRecipients);
238
QCOMPARE(messageRecipients, recipients);
239
QString text = args[0].toString();
240
if (!text.isEmpty()) {
243
QVariantList attachments = args[1].toList();
244
// each message should contain no more than one attachment
245
QCOMPARE(attachments.count(), 1);
246
attachmentCount += 1;
249
QCOMPARE(messageText, message);
250
QCOMPARE(attachmentCount, attachmentList.count());
221
254
QTEST_MAIN(ChatManagerTest)