|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #include <msvruids.h> |
|
17 #include <e32test.h> |
|
18 #include <f32fsys.h> |
|
19 #include <s32file.h> |
|
20 #include <e32uid.h> |
|
21 #include <msvreg.h> |
|
22 #include <mtsr.h> |
|
23 |
|
24 #include <msvids.h> |
|
25 #include <bioscmds.h> |
|
26 // BIF file database |
|
27 #include <biodb.h> |
|
28 |
|
29 #include <biouids.h> // Defines for use in Bio messaging |
|
30 #include <bitsids.h> // Uids for use in Test Harnesses |
|
31 |
|
32 #include <bsp.h> |
|
33 |
|
34 #include "biotestutils.h" |
|
35 |
|
36 #include <txtrich.h> // rich text stuff |
|
37 #include <txtfmlyr.h> // para format gubbins.. |
|
38 |
|
39 // Compiler flag to switch on Heap Failure Testing |
|
40 #define _HEAP_FAILURE_TEST_ |
|
41 |
|
42 RTest test(_L("BioServer MTM Testrig")); |
|
43 LOCAL_D CTrapCleanup* trapcleanup; |
|
44 LOCAL_D CActiveScheduler* activescheduler; |
|
45 #ifdef _DEBUG |
|
46 LOCAL_D TInt failCount1; |
|
47 #endif |
|
48 |
|
49 enum{ |
|
50 ENbssReadingFiles, |
|
51 ENbssTestParseProcess, |
|
52 ENbssTestParse, |
|
53 ENbssTestProcess, |
|
54 ENbssTestCopyTo, |
|
55 ENbssTestDelete, |
|
56 ENbssTestMoveTo, |
|
57 ENbssTestCopyFrom, |
|
58 ENbssTestMoveFrom, |
|
59 ENbssTestMoveWithin, |
|
60 ENbssTestCreate, |
|
61 ENbssTestChange, |
|
62 ENbssTestParsing // to allow heap testing to continue when |
|
63 // thread has left with KErrNoMemory |
|
64 }; |
|
65 |
|
66 // create our own active scheduler class |
|
67 |
|
68 class CExampleScheduler : public CActiveScheduler |
|
69 { |
|
70 public: |
|
71 void Error (TInt aError) const; |
|
72 }; |
|
73 |
|
74 void CExampleScheduler::Error(TInt /*anError*/) const |
|
75 { |
|
76 CActiveScheduler::Stop(); |
|
77 } |
|
78 |
|
79 class CTestNbssMtm : public CActive |
|
80 { |
|
81 public: |
|
82 static CTestNbssMtm* NewLC(); |
|
83 static CTestNbssMtm* NewL(); |
|
84 void ConstructL(); |
|
85 |
|
86 // Destruction |
|
87 ~CTestNbssMtm(); |
|
88 |
|
89 // Issue request |
|
90 void StartL(); |
|
91 CBaseServerMtm* Mtm(); |
|
92 // Cancel request. |
|
93 // Defined as pure virtual by CActive; |
|
94 // implementation provided by this class. |
|
95 void DoCancel(); |
|
96 |
|
97 // Service completed request. |
|
98 // Defined as pure virtual by CActive; |
|
99 // implementation provided by this class, |
|
100 void RunL(); |
|
101 void DoRunL(); |
|
102 |
|
103 // Sets the active scheduler going |
|
104 void QueueOperationAsync(TInt aErr); |
|
105 |
|
106 protected: |
|
107 // message creation code |
|
108 void InitialiseTesterL(); |
|
109 void SetMessageType(const TDesC& aFileName); |
|
110 // mtm test functions |
|
111 void DoCreateParserL(); |
|
112 void DoParseAgainL(); |
|
113 void DoProcessAgainL(); |
|
114 void DoCopyToL(); |
|
115 void DoCopyFromL(); |
|
116 void DoMoveToL(); |
|
117 void DoMoveFromL(); |
|
118 void DoMoveWithinL(); |
|
119 void DoDeleteL(); |
|
120 void DoCreateL(); |
|
121 void DoChangeL(); |
|
122 |
|
123 void ProcessError(TInt& aError); |
|
124 |
|
125 protected: |
|
126 // Data members defined by this class |
|
127 CBaseServerMtm* iNbssServerMtm; |
|
128 CMsvEntrySelection* iSelection; |
|
129 CMsvEntrySelection* iMsvSelection; |
|
130 TInt iState; |
|
131 |
|
132 CDir* iDir; |
|
133 |
|
134 RFs iFs; |
|
135 |
|
136 CBioTestUtils* iBioTestUtils; |
|
137 |
|
138 TInt iNumFiles; |
|
139 TInt iFilesProcessed; |
|
140 TInt iMessagesCreated; |
|
141 TInt iTestCtr; |
|
142 CArrayPtrSeg<CParsedField>* iTestParsedFieldArray; |
|
143 TBool iTestsSuccessful; |
|
144 |
|
145 private: |
|
146 CTestNbssMtm(); |
|
147 }; |
|
148 |
|
149 // |
|
150 // CTestRefresh CActive object |
|
151 // |
|
152 CTestNbssMtm::CTestNbssMtm() // construct low-priority active object |
|
153 : CActive(-5) |
|
154 { |
|
155 } |
|
156 |
|
157 CTestNbssMtm *CTestNbssMtm::NewLC() |
|
158 { |
|
159 CTestNbssMtm* self=new (ELeave) CTestNbssMtm(); |
|
160 |
|
161 CleanupStack::PushL(self); |
|
162 self->ConstructL(); |
|
163 return self; |
|
164 } |
|
165 |
|
166 CTestNbssMtm *CTestNbssMtm::NewL() |
|
167 { |
|
168 CTestNbssMtm* self=NewLC(); |
|
169 CleanupStack::Pop(); |
|
170 return self; |
|
171 } |
|
172 |
|
173 void CTestNbssMtm::ConstructL() |
|
174 { |
|
175 // connect to file system & create a BIO database |
|
176 User::LeaveIfError(iFs.Connect()); |
|
177 |
|
178 iBioTestUtils = CBioTestUtils::NewL(test,ETuGoServerSide); |
|
179 |
|
180 iBioTestUtils->CreateServicesL(); |
|
181 |
|
182 iBioTestUtils->InstantiateServerMtmsL(); |
|
183 |
|
184 iNbssServerMtm = iBioTestUtils->iBioServerMtm; |
|
185 |
|
186 CActiveScheduler::Add(this); // add to active scheduler |
|
187 |
|
188 // create an entry selection |
|
189 iSelection= new (ELeave) CMsvEntrySelection; |
|
190 |
|
191 iNumFiles=0; |
|
192 iFilesProcessed=0; |
|
193 iMessagesCreated=0; |
|
194 iTestsSuccessful = ETrue; |
|
195 |
|
196 test.Console()->ClearScreen(); // get rid of menu |
|
197 } |
|
198 |
|
199 CTestNbssMtm::~CTestNbssMtm() |
|
200 { |
|
201 Cancel(); // make sure we're cancelled |
|
202 |
|
203 delete iSelection; |
|
204 delete iMsvSelection; |
|
205 delete iBioTestUtils; |
|
206 delete iDir; |
|
207 |
|
208 iFs.Close(); |
|
209 |
|
210 if(iTestParsedFieldArray) |
|
211 { |
|
212 iTestParsedFieldArray->ResetAndDestroy(); |
|
213 delete iTestParsedFieldArray; |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 void CTestNbssMtm::DoCancel() |
|
220 { |
|
221 iNbssServerMtm->Cancel(); |
|
222 CActiveScheduler::Stop(); |
|
223 } |
|
224 |
|
225 |
|
226 CBaseServerMtm* CTestNbssMtm::Mtm() |
|
227 { |
|
228 return iNbssServerMtm; |
|
229 } |
|
230 |
|
231 |
|
232 void CTestNbssMtm::StartL() |
|
233 { |
|
234 test.Next(_L("CTestNbssMtm::Start()\n")); |
|
235 Cancel(); |
|
236 iState=ENbssReadingFiles; |
|
237 #if defined _HEAP_FAILURE_TEST_ |
|
238 TBool finished=EFalse; |
|
239 #ifdef _DEBUG |
|
240 TInt failCount=0; |
|
241 failCount1=0; |
|
242 #endif |
|
243 while (!finished) |
|
244 { |
|
245 __UHEAP_FAILNEXT(failCount++); |
|
246 TRAPD(error,InitialiseTesterL()); |
|
247 if (error==KErrNone) |
|
248 { |
|
249 finished=ETrue; |
|
250 __UHEAP_RESET; |
|
251 } |
|
252 else |
|
253 { |
|
254 test(error==KErrNoMemory); |
|
255 __UHEAP_RESET; |
|
256 } |
|
257 } |
|
258 #else |
|
259 InitialiseTesterL(); |
|
260 #endif |
|
261 QueueOperationAsync(KErrNone); |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 void CTestNbssMtm::QueueOperationAsync(TInt aErr) |
|
267 { |
|
268 TRequestStatus* pS = &iStatus; |
|
269 iStatus = KRequestPending; |
|
270 User::RequestComplete(pS, aErr); |
|
271 SetActive(); |
|
272 } |
|
273 |
|
274 void CTestNbssMtm::InitialiseTesterL() |
|
275 { |
|
276 // Get the NB if we don't need this two step process, use SetSmsServiceL(). |
|
277 iBioTestUtils->TestStart(iTestCtr); |
|
278 iBioTestUtils->SetBIOServiceIdL(); |
|
279 // Empty the Inbox |
|
280 iBioTestUtils->EmptyInboxMessagesL(); |
|
281 iMsvSelection = iBioTestUtils->GenerateMessagesL(); |
|
282 } |
|
283 |
|
284 void CTestNbssMtm::DoCreateParserL() |
|
285 { |
|
286 TBuf8<1>dummy; |
|
287 // add service entry and msg entry to selection passed to MTM |
|
288 iSelection->Reset(); |
|
289 iSelection->AppendL((*iMsvSelection)[iFilesProcessed]); |
|
290 |
|
291 #if defined _HEAP_FAILURE_TEST_ |
|
292 TBool finished=EFalse; |
|
293 while (!finished) |
|
294 { |
|
295 __UHEAP_FAILNEXT(failCount1++); |
|
296 TRAPD(error,iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmParseThenProcess, dummy, iStatus)); |
|
297 if (error==KErrNone) |
|
298 { |
|
299 finished=ETrue; |
|
300 __UHEAP_RESET; |
|
301 } |
|
302 else |
|
303 { |
|
304 test(error==KErrNoMemory); |
|
305 __UHEAP_RESET; |
|
306 } |
|
307 } |
|
308 #else |
|
309 iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmParseThenProcess, dummy, iStatus); |
|
310 #endif |
|
311 } |
|
312 |
|
313 void CTestNbssMtm::DoParseAgainL() |
|
314 { |
|
315 TBuf8<1>dummy; |
|
316 iState = ENbssTestParse; |
|
317 // add service entry and msg entry to selection passed to MTM |
|
318 iSelection->Reset(); |
|
319 |
|
320 iSelection->AppendL((*iMsvSelection)[iFilesProcessed]); |
|
321 |
|
322 #if defined _HEAP_FAILURE_TEST_ |
|
323 TBool finished=EFalse; |
|
324 |
|
325 #ifdef _DEBUG |
|
326 TInt failCount=0; |
|
327 #endif |
|
328 |
|
329 while (!finished) |
|
330 { |
|
331 __UHEAP_FAILNEXT(failCount++); |
|
332 TRAPD(error,iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmParse, dummy, iStatus)); |
|
333 if (error==KErrNone) |
|
334 { |
|
335 finished=ETrue; |
|
336 __UHEAP_RESET; |
|
337 } |
|
338 else |
|
339 { |
|
340 test(error==KErrNoMemory); |
|
341 __UHEAP_RESET; |
|
342 } |
|
343 } |
|
344 #else |
|
345 iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmParse, dummy, iStatus); |
|
346 #endif |
|
347 iState = ENbssTestParse; |
|
348 } |
|
349 |
|
350 void CTestNbssMtm::DoProcessAgainL() |
|
351 { |
|
352 TBuf8<1>dummy; |
|
353 iState = ENbssTestProcess; |
|
354 // add service entry and msg entry to selection passed to MTM |
|
355 iSelection->Reset(); |
|
356 iSelection->AppendL((*iMsvSelection)[iFilesProcessed]); |
|
357 |
|
358 #if defined _HEAP_FAILURE_TEST_ |
|
359 TBool finished=EFalse; |
|
360 |
|
361 #ifdef _DEBUG |
|
362 TInt failCount=0; |
|
363 #endif |
|
364 |
|
365 while (!finished) |
|
366 { |
|
367 __UHEAP_FAILNEXT(failCount++); |
|
368 TRAPD(error,iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmProcess, dummy, iStatus)); |
|
369 if (error==KErrNone) |
|
370 { |
|
371 finished=ETrue; |
|
372 __UHEAP_RESET; |
|
373 } |
|
374 else |
|
375 { |
|
376 test(error==KErrNoMemory); |
|
377 __UHEAP_RESET; |
|
378 } |
|
379 } |
|
380 #else |
|
381 iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmProcess, dummy, iStatus); |
|
382 #endif |
|
383 iState = ENbssTestProcess; |
|
384 } |
|
385 |
|
386 void CTestNbssMtm::DoCopyToL() |
|
387 { |
|
388 iNbssServerMtm->CopyToLocalL(*iSelection, KMsvGlobalInBoxIndexEntryId, iStatus); |
|
389 } |
|
390 |
|
391 void CTestNbssMtm::DoCopyFromL() |
|
392 { |
|
393 iNbssServerMtm->CopyFromLocalL(*iSelection,KMsvGlobalInBoxIndexEntryId, iStatus); |
|
394 } |
|
395 |
|
396 void CTestNbssMtm::DoDeleteL() |
|
397 { |
|
398 iNbssServerMtm->MoveFromLocalL(*iSelection,KMsvGlobalInBoxIndexEntryId, iStatus); |
|
399 } |
|
400 |
|
401 void CTestNbssMtm::DoMoveToL() |
|
402 { |
|
403 iNbssServerMtm->MoveFromLocalL(*iSelection,KMsvGlobalInBoxIndexEntryId, iStatus); |
|
404 } |
|
405 |
|
406 void CTestNbssMtm::DoMoveFromL() |
|
407 { |
|
408 iNbssServerMtm->MoveFromLocalL(*iSelection,KMsvGlobalInBoxIndexEntryId, iStatus); |
|
409 } |
|
410 |
|
411 void CTestNbssMtm::DoMoveWithinL() |
|
412 { |
|
413 iNbssServerMtm->MoveWithinServiceL(*iSelection,KMsvGlobalInBoxIndexEntryId, iStatus); |
|
414 } |
|
415 |
|
416 void CTestNbssMtm::DoCreateL() |
|
417 { |
|
418 TMsvEntry dudEntry; |
|
419 iNbssServerMtm->CreateL(dudEntry, iStatus); |
|
420 } |
|
421 |
|
422 // test create |
|
423 void CTestNbssMtm::DoChangeL() |
|
424 { |
|
425 TMsvEntry dudEntry; |
|
426 iNbssServerMtm->ChangeL(dudEntry, iStatus); |
|
427 } |
|
428 |
|
429 void CTestNbssMtm::RunL() |
|
430 { |
|
431 TRAPD(error,DoRunL()); |
|
432 if(error!=KErrNone) |
|
433 { |
|
434 iBioTestUtils->TestFinish(iTestCtr,error); |
|
435 CActiveScheduler::Stop(); |
|
436 } |
|
437 } |
|
438 |
|
439 void CTestNbssMtm::DoRunL() |
|
440 { |
|
441 iTestCtr++; |
|
442 TInt error=iStatus.Int(); |
|
443 |
|
444 if (iState == ENbssTestParsing) |
|
445 { |
|
446 // heap testing sets the active state to KErrNoMemory. In such a case |
|
447 // resume testing from the current count of failCount1 |
|
448 if (error == KErrNone || error == KErrNotSupported) |
|
449 { |
|
450 // test has complete ok - move to next state |
|
451 iBioTestUtils->LogCurrentMessageTypeL((*iMsvSelection)[iFilesProcessed]); |
|
452 iState = ENbssTestParseProcess; |
|
453 } |
|
454 else |
|
455 test (error==KErrNoMemory); |
|
456 } |
|
457 else |
|
458 { |
|
459 ProcessError(error); |
|
460 iBioTestUtils->TestFinish(iTestCtr,error); |
|
461 } |
|
462 TBool quit=EFalse; |
|
463 |
|
464 while (!quit) |
|
465 { |
|
466 switch(iState) |
|
467 { |
|
468 case ENbssReadingFiles: |
|
469 // for messaging api v2 the bio server mtm is null. The following code allows |
|
470 // the test harness to run and pass without breaking the nightly builds, but |
|
471 // since this test harness is redundant, it should be removed. |
|
472 iBioTestUtils->TestStart(iTestCtr,_L("Dummy test for null bio server MTM")); |
|
473 iBioTestUtils->TestHarnessCompleted(); |
|
474 CActiveScheduler::Stop(); |
|
475 quit=ETrue; |
|
476 break; |
|
477 case ENbssTestParseProcess: |
|
478 iBioTestUtils->TestStart(iTestCtr,_L("re-parse")); |
|
479 DoParseAgainL(); |
|
480 SetActive(); |
|
481 quit=ETrue; |
|
482 break; |
|
483 case ENbssTestParse: |
|
484 iBioTestUtils->TestStart(iTestCtr,_L("re-process")); |
|
485 DoProcessAgainL(); |
|
486 SetActive(); |
|
487 quit=ETrue; |
|
488 break; |
|
489 case ENbssTestParsing: |
|
490 DoCreateParserL(); |
|
491 SetActive(); |
|
492 quit=ETrue; |
|
493 break; |
|
494 |
|
495 case ENbssTestProcess: |
|
496 iFilesProcessed++; |
|
497 if(iFilesProcessed == iMessagesCreated) |
|
498 { |
|
499 if(iTestsSuccessful) |
|
500 iBioTestUtils->TestHarnessCompleted(); |
|
501 CActiveScheduler::Stop(); |
|
502 quit=ETrue; |
|
503 } |
|
504 else |
|
505 { |
|
506 iBioTestUtils->TestStart(iTestCtr,_L("Call parse and process")); |
|
507 #ifdef _DEBUG |
|
508 failCount1=0; |
|
509 #endif |
|
510 iState=ENbssTestParsing; |
|
511 } |
|
512 break; |
|
513 } |
|
514 } |
|
515 } |
|
516 |
|
517 void CTestNbssMtm::ProcessError(TInt& aError) |
|
518 { |
|
519 if(aError==KErrNotSupported) |
|
520 { |
|
521 aError = KErrNone; |
|
522 iBioTestUtils->WriteComment(_L("Unsupported operation")); |
|
523 } |
|
524 else if (aError == -521) |
|
525 { |
|
526 aError = KErrNone; |
|
527 iBioTestUtils->WriteComment(_L("Re-processing not performed. Script can only be added to once.")); |
|
528 } |
|
529 else if((aError <= -500 && aError >= -521) || (aError <= -600 && aError >= -614)) |
|
530 { |
|
531 iBioTestUtils->WriteComment(_L("Corrupt or missing Bio-data")); |
|
532 } |
|
533 else if(aError != KErrNone) |
|
534 iTestsSuccessful = EFalse; |
|
535 } |
|
536 |
|
537 LOCAL_C void testSetup() |
|
538 // |
|
539 // Start the various bits and pieces of the comms server |
|
540 // |
|
541 { |
|
542 trapcleanup=CTrapCleanup::New(); |
|
543 test(trapcleanup!=NULL); |
|
544 activescheduler = new CActiveScheduler; |
|
545 test(activescheduler!=NULL); |
|
546 CActiveScheduler::Install(activescheduler); |
|
547 } |
|
548 |
|
549 LOCAL_C void testUnsetup() |
|
550 // |
|
551 // Start the various bits and pieces of the comms server |
|
552 // |
|
553 { |
|
554 delete activescheduler; |
|
555 delete trapcleanup; |
|
556 } |
|
557 |
|
558 |
|
559 LOCAL_C void doMainL() |
|
560 // |
|
561 // Test SMMS. |
|
562 // |
|
563 { |
|
564 CTestNbssMtm* nbssTester = CTestNbssMtm::NewL(); |
|
565 nbssTester->StartL(); |
|
566 |
|
567 CActiveScheduler::Start(); |
|
568 |
|
569 delete nbssTester; |
|
570 } |
|
571 |
|
572 GLDEF_C TInt E32Main() |
|
573 { |
|
574 test.Title(); |
|
575 test.Start(_L("Testing...")); |
|
576 __UHEAP_MARK; |
|
577 |
|
578 testSetup(); |
|
579 |
|
580 TRAPD(error,doMainL()); |
|
581 |
|
582 testUnsetup(); |
|
583 |
|
584 test (error==KErrNone); |
|
585 |
|
586 test.Console()->Printf(_L("Done, press any key\n")); |
|
587 |
|
588 __UHEAP_MARKEND; |
|
589 test.End(); |
|
590 return KErrNone; |
|
591 } |
|
592 |