~phablet-team/telephony-service/qml-start-chat

« back to all changes in this revision

Viewing changes to tests/libtelephonyservice/ChatManagerTest.cpp

  • Committer: Gustavo Pichorim Boiko
  • Date: 2016-10-29 02:20:13 UTC
  • mfrom: (1228.2.3 fix_tests)
  • Revision ID: gustavo.boiko@canonical.com-20161029022013-a1uxqqq8g93scwsi
Fix tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2013-2015 Canonical, Ltd.
 
2
 * Copyright (C) 2013-2016 Canonical, Ltd.
3
3
 *
4
4
 * This file is part of telephony-service.
5
5
 *
36
36
    void cleanup();
37
37
    void testSendMessage_data();
38
38
    void testSendMessage();
39
 
    void testSendMessageWithAttachments_data();
40
39
    void testSendMessageWithAttachments();
 
40
    void testSendMessageWithAttachmentsSplitted();
41
41
    void testAcknowledgeMessages();
42
42
 
43
43
private:
170
170
    QCOMPARE(receivedIds, messageIds);
171
171
}
172
172
 
173
 
void ChatManagerTest::testSendMessageWithAttachments_data()
174
 
{
175
 
    QTest::addColumn<QStringList>("recipients");
176
 
    QTest::addColumn<QString>("message");
177
 
    QTest::addColumn<QString>("accountId");
178
 
    QTest::addColumn<bool>("mmsFlag");
179
 
 
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;
182
 
 
183
 
}
184
 
 
185
173
void ChatManagerTest::testSendMessageWithAttachments()
186
174
{
187
 
    QFETCH(QStringList, recipients);
188
 
    QFETCH(QString, message);
189
 
    QFETCH(QString, accountId);
190
 
    QFETCH(bool, mmsFlag);
191
 
 
192
 
    // just to make it easier, sort the recipients
193
 
    qSort(recipients);
194
 
 
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");
 
178
 
 
179
    MockController *controller = mPhoneMockController;
196
180
 
197
181
    QSignalSpy controllerMessageSentSpy(controller, SIGNAL(MessageSent(QString,QVariantList,QVariantMap)));
198
182
 
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);
204
188
 
207
191
    ChatManager::instance()->sendMessage(accountId, message, attachments, properties);
208
192
 
209
193
    TRY_COMPARE(controllerMessageSentSpy.count(), 1);
 
194
 
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);
216
 
 
217
 
    QCOMPARE(messageProperties.contains("x-canonical-mms"), mmsFlag);
218
 
    QCOMPARE(messageProperties["x-canonical-mms"].toBool(), mmsFlag);
 
202
    QCOMPARE(messageAttachments.count(), attachmentList.count());
 
203
}
 
204
 
 
205
void ChatManagerTest::testSendMessageWithAttachmentsSplitted()
 
206
{
 
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");
 
211
 
 
212
    MockController *controller = mGenericMockController;
 
213
 
 
214
    QSignalSpy controllerMessageSentSpy(controller, SIGNAL(MessageSent(QString,QVariantList,QVariantMap)));
 
215
 
 
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);
 
221
 
 
222
    QVariantMap properties;
 
223
    properties["participantIds"] = recipients;
 
224
    ChatManager::instance()->sendMessage(accountId, message, attachments, properties);
 
225
 
 
226
    TRY_COMPARE(controllerMessageSentSpy.count(), attachmentList.count() + 1);
 
227
 
 
228
    QString messageText;
 
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()) {
 
241
            messageText = text;
 
242
        } else {
 
243
            QVariantList attachments = args[1].toList();
 
244
            // each message should contain no more than one attachment
 
245
            QCOMPARE(attachments.count(), 1);
 
246
            attachmentCount += 1;
 
247
        }
 
248
    }
 
249
    QCOMPARE(messageText, message);
 
250
    QCOMPARE(attachmentCount, attachmentList.count());
 
251
 
219
252
}
220
253
 
221
254
QTEST_MAIN(ChatManagerTest)