|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // sendas2test.cpp |
|
15 // |
|
16 #ifndef __SENDAS2TEST_H__ |
|
17 #define __SENDAS2TEST_H__ |
|
18 |
|
19 #include <sendas2.h> |
|
20 #include <csendasaccounts.h> |
|
21 #include <csendasmessagetypes.h> |
|
22 #include <e32base.h> |
|
23 #include "msvtestutilsbase.h" |
|
24 #include <mtclreg.h> |
|
25 #include <msvids.h> |
|
26 #include <msvuids.h> |
|
27 #include <msvapi.h> |
|
28 #include <e32uid.h> |
|
29 #include <msvruids.h> |
|
30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
31 #include "msvconsts.h" |
|
32 #endif |
|
33 |
|
34 // to be defined by test harness |
|
35 GLREF_D RTest test; |
|
36 GLREF_D void doTestsL(); |
|
37 |
|
38 // forward declarations |
|
39 class CSendTestUtils; |
|
40 |
|
41 // globals |
|
42 TInt SchedulerError; |
|
43 CSendTestUtils* theUtils = NULL; |
|
44 CTrapCleanup* theCleanup = NULL; |
|
45 |
|
46 const TInt KNumberOfTestMtms =5; |
|
47 const TInt KNumberOfTestMtmsCanSend =4; |
|
48 |
|
49 _LIT(KMtmDataDir, "c:\\system\\mtm\\"); |
|
50 _LIT(KMtmDataFile1, "c:\\system\\mtm\\SENDAS2MTM1.dat"); |
|
51 _LIT(KMtmDataFile2, "c:\\system\\mtm\\SENDAS2MTM2.dat"); |
|
52 _LIT(KMtmDataFile3, "c:\\system\\mtm\\SENDAS2MTM3.dat"); |
|
53 _LIT(KMtmDataFile4, "c:\\system\\mtm\\SENDAS2MTM4.dat"); |
|
54 _LIT(KMtmDataFile5, "c:\\system\\mtm\\SENDAS2MTM5.dat"); |
|
55 _LIT(KMtmDataFile6, "c:\\system\\mtm\\SENDAS2MTM6.dat"); |
|
56 |
|
57 _LIT(KMtmName1, "test MTM 1"); |
|
58 _LIT(KMtmName2, "test MTM 2"); |
|
59 _LIT(KMtmName3, "test MTM 3 with longer name"); |
|
60 _LIT(KMtmName4, "test MTM 4"); |
|
61 _LIT(KMtmName5, "test MTM 5"); |
|
62 _LIT(KMtmName6, "SMS Test CLIENT"); |
|
63 |
|
64 const TUid KUidTestMtm1={0x100014A4}; |
|
65 const TUid KUidTestMtm2={0x100014A5}; |
|
66 const TUid KUidTestMtm3={0x100014A6}; |
|
67 const TUid KUidTestMtm4={0x100014A7}; |
|
68 const TUid KUidTestMtm5={0x100014A8}; |
|
69 const TUid KUidTestMtm6={0x1000102C}; |
|
70 |
|
71 _LIT(KTestMtmFileName1, "sendas2mtm1.dll"); |
|
72 _LIT(KTestMtmFileName2, "sendas2mtm2.dll"); |
|
73 _LIT(KTestMtmFileName3, "sendas2mtm3.dll"); |
|
74 _LIT(KTestMtmFileName4, "sendas2mtm4.dll"); |
|
75 _LIT(KTestMtmFileName5, "sendas2mtm5.dll"); |
|
76 _LIT(KTestMtmFileName6, "smcm.dll"); |
|
77 |
|
78 _LIT(KMtmRegistryFile, "c:\\private\\1000484b\\MTM Registry v2"); |
|
79 |
|
80 const TUid KUidRenderingUid={0x10001000}; |
|
81 |
|
82 TBuf<32> KMtm1Service1 = _L("a new service"); |
|
83 TBuf<64> KMtm1Service2 = _L("the last service (alphabetically)"); |
|
84 TBuf<32> KMtm1Service3 = _L("last created, but in the middle"); |
|
85 TInt theMtm1Service1Id,theMtm1Service2Id,theMtm1Service3Id; |
|
86 |
|
87 TBuf<32> KMtm3Service1 = _L("zzzzzzzz"); |
|
88 TBuf<32> KMtm3Service2 = _L("aaaaaaaaahhhhhhhhh"); |
|
89 TInt theMtm3Service1Id,theMtm3Service2Id; |
|
90 |
|
91 TBuf<32> KMtm4Service1 = _L("lalala"); |
|
92 TBuf<32> KMtm6Service1 = _L("SMS Client"); |
|
93 TInt theMtm4Service1Id; |
|
94 |
|
95 // Attachment names |
|
96 _LIT(KErrAttachmentName1, "attachment1.txt"); |
|
97 _LIT(KErrAttachmentName2, "attachment2.txt"); |
|
98 _LIT(KAttachmentName, "Attach.txt"); |
|
99 |
|
100 |
|
101 TInt theErr; |
|
102 #define REPORT_IF_ERROR(a) {theErr=a; if (theErr) test(0);} |
|
103 |
|
104 //********************************** |
|
105 // CTestScheduler |
|
106 //********************************** |
|
107 |
|
108 class CTestScheduler : public CActiveScheduler |
|
109 { |
|
110 public: |
|
111 void Error (TInt aError) const; |
|
112 }; |
|
113 |
|
114 void CTestScheduler::Error( TInt anError ) const |
|
115 { |
|
116 SchedulerError = anError; |
|
117 } |
|
118 |
|
119 //********************************** |
|
120 // CDummyObserver |
|
121 //********************************** |
|
122 |
|
123 class CDummyObserver : public CBase, public MMsvSessionObserver |
|
124 { |
|
125 public: |
|
126 void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) {}; |
|
127 }; |
|
128 |
|
129 //********************************** |
|
130 // CSendTestUtils |
|
131 //********************************** |
|
132 |
|
133 class CSendTestUtils : public CTestUtils |
|
134 { |
|
135 public: |
|
136 static CSendTestUtils* NewL(RTest& aTest); |
|
137 protected: |
|
138 CSendTestUtils(RTest& aTest); |
|
139 public: |
|
140 void Panic(TInt aPanic); |
|
141 void Start(const TDesC& aDes); |
|
142 void Complete(); |
|
143 TUid FindMessageTypeL(RSendAs& aSendAs, const TDesC& aName); |
|
144 void SetupMtmsAndServicesL(); |
|
145 void CreateDataFilesL(const TDesC& aFilename, const TDesC& aMtmName, TUid aUid, const TDesC& aServerMtmFileName, const TDesC& aClientMtmFileName); |
|
146 void DeleteServicesL(CMsvEntry& aEntry, TUid aUid); |
|
147 TMsvId CreateServiceL(CMsvEntry& aEntry, const TMsvEntry& aService); |
|
148 void RemoveMailFolderL(TInt aDrive); |
|
149 private: |
|
150 TInt iTestNum; |
|
151 }; |
|
152 |
|
153 CSendTestUtils* CSendTestUtils::NewL(RTest& aTest) |
|
154 { |
|
155 CSendTestUtils* self = new(ELeave)CSendTestUtils(aTest); |
|
156 CleanupStack::PushL(self); |
|
157 self->ConstructL(); |
|
158 CleanupStack::Pop(self); |
|
159 return self; |
|
160 } |
|
161 |
|
162 CSendTestUtils::CSendTestUtils(RTest& aTest) : |
|
163 CTestUtils(aTest) |
|
164 { |
|
165 } |
|
166 |
|
167 void CSendTestUtils::Panic(TInt) |
|
168 { |
|
169 test(EFalse); |
|
170 } |
|
171 |
|
172 void CSendTestUtils::Start(const TDesC& aDes) |
|
173 { |
|
174 if (iTestNum == 0) |
|
175 { |
|
176 test.Start(aDes); |
|
177 } |
|
178 else |
|
179 { |
|
180 test.Next(aDes); |
|
181 } |
|
182 |
|
183 TestStart(++iTestNum, aDes); |
|
184 } |
|
185 |
|
186 void CSendTestUtils::Complete() |
|
187 { |
|
188 TestFinish(iTestNum, KErrNone); |
|
189 } |
|
190 |
|
191 TUid CSendTestUtils::FindMessageTypeL(RSendAs& aSendAs, const TDesC& aName) |
|
192 { |
|
193 // get list of available mtms |
|
194 CSendAsMessageTypes* messageTypes = CSendAsMessageTypes::NewL(); |
|
195 CleanupStack::PushL(messageTypes); |
|
196 aSendAs.FilteredMessageTypesL(*messageTypes); |
|
197 |
|
198 // get count of mtms |
|
199 TUid mtmUid(KNullUid); |
|
200 TInt count = messageTypes->Count(); |
|
201 while (count--) |
|
202 { |
|
203 if (messageTypes->AvailableMessageTypes().MdcaPoint(count) == aName) |
|
204 { |
|
205 mtmUid = messageTypes->MessageTypeUid(count); |
|
206 break; |
|
207 } |
|
208 } |
|
209 test(mtmUid != KNullUid); |
|
210 return mtmUid; |
|
211 } |
|
212 |
|
213 void CSendTestUtils::SetupMtmsAndServicesL() |
|
214 { |
|
215 FileSession().Delete(KMtmDataFile1); |
|
216 FileSession().Delete(KMtmDataFile2); |
|
217 FileSession().Delete(KMtmDataFile3); |
|
218 FileSession().Delete(KMtmDataFile4); |
|
219 FileSession().Delete(KMtmDataFile5); |
|
220 FileSession().Delete(KMtmRegistryFile); |
|
221 FileSession().Delete(KMtmDataFile6); |
|
222 |
|
223 CDummyObserver* ob = new(ELeave) CDummyObserver; |
|
224 CleanupStack::PushL(ob); |
|
225 CMsvSession* session = CMsvSession::OpenSyncL(*ob); |
|
226 CleanupStack::PushL(session); |
|
227 |
|
228 // MTMs |
|
229 CClientMtmRegistry* reg = CClientMtmRegistry::NewL(*session); |
|
230 TInt initialMtmCount = reg->NumRegisteredMtmDlls(); |
|
231 delete reg; |
|
232 reg=NULL; |
|
233 |
|
234 // Create an mtm directory if not already exists. |
|
235 TBool isOpen(EFalse); |
|
236 if (FileSession().IsFileOpen(KMtmDataDir, isOpen) != KErrNone) |
|
237 { |
|
238 TInt err = FileSession().MkDirAll(KMtmDataDir); |
|
239 if (err != KErrAlreadyExists) |
|
240 { |
|
241 User::Leave(err); |
|
242 } |
|
243 } |
|
244 |
|
245 TInt installedTestMtms = 0; |
|
246 CreateDataFilesL(KMtmDataFile1, KMtmName1, KUidTestMtm1, KTestMtmFileName1, KTestMtmFileName1); |
|
247 TInt err = session->InstallMtmGroup(KMtmDataFile1); |
|
248 if( err != KErrAlreadyExists ) |
|
249 { |
|
250 ++installedTestMtms; |
|
251 } |
|
252 CreateDataFilesL(KMtmDataFile2, KMtmName2, KUidTestMtm2, KTestMtmFileName2, KTestMtmFileName2); |
|
253 err = session->InstallMtmGroup(KMtmDataFile2); |
|
254 if( err != KErrAlreadyExists ) |
|
255 { |
|
256 ++installedTestMtms; |
|
257 } |
|
258 CreateDataFilesL(KMtmDataFile3, KMtmName3, KUidTestMtm3, KTestMtmFileName3, KTestMtmFileName3); |
|
259 err = session->InstallMtmGroup(KMtmDataFile3); |
|
260 if( err != KErrAlreadyExists ) |
|
261 { |
|
262 ++installedTestMtms; |
|
263 } |
|
264 CreateDataFilesL(KMtmDataFile4, KMtmName4, KUidTestMtm4, KTestMtmFileName4, KTestMtmFileName4); |
|
265 err = session->InstallMtmGroup(KMtmDataFile4); |
|
266 if( err != KErrAlreadyExists ) |
|
267 { |
|
268 ++installedTestMtms; |
|
269 } |
|
270 CreateDataFilesL(KMtmDataFile5, KMtmName5, KUidTestMtm5, KTestMtmFileName5, KTestMtmFileName5); |
|
271 err = session->InstallMtmGroup(KMtmDataFile5); |
|
272 if( err != KErrAlreadyExists ) |
|
273 { |
|
274 ++installedTestMtms; |
|
275 } |
|
276 CreateDataFilesL(KMtmDataFile6, KMtmName6, KUidTestMtm6, KTestMtmFileName6, KTestMtmFileName6); |
|
277 err = session->InstallMtmGroup(KMtmDataFile6); |
|
278 if( err != KErrAlreadyExists ) |
|
279 { |
|
280 ++installedTestMtms; |
|
281 } |
|
282 |
|
283 // |
|
284 reg = CClientMtmRegistry::NewL(*session); |
|
285 test(reg->NumRegisteredMtmDlls()==initialMtmCount+installedTestMtms); |
|
286 delete reg; reg=NULL; |
|
287 test.Printf(TRefByValue<const TDesC>(_L("created %d test mtms\n")),installedTestMtms); |
|
288 test.Printf(TRefByValue<const TDesC>(_L("-> %d test mtms already installed\n")),KNumberOfTestMtms-installedTestMtms); |
|
289 |
|
290 // |
|
291 // services |
|
292 CMsvEntry* entry = session->GetEntryL(KMsvRootIndexEntryId); |
|
293 CleanupStack::PushL(entry); |
|
294 DeleteServicesL(*entry, KUidTestMtm1); |
|
295 DeleteServicesL(*entry, KUidTestMtm3); |
|
296 DeleteServicesL(*entry, KUidTestMtm4); |
|
297 DeleteServicesL(*entry, KUidTestMtm5); |
|
298 DeleteServicesL(*entry, KUidTestMtm6); |
|
299 // |
|
300 TMsvEntry service; |
|
301 service.iType = KUidMsvServiceEntry; |
|
302 service.iMtm = KUidTestMtm1; |
|
303 service.iDetails.Set(KMtm1Service1); |
|
304 theMtm1Service1Id = CreateServiceL(*entry, service); |
|
305 // |
|
306 service.iDetails.Set(KMtm1Service2); |
|
307 theMtm1Service2Id = CreateServiceL(*entry, service); |
|
308 // |
|
309 service.iDetails.Set(KMtm1Service3); |
|
310 theMtm1Service3Id = CreateServiceL(*entry, service); |
|
311 // |
|
312 service.iMtm = KUidTestMtm3; |
|
313 service.iDetails.Set(KMtm3Service1); |
|
314 theMtm3Service1Id = CreateServiceL(*entry, service); |
|
315 // |
|
316 service.iDetails.Set(KMtm3Service2); |
|
317 theMtm3Service2Id = CreateServiceL(*entry, service); |
|
318 // |
|
319 service.iMtm = KUidTestMtm4; |
|
320 service.iDetails.Set(KMtm4Service1); |
|
321 theMtm4Service1Id = CreateServiceL(*entry, service); |
|
322 |
|
323 service.iMtm = KUidTestMtm6; |
|
324 service.iDetails.Set(KMtm6Service1); |
|
325 theMtm4Service1Id = CreateServiceL(*entry, service); |
|
326 |
|
327 CleanupStack::PopAndDestroy(3); // ob, session, entry |
|
328 } |
|
329 |
|
330 |
|
331 void CSendTestUtils::CreateDataFilesL(const TDesC& aFilename, const TDesC& aMtmName, TUid aUid, const TDesC& aServerMtmFileName, const TDesC& aClientMtmFileName) |
|
332 { |
|
333 CMtmDllInfoArray* mtmdllinfoarray=new(ELeave) CMtmDllInfoArray(); |
|
334 CleanupStack::PushL(mtmdllinfoarray); |
|
335 |
|
336 CMtmDllInfo* mtmdllinfo1=CMtmDllInfo::NewL(aMtmName, TUidType(KDynamicLibraryUid, KUidMtmServerComponent, TUid::Uid(KUidMtmDefaultSpecificVal)),aServerMtmFileName,1,TVersion(2,0,0)); |
|
337 mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo1); |
|
338 |
|
339 CMtmDllInfo* mtmdllinfo2=CMtmDllInfo::NewL(aMtmName, TUidType(KDynamicLibraryUid, KUidMtmClientComponent, TUid::Uid(KUidMtmDefaultSpecificVal)),aClientMtmFileName,1,TVersion(2,0,0)); |
|
340 mtmdllinfoarray->AddMtmDllInfoL(mtmdllinfo2); |
|
341 |
|
342 TCapabilitySet capSet; |
|
343 capSet.SetEmpty(); |
|
344 CleanupStack::Pop(mtmdllinfoarray); // next line takes ownership |
|
345 CMtmGroupData* mtmgroupdata=CMtmGroupData::NewL(aUid,aUid, mtmdllinfoarray, capSet); |
|
346 |
|
347 CleanupStack::PushL(mtmgroupdata); |
|
348 |
|
349 CFileStore* filestore = CPermanentFileStore::ReplaceLC(theUtils->FileSession(), aFilename, EFileShareExclusive|EFileStream|EFileWrite); |
|
350 TUidType uidtype(KPermanentFileStoreLayoutUid,KUidMsvDataComponent, aUid); |
|
351 filestore->SetTypeL(uidtype); |
|
352 RStoreWriteStream out; |
|
353 TStreamId streamid=out.CreateLC(*filestore); // Push to stack |
|
354 mtmgroupdata->ExternalizeL(out); |
|
355 out.CommitL(); |
|
356 CleanupStack::PopAndDestroy(); // out |
|
357 filestore->SetRootL(streamid); |
|
358 filestore->CommitL(); |
|
359 CleanupStack::PopAndDestroy(); // filestore |
|
360 |
|
361 CleanupStack::PopAndDestroy(); // mtmgroupdata |
|
362 } |
|
363 |
|
364 |
|
365 void CSendTestUtils::DeleteServicesL(CMsvEntry& aEntry, TUid aUid) |
|
366 { |
|
367 CMsvEntrySelection* selection = aEntry.ChildrenWithMtmL(aUid); |
|
368 if (selection->Count()) |
|
369 { |
|
370 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
371 wait->Start(); |
|
372 CMsvOperation* op = aEntry.DeleteL(*selection, wait->iStatus); |
|
373 CActiveScheduler::Start(); |
|
374 test(wait->iStatus.Int()==KErrNone||wait->iStatus.Int()==KErrNotFound); |
|
375 delete op; |
|
376 CleanupStack::PopAndDestroy(wait); |
|
377 } |
|
378 delete selection; |
|
379 } |
|
380 |
|
381 |
|
382 TMsvId CSendTestUtils::CreateServiceL(CMsvEntry& aEntry, const TMsvEntry& aService) |
|
383 { |
|
384 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
385 wait->Start(); |
|
386 CMsvOperation* op = aEntry.CreateL(aService, wait->iStatus); |
|
387 CActiveScheduler::Start(); |
|
388 REPORT_IF_ERROR(wait->iStatus.Int()); |
|
389 TMsvLocalOperationProgress localProg(McliUtils::GetLocalProgressL(*op)); |
|
390 TMsvId id = localProg.iId; |
|
391 delete op; |
|
392 CleanupStack::PopAndDestroy(); // wait |
|
393 return id; |
|
394 } |
|
395 |
|
396 void CSendTestUtils::RemoveMailFolderL(TInt aDrive) |
|
397 { |
|
398 CFileMan* fileMan = CFileMan::NewL(theUtils->FileSession()); |
|
399 CleanupStack::PushL(fileMan); |
|
400 |
|
401 TDriveUnit drive(aDrive); |
|
402 TPtrC ptr(drive.Name()); |
|
403 |
|
404 TParse parse; |
|
405 test(parse.Set(ptr, &KMsvDefaultFolder(), NULL) == KErrNone); |
|
406 |
|
407 TInt error = fileMan->RmDir(parse.DriveAndPath()); |
|
408 test(error == KErrNone || error == KErrPathNotFound); |
|
409 |
|
410 CleanupStack::PopAndDestroy(); |
|
411 } |
|
412 |
|
413 //********************************** |
|
414 // Global |
|
415 //********************************** |
|
416 |
|
417 void SetupSchedulerL() |
|
418 { |
|
419 CActiveScheduler::Install(new(ELeave)CTestScheduler); |
|
420 } |
|
421 |
|
422 void CloseScheduler(TInt aRet) |
|
423 { |
|
424 if (theUtils) |
|
425 { |
|
426 if (!aRet) |
|
427 { |
|
428 theUtils->TestHarnessCompleted(); |
|
429 } |
|
430 else |
|
431 { |
|
432 theUtils->TestHarnessFailed(aRet); |
|
433 } |
|
434 } |
|
435 test(aRet == KErrNone); |
|
436 |
|
437 delete CActiveScheduler::Current(); |
|
438 } |
|
439 |
|
440 void doMainL() |
|
441 { |
|
442 SetupSchedulerL(); |
|
443 |
|
444 // sendas2 test utils |
|
445 theUtils = CSendTestUtils::NewL(test); |
|
446 |
|
447 // TODO: Use test server to delete message folder and remove CENREP entries |
|
448 //theUtils->RemoveMailFolderL(EDriveC); |
|
449 |
|
450 // setup mtms |
|
451 theUtils->SetupMtmsAndServicesL(); |
|
452 |
|
453 // do the tests |
|
454 doTestsL(); |
|
455 } |
|
456 |
|
457 GLDEF_C TInt E32Main() |
|
458 { |
|
459 __UHEAP_MARK; |
|
460 theCleanup=CTrapCleanup::New(); |
|
461 TRAPD(ret,doMainL()); |
|
462 test(ret == KErrNone); |
|
463 CloseScheduler(ret); |
|
464 delete theUtils; |
|
465 delete theCleanup; |
|
466 test.Console()->SetPos(0, 13); |
|
467 test.End(); |
|
468 test.Close(); |
|
469 __UHEAP_MARKEND; |
|
470 return(KErrNone); |
|
471 } |
|
472 |
|
473 #endif |