|
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 Data Plugin |
|
15 */ |
|
16 |
|
17 #include <QtTest/QtTest> |
|
18 #include <QtDebug> |
|
19 #include <QTimer> |
|
20 #include <QSignalSpy> |
|
21 #include <mmsclient.h> |
|
22 #include <mmssettings.h> |
|
23 #include <CMsvMimeHeaders.h> |
|
24 #include <f32file.h> |
|
25 #include "debugtraces.h" |
|
26 #include "convergedmessageaddress.h" |
|
27 #include "testunidatamodelmmsplugin.h" |
|
28 #include "testunidatamodelmmsplugin.ini" |
|
29 #include "xqconversions.h" |
|
30 #include "unidatamodelplugininterface.h" |
|
31 #include "unidatamodelloader.h" |
|
32 |
|
33 //--------------------------------------------------------------- |
|
34 // TestUniDataModelPlugin::initTestCase |
|
35 //--------------------------------------------------------------- |
|
36 void TestUniDataModelMMSPlugin::initTestCase() |
|
37 { |
|
38 iObserver = new (ELeave) TestObserverMMS(); |
|
39 |
|
40 // Create a new messaging server session.. |
|
41 TRAPD(err,iMSession = CMsvSession::OpenSyncL(*iObserver)); |
|
42 if(err) |
|
43 { |
|
44 TInt x = err; |
|
45 } |
|
46 |
|
47 // Create the client mtm registry |
|
48 CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL(*iMSession); |
|
49 |
|
50 // Get the MMS clientmtm |
|
51 iMmsClientMtm = static_cast<CMmsClientMtm*> (mtmReg->NewMtmL(KUidMsgTypeMultimedia)); |
|
52 |
|
53 //Connecting to File Server Session |
|
54 User::LeaveIfError( iFs.Connect() ); |
|
55 iFs.SetSessionPath( KRootPath ); |
|
56 |
|
57 //Getting Service ID for MMS |
|
58 CMmsSettings* settings = CMmsSettings::NewL(); |
|
59 settings->LoadSettingsL(); |
|
60 iServiceId = settings->Service(); |
|
61 |
|
62 iMessageId = 0; |
|
63 |
|
64 //Saving the Timestamp before Message is created |
|
65 retTimeStamp = QDateTime::currentDateTime(); |
|
66 |
|
67 // Get the MMS data modelplugin |
|
68 pluginLoader = new UniDataModelLoader; |
|
69 pluginInterface = pluginLoader->getDataModelPlugin(ConvergedMessage::Mms); |
|
70 } |
|
71 |
|
72 //--------------------------------------------------------------- |
|
73 // TestUniDataModelPlugin::init |
|
74 //--------------------------------------------------------------- |
|
75 void TestUniDataModelMMSPlugin::init() |
|
76 { |
|
77 } |
|
78 |
|
79 //--------------------------------------------------------------- |
|
80 // TestUniDataModelPlugin::testInboxMessage |
|
81 //--------------------------------------------------------------- |
|
82 void TestUniDataModelMMSPlugin::testInboxMessage() |
|
83 { |
|
84 //Create the MMS First |
|
85 createMMS(KMsvGlobalInBoxIndexEntryIdValue,ETrue); |
|
86 |
|
87 QTest::qWait(50000); //to ensure path completion |
|
88 |
|
89 //MMS Message created, will now be validated |
|
90 |
|
91 //Checking if Another Instance of MMS Data Plugin can be created form an existing one |
|
92 QObject* anotherInstance = pluginInterface->createInstance(); |
|
93 QVERIFY(anotherInstance != NULL); |
|
94 delete anotherInstance; |
|
95 |
|
96 //Setting a Message ID, thereby populating the MMS message at the Plugin |
|
97 QVERIFY(pluginInterface->setMessageId(iMessageId) == KErrNone); |
|
98 |
|
99 //Verifying the MMS message size |
|
100 QVERIFY(pluginInterface->messageSize() == msgSize); |
|
101 |
|
102 //Verifying the MMS timestamp |
|
103 QVERIFY(pluginInterface->timeStamp() == retTimeStamp); |
|
104 |
|
105 //Verifying is the MMP Plugin works file afetr it has been Reset and Restored |
|
106 pluginInterface->reset(); |
|
107 pluginInterface->restore(*iMmsClientMtm); |
|
108 QVERIFY(pluginInterface->setMessageId(iMessageId) == KErrNone); |
|
109 |
|
110 //Subject Verification |
|
111 QVERIFY(pluginInterface->subject().compare(QString(TEST_MSG_SUBJECT)) == 0); |
|
112 |
|
113 //MMS message have no Body String |
|
114 QString body; |
|
115 pluginInterface->body(body); |
|
116 QVERIFY(body == QString("")); |
|
117 |
|
118 //Message type verification |
|
119 QVERIFY(pluginInterface->messageType().compare(QString("mms")) == 0); |
|
120 |
|
121 //Fetch the To List |
|
122 ConvergedMessageAddressList recipientList; |
|
123 pluginInterface->toRecipientList(recipientList); |
|
124 QVERIFY(recipientList.count() != 0); |
|
125 QVERIFY(recipientList[0]->address().compare(QString(TEST_MSG_RECIEPIENT1)) == 0); |
|
126 |
|
127 //Fetch the CC List |
|
128 ConvergedMessageAddressList recipientList2; |
|
129 pluginInterface->ccRecipientList(recipientList2); |
|
130 QVERIFY(recipientList2.count() != 0); |
|
131 QVERIFY(recipientList2[0]->address().compare(QString(TEST_MSG_RECIEPIENT2)) == 0); |
|
132 |
|
133 //Fetch the BCC List |
|
134 ConvergedMessageAddressList recipientList3; |
|
135 pluginInterface->bccRecipientList(recipientList3); |
|
136 QVERIFY(recipientList3.count() != 0); |
|
137 QVERIFY(recipientList3[0]->address().compare(QString(TEST_MSG_RECIEPIENT3)) == 0); |
|
138 |
|
139 //Fetch the From Address |
|
140 QString recepient(TEST_MSG_FROM1); |
|
141 QString fromaddress; |
|
142 pluginInterface->fromAddress(fromaddress); |
|
143 QVERIFY(recepient == fromaddress); |
|
144 |
|
145 //Verifying Attachments |
|
146 UniMessageInfoList attList = pluginInterface->attachmentList(); |
|
147 QVERIFY(attList.count() == 0); |
|
148 |
|
149 QVERIFY(pluginInterface->hasAttachment() == false); |
|
150 |
|
151 QVERIFY(pluginInterface->attachmentCount() == 0); |
|
152 |
|
153 QVERIFY(pluginInterface->messagePriority() == 1); |
|
154 |
|
155 //Verifying various objects added to the MMS Message during creation |
|
156 QVERIFY(pluginInterface->objectCount() == 2); |
|
157 |
|
158 UniMessageInfoList objectlist = pluginInterface->objectList(); |
|
159 QVERIFY(!objectlist.isEmpty()); |
|
160 |
|
161 QVERIFY(objectlist[1]->path().contains(QString("TestUnidataModelMMSPluginPhoto.jpg"), Qt::CaseInsensitive) == true); |
|
162 QVERIFY(objectlist[1]->mimetype().contains(QString("image/jpeg"), Qt::CaseInsensitive) == true); |
|
163 |
|
164 QVERIFY(pluginInterface->slideCount() == 1); |
|
165 |
|
166 QVERIFY(pluginInterface->slideContent(0)[0]->path().contains(QString("Story.txt"), Qt::CaseInsensitive) == true); |
|
167 QVERIFY(pluginInterface->slideContent(0)[0]->mimetype().contains(QString("text/plain"), Qt::CaseInsensitive) == true); |
|
168 |
|
169 //Verifying if the plugin returns the correct session, thus will correctly delete the MMS we just created |
|
170 CMsvSession* msvSession = pluginInterface->session(); |
|
171 QVERIFY(msvSession != NULL); |
|
172 msvSession->RemoveEntry(iMessageId); |
|
173 |
|
174 qDebug() << "Verified Test MMS Successfully"; |
|
175 } |
|
176 |
|
177 //--------------------------------------------------------------- |
|
178 // TestUniDataModelPlugin::cleanup |
|
179 //--------------------------------------------------------------- |
|
180 void TestUniDataModelMMSPlugin::cleanup() |
|
181 { |
|
182 } |
|
183 |
|
184 //--------------------------------------------------------------- |
|
185 // TestUniDataModelPlugin::cleanupTestCase |
|
186 //--------------------------------------------------------------- |
|
187 void TestUniDataModelMMSPlugin::cleanupTestCase() |
|
188 { |
|
189 //Cleanup |
|
190 delete pluginInterface; |
|
191 delete pluginLoader; |
|
192 delete iMmsClientMtm; |
|
193 delete iMSession; |
|
194 delete iObserver; |
|
195 } |
|
196 |
|
197 //--------------------------------------------------------------- |
|
198 // TestUniDataModelPlugin::createMMS |
|
199 //--------------------------------------------------------------- |
|
200 void TestUniDataModelMMSPlugin::createMMS(TMsvId pId, TBool subjectField) |
|
201 { |
|
202 TMsvEntry indexEntry; |
|
203 indexEntry.iType = KUidMsvMessageEntry; |
|
204 indexEntry.iMtm = KUidMsgTypeMultimedia; |
|
205 indexEntry.iServiceId = iServiceId; |
|
206 indexEntry.iDate.HomeTime(); |
|
207 |
|
208 // Convert TTime to QDateTime , this will be used for comparing the time of mesage |
|
209 // when fetched from datamodel |
|
210 TTime unixEpoch(KUnixEpoch); |
|
211 TTimeIntervalSeconds seconds; |
|
212 TTime timeStamp = indexEntry.iDate; |
|
213 timeStamp.SecondsFrom(unixEpoch, seconds); |
|
214 retTimeStamp.setTime_t(seconds.Int()); |
|
215 |
|
216 TMsvId parentId = pId; |
|
217 CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering()); |
|
218 CleanupStack::PushL(entry); |
|
219 |
|
220 entry->SetEntryL(parentId); |
|
221 entry->CreateL(indexEntry); |
|
222 entry->SetEntryL(indexEntry.Id()); |
|
223 iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId()); |
|
224 |
|
225 CMsvStore* store = iMmsClientMtm->Entry().EditStoreL(); |
|
226 CleanupStack::PushL(store); |
|
227 |
|
228 //MMS Message ID Saved |
|
229 iMessageId = indexEntry.Id(); |
|
230 |
|
231 //Adding Subject |
|
232 if(subjectField) |
|
233 { |
|
234 QString subject(TEST_MSG_SUBJECT); |
|
235 HBufC* subj = XQConversions::qStringToS60Desc(subject); |
|
236 iMmsClientMtm->SetSubjectL(*subj); |
|
237 } |
|
238 |
|
239 //Adding Sender |
|
240 QString sender(TEST_MSG_FROM1); |
|
241 HBufC* addr = XQConversions::qStringToS60Desc(sender); |
|
242 |
|
243 if (addr) |
|
244 { |
|
245 CleanupStack::PushL(addr); |
|
246 TBuf<32> name; |
|
247 name.Copy(addr->Left(32)); |
|
248 indexEntry.iDetails.Set(name); |
|
249 |
|
250 iMmsClientMtm->SetSenderL(*addr); |
|
251 |
|
252 CleanupStack::PopAndDestroy(addr); |
|
253 } |
|
254 |
|
255 //Adding Recipient |
|
256 QString recipient(TEST_MSG_RECIEPIENT1); |
|
257 HBufC* addr2 = XQConversions::qStringToS60Desc(recipient); |
|
258 if (addr2) |
|
259 { |
|
260 CleanupStack::PushL(addr2); |
|
261 iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2); |
|
262 CleanupStack::PopAndDestroy(addr2); |
|
263 } |
|
264 |
|
265 //Adding cCRecipient |
|
266 QString recipient2(TEST_MSG_RECIEPIENT2); |
|
267 HBufC* addr3 = XQConversions::qStringToS60Desc(recipient2); |
|
268 if (addr3) |
|
269 { |
|
270 CleanupStack::PushL(addr3); |
|
271 iMmsClientMtm->AddAddresseeL(EMsvRecipientCc,*addr3); |
|
272 CleanupStack::PopAndDestroy(addr3); |
|
273 } |
|
274 |
|
275 //Adding bCCRecipient |
|
276 QString recipient3(TEST_MSG_RECIEPIENT3); |
|
277 HBufC* addr4 = XQConversions::qStringToS60Desc(recipient3); |
|
278 if (addr4) |
|
279 { |
|
280 CleanupStack::PushL(addr4); |
|
281 iMmsClientMtm->AddAddresseeL(EMsvRecipientBcc,*addr4); |
|
282 CleanupStack::PopAndDestroy(addr4); |
|
283 } |
|
284 |
|
285 //Create Text Attachment |
|
286 TMsvAttachmentId attaId = 0; |
|
287 TFileName attachmentFile( _L("story.txt") ); |
|
288 TBufC<12> story = _L( "Hello world!" ); |
|
289 |
|
290 iMmsClientMtm->CreateTextAttachmentL(*store, attaId, story, attachmentFile, ETrue ); |
|
291 qDebug() << "Text Attachment id" << attaId; |
|
292 |
|
293 //Image Attachment added to the message entry |
|
294 RFile attaFile; |
|
295 // Set filename of attachment |
|
296 TFileName name( KPictureFileName ); |
|
297 |
|
298 CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); |
|
299 CleanupStack::PushL( mimeHeaders ); |
|
300 |
|
301 // Set values to mime headers |
|
302 mimeHeaders->SetContentTypeL( _L8( "image") ); |
|
303 mimeHeaders->SetContentSubTypeL( _L8( "jpeg" ) ); |
|
304 |
|
305 _LIT8(KMimeType, "image/jpeg"); |
|
306 TBufC8<10> mimeType(KMimeType); |
|
307 // CreateAttachment2L will set the content type to attachment Info |
|
308 |
|
309 // Open the attachment file for reading |
|
310 attaFile.Open( iFs, name, EFileShareReadersOnly | EFileRead ); |
|
311 CleanupClosePushL(attaFile); |
|
312 |
|
313 CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
314 // attaInfo ownerhip will be transferred to Attachment Manager. |
|
315 // It must not be pushed onto the cleanupStack before calling |
|
316 // CreateAttachment2L. |
|
317 |
|
318 iMmsClientMtm->CreateAttachment2L(*store, attaFile,mimeType,*mimeHeaders,attaInfo,attaId); |
|
319 qDebug() << "Image Attachment id" << attaId; |
|
320 |
|
321 // Now Attachment Manager owns the attaInfo |
|
322 CleanupStack::Pop(); // attaFile.Close() |
|
323 CleanupStack::PopAndDestroy(); // mimeHeaders |
|
324 |
|
325 store->CommitL(); |
|
326 |
|
327 CleanupStack::PopAndDestroy(store); // store |
|
328 |
|
329 iMmsClientMtm->SaveMessageL(); |
|
330 |
|
331 //Saving the message size for future checking |
|
332 msgSize = iMmsClientMtm->MessageSize(); |
|
333 |
|
334 CleanupStack::Pop(entry); // entry |
|
335 } |
|
336 |
|
337 //--------------------------------------------------------------- |
|
338 // TestObserverMMS::HandleSessionEventL |
|
339 //--------------------------------------------------------------- |
|
340 void TestObserverMMS::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, |
|
341 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
342 { |
|
343 } |
|
344 |
|
345 //--------------------------------------------------------------- |
|
346 // main |
|
347 // main entry point |
|
348 //--------------------------------------------------------------- |
|
349 int main(int argc, char *argv[]) |
|
350 { |
|
351 int ret = -1; |
|
352 QCoreApplication app(argc, argv); |
|
353 QObject* tc = new TestUniDataModelMMSPlugin(); |
|
354 |
|
355 #ifdef __WINSCW__ |
|
356 char *new_argv[3]; |
|
357 QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log"; |
|
358 QByteArray bytes = str.toAscii(); |
|
359 char arg1[] = "-o"; |
|
360 new_argv[0] = argv[0]; |
|
361 new_argv[1] = arg1; |
|
362 new_argv[2] = bytes.data(); |
|
363 ret = QTest::qExec(tc, 3, new_argv); |
|
364 #else |
|
365 ret = QTest::qExec(tc, argc, argv); |
|
366 #endif |
|
367 |
|
368 delete tc; |
|
369 return ret; |
|
370 } |
|
371 |
|
372 //End of File |