1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: : Main test class definition for MMS Plugin |
|
15 */ |
|
16 |
|
17 #include <QtTest/QtTest> |
|
18 #include <QTimer> |
|
19 #include <QSignalSpy> |
|
20 #include "debugtraces.h" |
|
21 #include "testmmsplugin.h" |
|
22 #include "convergedmessage.h" |
|
23 #include "convergedmessageid.h" |
|
24 #include "unieditormmsplugin.h" |
|
25 #include "mmstestbed.h" |
|
26 #include "testmmsplugin.ini" |
|
27 |
|
28 //--------------------------------------------------------------- |
|
29 // TestMmsPlugin::initTestCase |
|
30 //--------------------------------------------------------------- |
|
31 void TestMmsPlugin::initTestCase() |
|
32 { |
|
33 //Instantiate UniEditorMmsPlugin and verify if it is correctly Instantited. |
|
34 msgPlugin = new UniEditorMmsPlugin(); |
|
35 QVERIFY(msgPlugin != NULL); |
|
36 |
|
37 //Verify if MMS service is Validated. |
|
38 QCOMPARE(msgPlugin->validateService(), 1); |
|
39 QCOMPARE(msgPlugin->isServiceValid(), 1); |
|
40 msgPlugin->setEncodingSettings(ETrue, ESmsEncodingNone, -1); |
|
41 QString str("Hello"); |
|
42 TInt numOfRemainingChars = 1; |
|
43 TInt numOfPDUs = 1; |
|
44 TBool unicodeMode = ETrue; |
|
45 TSmsEncoding smsEncoding = ESmsEncodingNone; |
|
46 QVERIFY(msgPlugin->getNumPDUs(str, numOfRemainingChars, numOfPDUs, unicodeMode, smsEncoding) == true); |
|
47 |
|
48 //Verify MmsTestBed Instance. |
|
49 mmstestbed = new MmsTestBed; |
|
50 QVERIFY(mmstestbed != NULL); |
|
51 |
|
52 //register user defined object to meta system. |
|
53 qRegisterMetaType<long int> ("long int"); |
|
54 |
|
55 //set up signalspy to listen to signals emitted by mmstestbed |
|
56 spy_draft = new QSignalSpy(mmstestbed, SIGNAL(entryCreatedInDraft(long int))); |
|
57 spy_outbox = new QSignalSpy(mmstestbed, SIGNAL(entryMovedToOutbox(long int))); |
|
58 spy_sent = new QSignalSpy(mmstestbed, SIGNAL(entryMovedToSent(long int))); |
|
59 spy_inbox = new QSignalSpy(mmstestbed, SIGNAL(entryCreatedInInbox(long int))); |
|
60 } |
|
61 |
|
62 //--------------------------------------------------------------- |
|
63 // TestMmsPlugin::init |
|
64 //--------------------------------------------------------------- |
|
65 void TestMmsPlugin::init() |
|
66 { |
|
67 } |
|
68 |
|
69 //--------------------------------------------------------------- |
|
70 // TestMmsPlugin::createMMSWithTextAttachment |
|
71 //--------------------------------------------------------------- |
|
72 void TestMmsPlugin::createMMSWithTextAttachment() |
|
73 { |
|
74 //Create a Converged Message instance. |
|
75 QString subject = TEST_MSG_SUBJECT; |
|
76 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
77 |
|
78 QString sender(TEST_SENDER); |
|
79 ConvergedMessageAddress address(sender); |
|
80 ConvergedMessageAttachmentList attachmentList; |
|
81 |
|
82 //Add a text attachment to attachment list. |
|
83 QString attachmentPath = TEST_ATTACHMENT5; |
|
84 ConvergedMessageAttachment* attachment = |
|
85 new ConvergedMessageAttachment(attachmentPath, ConvergedMessageAttachment::EAttachment); |
|
86 |
|
87 attachmentList.append(attachment); |
|
88 |
|
89 //Instantiate a Converged Message object and set service a MMS |
|
90 ConvergedMessage msg; |
|
91 msg.setMessageType(ConvergedMessage::Mms); |
|
92 |
|
93 //Set Subject |
|
94 msg.setSubject(subject); |
|
95 |
|
96 msg.setTimeStamp(timeStamp); |
|
97 |
|
98 //Set recipient. |
|
99 msg.addToRecipient(address); |
|
100 |
|
101 //Add attachments' list |
|
102 msg.addAttachments(attachmentList); |
|
103 msg.setPriority(ConvergedMessage::Normal); |
|
104 |
|
105 //Adding CC Address |
|
106 QString ccAddress(TEST_CC); |
|
107 ConvergedMessageAddress ccAdd(ccAddress); |
|
108 msg.addCcRecipient(ccAdd); |
|
109 |
|
110 //Adding BCC Address |
|
111 QString bccAddress(TEST_BCC); |
|
112 ConvergedMessageAddress bccAdd(bccAddress); |
|
113 msg.addBccRecipient(bccAdd); |
|
114 |
|
115 //Adding From Address |
|
116 QString recipientAddress(TEST_SENDER); |
|
117 ConvergedMessageAddress recipientAdd(recipientAddress); |
|
118 msg.addFromRecipient(recipientAdd); |
|
119 |
|
120 //start send and prepare to test send-success or fail |
|
121 mmstestbed->cleanAll(); |
|
122 mmstestbed->setConnectionLocal(true); |
|
123 |
|
124 //Get a valid MMS message ID and verify that it is valid. |
|
125 mmsMsgId = msgPlugin->convertTo(&msg); |
|
126 QVERIFY(mmsMsgId != -1); |
|
127 } |
|
128 |
|
129 //--------------------------------------------------------------- |
|
130 // TestMmsPlugin::testMMSWithTextAttachment |
|
131 //--------------------------------------------------------------- |
|
132 void TestMmsPlugin::testMMSWithTextAttachment() |
|
133 { |
|
134 long int mmsDraftMsgId; |
|
135 |
|
136 //check if draft-folder signal was received...this means message was created in draft |
|
137 if( 1 <= spy_draft->count()) |
|
138 { |
|
139 //compare the msgid and verify with the ID given by MMS plugin |
|
140 void * temp = const_cast<void*>(spy_draft->at(0).at(0).data()); |
|
141 mmsDraftMsgId = *reinterpret_cast< long int(*)>(temp); |
|
142 QVERIFY(mmsDraftMsgId == mmsMsgId); |
|
143 |
|
144 //Validate the MMS message with all the values set before. |
|
145 ConvergedMessage* draftMsg = msgPlugin->convertFrom(mmsDraftMsgId); |
|
146 QVERIFY(draftMsg->subject().compare(QString(TEST_MSG_SUBJECT)) == 0); |
|
147 QVERIFY(draftMsg->messageType() == ConvergedMessage::Mms); |
|
148 QVERIFY(QString(TEST_SENDER).contains(draftMsg->toAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
149 QVERIFY(QString(TEST_CC).contains(draftMsg->ccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
150 QVERIFY(QString(TEST_BCC).contains(draftMsg->bccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
151 QVERIFY(QString(TEST_SENDER).contains(draftMsg->fromAddress()->address(), Qt::CaseInsensitive) == true); |
|
152 QVERIFY(draftMsg->attachments().count() == 1); |
|
153 QVERIFY(draftMsg->attachments()[0]->attachmentType() == ConvergedMessageAttachment::EAttachment); |
|
154 QVERIFY(draftMsg->attachments()[0]->filePath().contains(QString(TEST_ATTACHMENT5).mid(QString(TEST_ATTACHMENT5).indexOf(QString("Sample.txt"), 0, Qt::CaseInsensitive)), Qt::CaseInsensitive) == true); |
|
155 } |
|
156 else |
|
157 { |
|
158 QFAIL("testSendReceiveMMS: Failed to create message in Draft"); |
|
159 //reset connection to 'global on, local off' |
|
160 mmstestbed->setConnectionLocal(false); |
|
161 } |
|
162 } |
|
163 |
|
164 //--------------------------------------------------------------- |
|
165 // TestMmsPlugin::sendMMSWithTextAttachment |
|
166 //--------------------------------------------------------------- |
|
167 void TestMmsPlugin::sendMMSWithTextAttachment() |
|
168 { |
|
169 //Send the MMS message and verify if it was sent successfully. |
|
170 bool sent = msgPlugin->send(mmsMsgId); |
|
171 QVERIFY(sent == true); |
|
172 } |
|
173 |
|
174 //--------------------------------------------------------------- |
|
175 // TestMmsPlugin::testSentMMSWithTextAttachment |
|
176 //--------------------------------------------------------------- |
|
177 void TestMmsPlugin::testSentMMSWithTextAttachment() |
|
178 { |
|
179 QTest::qWait(10000); //to ensure path completion |
|
180 |
|
181 //check if outbox-folder signal was received...this means message was moved to outbox for send |
|
182 if( 1 <= spy_outbox->count()) |
|
183 { |
|
184 //compare the msgid |
|
185 void * temp = const_cast<void*>(spy_outbox->at(0).at(0).data()); |
|
186 long int outboxId = *reinterpret_cast< long int(*)>(temp); |
|
187 QCOMPARE(outboxId, mmsMsgId); |
|
188 |
|
189 //push the message from outbox to mmsc(sent folder) |
|
190 mmstestbed->fromOutboxToMmsc(); |
|
191 } |
|
192 else |
|
193 { |
|
194 QFAIL("testSendReceiveMMS: Failed to move message to Outbox"); |
|
195 |
|
196 //reset connection to 'global on, local off' |
|
197 mmstestbed->setConnectionLocal(false); |
|
198 return; |
|
199 } |
|
200 |
|
201 //check if sent-folder signal was received....this means message was successfully sent scheduled. |
|
202 if( 1 <= spy_sent->count()) |
|
203 { |
|
204 //check for send-path |
|
205 void * temp = const_cast<void*>(spy_sent->at(0).at(0).data()); |
|
206 long int sentmsgid = *reinterpret_cast< long int(*)>(temp); |
|
207 QCOMPARE(sentmsgid, mmsMsgId); |
|
208 |
|
209 //issue a fetch request on the sent message, to test the receive path |
|
210 mmstestbed->fromMmscToInbox(); |
|
211 } |
|
212 else |
|
213 { |
|
214 QFAIL("testSendReceiveMMS: Failed to move message to Sent folder"); |
|
215 |
|
216 //reset connection to 'global on, local off' |
|
217 mmstestbed->setConnectionLocal(false); |
|
218 return; |
|
219 } |
|
220 |
|
221 //check if inbox-folder signal was received....this means message was successfully received at the inbox folder. |
|
222 if( spy_inbox->count() <= 0) |
|
223 { |
|
224 QFAIL("testSendReceiveMMS: Failed to move message to Inbox folder"); |
|
225 |
|
226 //reset connection to 'global on, local off' |
|
227 mmstestbed->setConnectionLocal(false); |
|
228 } |
|
229 } |
|
230 |
|
231 //--------------------------------------------------------------- |
|
232 // TestMmsPlugin::createMMSWithTextAndImageAttachment |
|
233 //--------------------------------------------------------------- |
|
234 void TestMmsPlugin::createMMSWithTextAndImageAttachment() |
|
235 { |
|
236 //Create a Converged Message instance. |
|
237 QString subject = TEST_MSG_SUBJECT; |
|
238 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
239 |
|
240 QString sender(TEST_SENDER); |
|
241 ConvergedMessageAddress address(sender); |
|
242 ConvergedMessageAttachmentList attachmentList; |
|
243 |
|
244 //Add a text attachment to attachment list. |
|
245 QString attachmentPath1 = TEST_ATTACHMENT5; |
|
246 ConvergedMessageAttachment* attachment = |
|
247 new ConvergedMessageAttachment(attachmentPath1, ConvergedMessageAttachment::EInline); |
|
248 |
|
249 //Add an image attachment to attachment list. |
|
250 QString attachmentPath2 = TEST_ATTACHMENT4; |
|
251 ConvergedMessageAttachment* attachmentImage = |
|
252 new ConvergedMessageAttachment(attachmentPath2, ConvergedMessageAttachment::EAttachment); |
|
253 |
|
254 attachmentList.append(attachment); |
|
255 attachmentList.append(attachmentImage); |
|
256 |
|
257 //Instantiate a Converged Message object and set service a MMS |
|
258 ConvergedMessage msg; |
|
259 msg.setMessageType(ConvergedMessage::Mms); |
|
260 msg.setSubject(subject); |
|
261 msg.setTimeStamp(timeStamp); |
|
262 msg.addToRecipient(address); |
|
263 |
|
264 //Add attachments' list |
|
265 msg.addAttachments(attachmentList); |
|
266 msg.setPriority(ConvergedMessage::Normal); |
|
267 |
|
268 //Adding CC Address |
|
269 QString ccAddress(TEST_CC); |
|
270 ConvergedMessageAddress ccAdd(ccAddress); |
|
271 msg.addCcRecipient(ccAdd); |
|
272 |
|
273 //Adding BCC Address |
|
274 QString bccAddress(TEST_BCC); |
|
275 ConvergedMessageAddress bccAdd(bccAddress); |
|
276 msg.addBccRecipient(bccAdd); |
|
277 |
|
278 //Adding From Address |
|
279 QString recipientAddress(TEST_SENDER); |
|
280 ConvergedMessageAddress recipientAdd(recipientAddress); |
|
281 msg.addFromRecipient(recipientAdd); |
|
282 |
|
283 //start send and prepare to test send-success or fail |
|
284 mmstestbed->cleanAll(); |
|
285 mmstestbed->setConnectionLocal(true); |
|
286 |
|
287 //Get a valid MMS message ID and verify that it is valid. |
|
288 mmsMsgId = msgPlugin->convertTo(&msg); |
|
289 QVERIFY(mmsMsgId != -1); |
|
290 } |
|
291 |
|
292 //--------------------------------------------------------------- |
|
293 // TestMmsPlugin::testMMSWithTextAndImageAttachment |
|
294 //--------------------------------------------------------------- |
|
295 void TestMmsPlugin::testMMSWithTextAndImageAttachment() |
|
296 { |
|
297 long int mmsDraftMsgId; |
|
298 |
|
299 //check if draft-folder signal was received...this means message was created in draft |
|
300 if( 1 <= spy_draft->count()) |
|
301 { |
|
302 //compare the msgid and verify with the ID given by MMS plugin |
|
303 void * temp = const_cast<void*>(spy_draft->at(1).at(0).data()); |
|
304 mmsDraftMsgId = *reinterpret_cast< long int(*)>(temp); |
|
305 QVERIFY(mmsDraftMsgId == mmsMsgId); |
|
306 |
|
307 //Validate the MMS message with all the values set before. |
|
308 ConvergedMessage* draftMsg = msgPlugin->convertFrom(mmsDraftMsgId); |
|
309 QVERIFY(draftMsg->subject().compare(QString(TEST_MSG_SUBJECT)) == 0); |
|
310 QVERIFY(draftMsg->messageType() == ConvergedMessage::Mms); |
|
311 QVERIFY(QString(TEST_SENDER).contains(draftMsg->toAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
312 QVERIFY(QString(TEST_CC).contains(draftMsg->ccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
313 QVERIFY(QString(TEST_BCC).contains(draftMsg->bccAddressList()[0]->address(), Qt::CaseInsensitive) == true); |
|
314 QVERIFY(QString(TEST_SENDER).contains(draftMsg->fromAddress()->address(), Qt::CaseInsensitive) == true); |
|
315 QVERIFY(draftMsg->attachments().count() == 1); |
|
316 QVERIFY(draftMsg->attachments()[0]->attachmentType() == ConvergedMessageAttachment::EAttachment); |
|
317 QVERIFY(draftMsg->attachments()[0]->filePath().contains(QString(TEST_ATTACHMENT4).mid(QString(TEST_ATTACHMENT4).indexOf(QString("SmileyFace.gif"), 0, Qt::CaseInsensitive)), Qt::CaseInsensitive) == true); |
|
318 } |
|
319 else |
|
320 { |
|
321 QFAIL("testSendReceiveMMS: Failed to create message in Draft"); |
|
322 //reset connection to 'global on, local off' |
|
323 mmstestbed->setConnectionLocal(false); |
|
324 } |
|
325 } |
|
326 |
|
327 //--------------------------------------------------------------- |
|
328 // TestMmsPlugin::sendMMSWithTextAndImageAttachment |
|
329 //--------------------------------------------------------------- |
|
330 void TestMmsPlugin::sendMMSWithTextAndImageAttachment() |
|
331 { |
|
332 //Send the MMS message and verify if it was sent successfully. |
|
333 bool sent = msgPlugin->send(mmsMsgId); |
|
334 QVERIFY(sent == true); |
|
335 } |
|
336 |
|
337 //--------------------------------------------------------------- |
|
338 // TestMmsPlugin::testSentMMSWithTextAndImageAttachment |
|
339 //--------------------------------------------------------------- |
|
340 void TestMmsPlugin::testSentMMSWithTextAndImageAttachment() |
|
341 { |
|
342 QTest::qWait(10000); //to ensure path completion |
|
343 |
|
344 //check if outbox-folder signal was received...this means message was moved to outbox for send |
|
345 if( 1 <= spy_outbox->count()) |
|
346 { |
|
347 //compare the msgid |
|
348 void * temp = const_cast<void*>(spy_outbox->at(1).at(0).data()); |
|
349 long int outboxId = *reinterpret_cast< long int(*)>(temp); |
|
350 QCOMPARE(outboxId, mmsMsgId); |
|
351 |
|
352 //push the message from outbox to mmsc(sent folder) |
|
353 mmstestbed->fromOutboxToMmsc(); |
|
354 } |
|
355 else |
|
356 { |
|
357 QFAIL("testSendReceiveMMS: Failed to move message to Outbox"); |
|
358 |
|
359 //reset connection to 'global on, local off' |
|
360 mmstestbed->setConnectionLocal(false); |
|
361 return; |
|
362 } |
|
363 |
|
364 //check if sent-folder signal was received....this means message was successfully sent scheduled. |
|
365 if( 1 <= spy_sent->count()) |
|
366 { |
|
367 //check for send-path |
|
368 void * temp = const_cast<void*>(spy_sent->at(1).at(0).data()); |
|
369 long int sentmsgid = *reinterpret_cast< long int(*)>(temp); |
|
370 QCOMPARE(sentmsgid, mmsMsgId); |
|
371 |
|
372 //issue a fetch request on the sent message, to test the receive path |
|
373 mmstestbed->fromMmscToInbox(); |
|
374 } |
|
375 else |
|
376 { |
|
377 QFAIL("testSendReceiveMMS: Failed to move message to Sent folder"); |
|
378 |
|
379 //reset connection to 'global on, local off' |
|
380 mmstestbed->setConnectionLocal(false); |
|
381 return; |
|
382 } |
|
383 |
|
384 //check if inbox-folder signal was received....this means message was successfully received at the inbox folder. |
|
385 if( spy_inbox->count() <= 0) |
|
386 { |
|
387 QFAIL("testSendReceiveMMS: Failed to move message to Inbox folder"); |
|
388 |
|
389 //reset connection to 'global on, local off' |
|
390 mmstestbed->setConnectionLocal(false); |
|
391 } |
|
392 } |
|
393 |
|
394 //--------------------------------------------------------------- |
|
395 // TestMmsPlugin::cleanup |
|
396 //--------------------------------------------------------------- |
|
397 void TestMmsPlugin::cleanup() |
|
398 { |
|
399 } |
|
400 |
|
401 //--------------------------------------------------------------- |
|
402 // TestMmsPlugin::cleanupTestCase |
|
403 //--------------------------------------------------------------- |
|
404 void TestMmsPlugin::cleanupTestCase() |
|
405 { |
|
406 //Cleanup |
|
407 delete spy_draft;//Signal for Draft Folder |
|
408 delete spy_outbox;//Signal for Outbox Folder |
|
409 delete spy_sent;//Signal for Sent Folder |
|
410 delete spy_inbox;//Signal for inbox Folder |
|
411 delete msgPlugin;//MMS Plugin |
|
412 delete mmstestbed;//MMS Testbed |
|
413 } |
|
414 |
|
415 //End of File |
|