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: |
|
15 */ |
|
16 |
|
17 #include "testmmsplugin.h" |
|
18 #include <QtTest/QtTest> |
|
19 #include "debugtraces.h" |
|
20 |
|
21 #include <QTimer> |
|
22 #include <QSignalSpy> |
|
23 |
|
24 #include "convergedmessage.h" |
|
25 #include "TestMsg.h" |
|
26 #include "convergedmessageid.h" |
|
27 #include "unieditormmsplugin.h" |
|
28 #include "messageserviceaction.h" |
|
29 //--------------------------------------------------------------- |
|
30 // TestMmsPlugin::initTestCase |
|
31 //--------------------------------------------------------------- |
|
32 void TestMmsPlugin::initTestCase() |
|
33 { |
|
34 msgPlugin = new UniEditorMmsPlugin(); |
|
35 QVERIFY(msgPlugin != 0); |
|
36 smsId = -1; |
|
37 mmsId = -1; |
|
38 } |
|
39 |
|
40 //--------------------------------------------------------------- |
|
41 // TestMmsPlugin::cleanupTestCase |
|
42 //--------------------------------------------------------------- |
|
43 void TestMmsPlugin::cleanupTestCase() |
|
44 { |
|
45 delete msgPlugin; |
|
46 } |
|
47 |
|
48 //--------------------------------------------------------------- |
|
49 // TestMmsPlugin::init |
|
50 //--------------------------------------------------------------- |
|
51 |
|
52 void TestMmsPlugin::init() |
|
53 { |
|
54 } |
|
55 |
|
56 //--------------------------------------------------------------- |
|
57 // TestMmsPlugin::cleanup |
|
58 //--------------------------------------------------------------- |
|
59 void TestMmsPlugin::cleanup() |
|
60 { |
|
61 } |
|
62 |
|
63 //--------------------------------------------------------------- |
|
64 // TestMmsPlugin::testSendMMS |
|
65 //--------------------------------------------------------------- |
|
66 |
|
67 void TestMmsPlugin::testSendMMS() |
|
68 { |
|
69 |
|
70 //register user defined object to meta system. |
|
71 qRegisterMetaType<ConvergedMessage*> ("ConvergedMessage*"); |
|
72 |
|
73 |
|
74 createMMSMessageWithAttachmentAndSend(); |
|
75 //wait for the response to complete |
|
76 //as sending a message goes through different stages |
|
77 |
|
78 //Create a smil attachment with image and text |
|
79 createMMSMessageWithSmilTextAndImageAttachmentAndSend(); |
|
80 |
|
81 //Create MMS with Normal priority |
|
82 createMMSMessageWithAttachmentAndSend(ETrue); |
|
83 } |
|
84 |
|
85 |
|
86 void TestMmsPlugin::createMMSMessageWithSmilTextAndImageAttachmentAndSend() |
|
87 { |
|
88 QString service = TEST_SERVICE_NAME_MMS; |
|
89 QString bodyText = TEST_MSG_BODY; |
|
90 QString subject = TEST_MSG_SUBJECT; |
|
91 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
92 |
|
93 QString sender(TEST_SENDER); |
|
94 ConvergedMessageAddress address(sender); |
|
95 ConvergedMessageAttachmentList attachmentList; |
|
96 |
|
97 ConvergedMessageAttachment* attachmentImage = |
|
98 new ConvergedMessageAttachment(TEST_ATTACHMENT4, ConvergedMessageAttachment::EAttachment); |
|
99 attachmentList.append(attachmentImage); |
|
100 |
|
101 ConvergedMessageAttachment* attachmenttext = |
|
102 new ConvergedMessageAttachment(TEST_ATTACHMENT5, ConvergedMessageAttachment::EAttachment); |
|
103 attachmentList.append(attachmenttext); |
|
104 |
|
105 ConvergedMessageAttachment* attachmentSmil = |
|
106 new ConvergedMessageAttachment(TEST_ATTACHMENT3, ConvergedMessageAttachment::ESmil); |
|
107 attachmentList.append(attachmentSmil); |
|
108 |
|
109 |
|
110 |
|
111 ConvergedMessage msg; |
|
112 msg.setMessageType(ConvergedMessage::Mms); |
|
113 msg.setSubject(subject); |
|
114 msg.setTimeStamp(timeStamp); |
|
115 msg.addToRecipient(address); |
|
116 msg.addAttachments(attachmentList); |
|
117 msg.setPriority(ConvergedMessage::Low); |
|
118 |
|
119 long int id = msgPlugin->convertTo(&msg); |
|
120 msgPlugin->send(id); |
|
121 |
|
122 } |
|
123 |
|
124 |
|
125 //--------------------------------------------------------------- |
|
126 // TestMmsPlugin::testMmsReceived |
|
127 //--------------------------------------------------------------- |
|
128 void TestMmsPlugin::testMmsReceived() |
|
129 { |
|
130 testReceived(msgPlugin->messageType()); |
|
131 QTest::qWait(5000); |
|
132 } |
|
133 |
|
134 /* |
|
135 * Creates a Smil file with only a text document as attachment |
|
136 */ |
|
137 |
|
138 void TestMmsPlugin::createMMSMessageWithAttachmentAndSend(TBool priority) |
|
139 { |
|
140 QString service = TEST_SERVICE_NAME_MMS; |
|
141 QString bodyText = TEST_MSG_BODY; |
|
142 QString subject = TEST_MSG_SUBJECT; |
|
143 qint64 timeStamp = QDateTime::currentDateTime().toTime_t(); |
|
144 |
|
145 QString sender(TEST_SENDER); |
|
146 ConvergedMessageAddress address(sender); |
|
147 ConvergedMessageAttachmentList attachmentList; |
|
148 |
|
149 |
|
150 ConvergedMessageAttachment* attachment2 = |
|
151 new ConvergedMessageAttachment(TEST_ATTACHMENT2, ConvergedMessageAttachment::ESmil); |
|
152 |
|
153 ConvergedMessageAttachment* attachment = |
|
154 new ConvergedMessageAttachment(TEST_ATTACHMENT, ConvergedMessageAttachment::EAttachment); |
|
155 |
|
156 attachmentList.append(attachment); |
|
157 |
|
158 attachmentList.append(attachment2); |
|
159 |
|
160 ConvergedMessage msg; |
|
161 msg.setMessageType(ConvergedMessage::Mms); |
|
162 msg.setSubject(subject); |
|
163 msg.setTimeStamp(timeStamp); |
|
164 msg.addToRecipient(address); |
|
165 msg.addAttachments(attachmentList); |
|
166 if(priority == EFalse) |
|
167 { |
|
168 msg.setPriority(ConvergedMessage::Normal); |
|
169 } |
|
170 else |
|
171 { |
|
172 msg.setPriority(ConvergedMessage::High); |
|
173 } |
|
174 |
|
175 //Adding alias |
|
176 ConvergedMessageAddress address1; |
|
177 address1.setAlias(QString(TEST_MSG_RECIEPIENT)); |
|
178 msg.addToRecipient(address1); |
|
179 |
|
180 //Adding CC Address |
|
181 QString ccAddress(TEST_CC); |
|
182 ConvergedMessageAddress ccAdd(ccAddress); |
|
183 msg.addCcRecipient(ccAdd); |
|
184 |
|
185 //Adding BCC Address |
|
186 QString bccAddress(TEST_BCC); |
|
187 ConvergedMessageAddress bccAdd(bccAddress); |
|
188 msg.addBccRecipient(bccAdd); |
|
189 |
|
190 long int id = msgPlugin->convertTo(&msg); |
|
191 msgPlugin->send(id); |
|
192 } |
|
193 |
|
194 //--------------------------------------------------------------- |
|
195 // TestMmsPlugin::testReceived |
|
196 //--------------------------------------------------------------- |
|
197 void TestMmsPlugin::testReceived(int type) |
|
198 { |
|
199 MessageServiceAction* messageAction = new MessageServiceAction(this); |
|
200 QVERIFY(messageAction != 0); |
|
201 |
|
202 //register user defined object to meta system. |
|
203 qRegisterMetaType<ConvergedMessage*>("ConvergedMessage*"); |
|
204 |
|
205 //signal spy. |
|
206 //listen to added event |
|
207 QSignalSpy spyAdd( messageAction, |
|
208 SIGNAL(messageAdded(ConvergedMessage*, QString))); |
|
209 //signal spy. |
|
210 //listen to updated event |
|
211 QSignalSpy spyUpdate( messageAction, |
|
212 SIGNAL(messageUpdated(ConvergedMessage*, QString))); |
|
213 //will force stub_clientmanager to emit messageUpdated. |
|
214 messageAction->registerForNotification(); |
|
215 //register user defined object to meta system. |
|
216 |
|
217 // wait for the response to come |
|
218 QTest::qWait(5000); |
|
219 |
|
220 //check signals |
|
221 int countAdd = -1; |
|
222 countAdd = spyAdd.count(); |
|
223 |
|
224 ConvergedMessage* message = 0; |
|
225 QString serviceId(""); |
|
226 |
|
227 if (countAdd) |
|
228 { |
|
229 //verify added event |
|
230 void * temp = const_cast<void*> (spyAdd.at(0).at(0).data()); |
|
231 message = *reinterpret_cast<ConvergedMessage*(*)> (temp); |
|
232 serviceId = spyAdd.at(0).at(1).toString(); |
|
233 QVERIFY(message != 0); |
|
234 validateMsg(*message, serviceId); |
|
235 } |
|
236 |
|
237 int countUpdate = -1; |
|
238 countUpdate = spyUpdate.count(); |
|
239 message = 0; |
|
240 |
|
241 for (int i = countUpdate; i > 0; --i) |
|
242 { |
|
243 //verify updated event |
|
244 void * temp = const_cast<void*> (spyUpdate.at(i-1).at(0).data()); |
|
245 message = *reinterpret_cast<ConvergedMessage*(*)> (temp); |
|
246 if (ConvergedMessage::Inbox == message->location()) |
|
247 { |
|
248 serviceId = spyUpdate.at(i-1).at(1).toString(); |
|
249 break; |
|
250 } |
|
251 } |
|
252 if (message) |
|
253 { |
|
254 validateMsg(*message, serviceId); |
|
255 } |
|
256 delete message; |
|
257 } |
|
258 |
|
259 //--------------------------------------------------------------- |
|
260 // TestMmsPlugin::validateMsg |
|
261 //--------------------------------------------------------------- |
|
262 void TestMmsPlugin::validateMsg(const ConvergedMessage& message, |
|
263 const QString& serviceId) |
|
264 { |
|
265 #ifdef _DEBUG_TRACES_ |
|
266 qDebug() << "....message received....."; |
|
267 #endif |
|
268 |
|
269 //process incoming messages |
|
270 if (message.location() == ConvergedMessage::Inbox) |
|
271 { |
|
272 int msgId; |
|
273 if (message.id()) |
|
274 { |
|
275 msgId = message.id()->getId(); |
|
276 } |
|
277 ConvergedMessageAddressList array = message.toAddressList(); |
|
278 if (array.count() > 0) |
|
279 { |
|
280 if (array[0]) |
|
281 QCOMPARE(array[0]->address(),QString(TEST_MSG_FROM1)); |
|
282 } |
|
283 ConvergedMessageAddress *fromAddr = message.fromAddress(); |
|
284 if (fromAddr) |
|
285 { |
|
286 QCOMPARE(fromAddr->address(),QString(TEST_MSG_FROM1)); |
|
287 } |
|
288 |
|
289 QCOMPARE(serviceId,QString(TEST_SERVICE_ID)); |
|
290 |
|
291 if (message.messageType() == ConvergedMessage::Mms) |
|
292 { |
|
293 mmsId = msgId; |
|
294 QCOMPARE(message.subject(), QString(TEST_MSG_SUBJECT)); |
|
295 } |
|
296 else if (message.messageType() == ConvergedMessage::Sms) |
|
297 { |
|
298 smsId = msgId; |
|
299 QCOMPARE(message.bodyText(), QString(TEST_MSG_BODY)); |
|
300 } |
|
301 } |
|
302 else if (message.location() == ConvergedMessage::Sent) |
|
303 { |
|
304 ConvergedMessageAddressList array = message.toAddressList(); |
|
305 if (array.count() > 0) |
|
306 { |
|
307 if (array[0]) |
|
308 QCOMPARE(array[0]->address(),QString(TEST_SENDER)); |
|
309 } |
|
310 |
|
311 // QCOMPARE(serviceId,QString(TEST_SERVICE_ID)); |
|
312 |
|
313 if (message.messageType() == ConvergedMessage::Mms) |
|
314 { |
|
315 QCOMPARE(message.subject(), QString(TEST_MSG_SUBJECT)); |
|
316 } |
|
317 else if (message.messageType() == ConvergedMessage::Sms) |
|
318 { |
|
319 QCOMPARE(message.bodyText(), QString(TEST_MSG_BODY)); |
|
320 } |
|
321 } |
|
322 } |
|