|
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 // Test harness for CBioClientSideTestUtilities. |
|
15 // |
|
16 // BIO messages are created by synchronous calls.... |
|
17 |
|
18 #pragma warning( disable : 4100 ) |
|
19 |
|
20 // Includes... |
|
21 #include <e32test.h> |
|
22 #include <e32hal.h> |
|
23 #include <e32uid.h> |
|
24 #include <msvapi.h> |
|
25 #include <msvuids.h> |
|
26 #include <msvids.h> |
|
27 #include <f32fsys.h> |
|
28 #include <s32file.h> |
|
29 #include <barsc.h> |
|
30 #include <msvreg.h> |
|
31 #include <txtrich.h> // rich text stuff |
|
32 #include <txtfmlyr.h> // para format gubbins.. |
|
33 |
|
34 #include <biouids.h> // Important defines for use in the BIO messaging project |
|
35 #include <bitsids.h> //Message uids defines for the Test harnesses |
|
36 #include "biotestutils.h" |
|
37 |
|
38 // Uncomment following define to print the details to screen |
|
39 // Difficult to view as there's so much information |
|
40 // Constants ids. |
|
41 |
|
42 |
|
43 // Classes defined/used |
|
44 class CTestScheduler; |
|
45 class CObserverTester; |
|
46 class CDummySessionObserver; |
|
47 |
|
48 // Global functions.. |
|
49 // functions() |
|
50 GLDEF_C void doMainL(); |
|
51 GLDEF_C TInt E32Main(); |
|
52 |
|
53 // Resources.. |
|
54 GLDEF_C RTest test(_L("BIO Message Generator Test Rig")); |
|
55 LOCAL_D CTrapCleanup* theCleanup; |
|
56 LOCAL_D CTestScheduler* theScheduler; |
|
57 LOCAL_D RFs rFs; |
|
58 |
|
59 // States for the tester |
|
60 typedef enum |
|
61 { |
|
62 EStart, |
|
63 EReadingFiles, |
|
64 ECreatingMessages, |
|
65 EGeneratingResults, |
|
66 EStop |
|
67 } TTesterState; |
|
68 |
|
69 // |
|
70 // CTestScheduler - test active scheduler.. |
|
71 // |
|
72 class CTestScheduler : public CActiveScheduler |
|
73 { |
|
74 public: |
|
75 // inline |
|
76 void Error(TInt aError) const; |
|
77 }; |
|
78 |
|
79 void CTestScheduler::Error(TInt anError) const |
|
80 { |
|
81 CActiveScheduler::Stop(); |
|
82 test.Printf(_L("\nLeave signalled, reason=%d\n"),anError); |
|
83 } |
|
84 |
|
85 // |
|
86 |
|
87 // |
|
88 // // |
|
89 // CClientSideMessGeneratorTester - class definition // |
|
90 // // |
|
91 // |
|
92 |
|
93 class CClientSideMessGeneratorTester : public CActive |
|
94 { |
|
95 // public API |
|
96 public: |
|
97 static CClientSideMessGeneratorTester * NewL(TTimeIntervalMicroSeconds32 aTime); |
|
98 static CClientSideMessGeneratorTester * NewLC(TTimeIntervalMicroSeconds32 aTime); |
|
99 ~CClientSideMessGeneratorTester (); |
|
100 |
|
101 // Starts everything off |
|
102 void StartL(); |
|
103 // Sets the active scheduler going |
|
104 void QueueOperationAsync(TInt aErr); |
|
105 |
|
106 // Asks Message server to enumerate the results.. |
|
107 TInt GenerateResults(); |
|
108 void DoGenerateResultsL(); |
|
109 |
|
110 protected: |
|
111 CClientSideMessGeneratorTester (TTimeIntervalMicroSeconds32 aTime); |
|
112 void ConstructL(); |
|
113 void CreateFilenameArrayL(); |
|
114 void GenerateNextMessageL(); |
|
115 TInt DoGenerateMessages(); |
|
116 void InitialiseTesterL(); |
|
117 void SetMessageType(const TDesC& aFileName); |
|
118 |
|
119 #ifdef _TBIOTEST_LOGGING_ |
|
120 // Additional Logging functionality |
|
121 void LogNewMessageDetails(TMsvId amessageId); |
|
122 void ChangeELineBreaksToLF(const TDesC& aDesIn, TBuf<1024>& aBuffer); |
|
123 TBool IsEOL( TChar ch); // TUint8 ch ); |
|
124 #endif //_TBIOTEST_LOGGING_ |
|
125 |
|
126 private: // Active Object functions |
|
127 void DoCancel(); |
|
128 void RunL(); |
|
129 |
|
130 private: |
|
131 // Resources |
|
132 CBioTestUtils* iBIOGenerator; |
|
133 RTimer iTimer; |
|
134 |
|
135 CDir* iDir; |
|
136 TInt iNumFiles; |
|
137 TInt iFilesProcessed; |
|
138 TInt iMessagesCreated; |
|
139 TBIOMessageType iCurrentMessageType; |
|
140 |
|
141 // States |
|
142 TTesterState iState; |
|
143 // Service Ids |
|
144 TMsvId iBIOServiceId; |
|
145 TMsvId iNewEntryId; |
|
146 // General. |
|
147 TTimeIntervalMicroSeconds32 iNotificationPeriod; |
|
148 TBool iReleaseContextOnCreate; |
|
149 |
|
150 TMsvLocalOperationProgress iProgress; |
|
151 TPckgBuf<TMsvLocalOperationProgress> iLocProgressBuf; |
|
152 }; |
|
153 |
|
154 // |
|
155 // // |
|
156 // Implementation The tester class.. // |
|
157 // // |
|
158 // |
|
159 |
|
160 CClientSideMessGeneratorTester * CClientSideMessGeneratorTester ::NewL(TTimeIntervalMicroSeconds32 aTime) |
|
161 { |
|
162 CClientSideMessGeneratorTester * self = |
|
163 CClientSideMessGeneratorTester ::NewLC(aTime); |
|
164 CleanupStack::Pop(); |
|
165 return self; |
|
166 } |
|
167 |
|
168 CClientSideMessGeneratorTester * CClientSideMessGeneratorTester ::NewLC(TTimeIntervalMicroSeconds32 aTime) |
|
169 { |
|
170 CClientSideMessGeneratorTester * self = |
|
171 new (ELeave) CClientSideMessGeneratorTester (aTime); |
|
172 CleanupStack::PushL(self); |
|
173 self->ConstructL(); |
|
174 return self; |
|
175 } |
|
176 |
|
177 CClientSideMessGeneratorTester ::CClientSideMessGeneratorTester (TTimeIntervalMicroSeconds32 aTime) |
|
178 : CActive(EPriorityNormal), |
|
179 iNotificationPeriod(aTime) |
|
180 { |
|
181 } |
|
182 |
|
183 CClientSideMessGeneratorTester ::~CClientSideMessGeneratorTester () |
|
184 { |
|
185 // NB don't delete the Logger or Printer objects because this object doesn't own them |
|
186 Cancel(); |
|
187 |
|
188 delete iDir; |
|
189 // |
|
190 delete iBIOGenerator; |
|
191 } |
|
192 |
|
193 void CClientSideMessGeneratorTester ::ConstructL() |
|
194 { |
|
195 // Create the SMS Test Message Utility object |
|
196 iBIOGenerator = CBioTestUtils::NewL(test); |
|
197 iBIOGenerator->GoClientSideL(); |
|
198 |
|
199 iNumFiles = 0; |
|
200 iFilesProcessed = 0; |
|
201 iMessagesCreated = 0; |
|
202 |
|
203 // Add ourselves to the active scheduler |
|
204 User::LeaveIfError(iTimer.CreateLocal()); |
|
205 CActiveScheduler::Add(this); |
|
206 } |
|
207 |
|
208 // |
|
209 // // |
|
210 // Start the tester off // |
|
211 // // |
|
212 // |
|
213 void CClientSideMessGeneratorTester ::StartL() |
|
214 { |
|
215 // Set the Scheduler going so we go to our RunL(). |
|
216 iState=EStart; |
|
217 QueueOperationAsync(KErrNone); |
|
218 } |
|
219 |
|
220 // |
|
221 // // |
|
222 // Active Object Stuff // |
|
223 // // |
|
224 // |
|
225 |
|
226 void CClientSideMessGeneratorTester ::RunL() |
|
227 { |
|
228 TInt err = iStatus.Int(); |
|
229 |
|
230 if(err != KErrNone) |
|
231 { |
|
232 iBIOGenerator->TestHarnessFailed(err); |
|
233 CActiveScheduler::Stop(); |
|
234 } |
|
235 switch(iState) |
|
236 { |
|
237 case EStart: |
|
238 iState = EReadingFiles; |
|
239 iBIOGenerator->TestStart(1,_L("Initialise tester")); |
|
240 InitialiseTesterL(); |
|
241 iBIOGenerator->TestFinish(1); |
|
242 break; |
|
243 case EReadingFiles: |
|
244 iState = ECreatingMessages; |
|
245 test.Printf(_L("Reading Text Filenames \n")); |
|
246 iBIOGenerator->TestStart(2,_L("Create filename array")); |
|
247 CreateFilenameArrayL(); |
|
248 iBIOGenerator->TestFinish(2); |
|
249 QueueOperationAsync(KErrNone); |
|
250 break; |
|
251 case ECreatingMessages: // don't set the next state here |
|
252 if (iFilesProcessed ==0) |
|
253 iBIOGenerator->TestStart(3,_L("Generating messages")); |
|
254 iBIOGenerator->SetSessionPath(KBIOTxtFilePath); |
|
255 GenerateNextMessageL(); // state gets set here when we processed all the messages |
|
256 QueueOperationAsync(KErrNone); |
|
257 break; |
|
258 // 1st time in start the notifications. |
|
259 case EGeneratingResults: |
|
260 iState = EStop; |
|
261 iBIOGenerator->TestFinish(3); |
|
262 iBIOGenerator->TestStart(4,_L("Do some results")); |
|
263 QueueOperationAsync(KErrNone); |
|
264 break; |
|
265 case EStop: |
|
266 iBIOGenerator->FindChildrenL(KMsvGlobalInBoxIndexEntryId); |
|
267 iBIOGenerator->TestHarnessCompleted(); |
|
268 CActiveScheduler::Stop(); |
|
269 break; |
|
270 } |
|
271 } |
|
272 |
|
273 void CClientSideMessGeneratorTester ::DoCancel() |
|
274 { |
|
275 } |
|
276 |
|
277 void CClientSideMessGeneratorTester ::QueueOperationAsync(TInt aErr) |
|
278 { |
|
279 TRequestStatus* pS = &iStatus; |
|
280 iStatus = KRequestPending; |
|
281 User::RequestComplete(pS, aErr); |
|
282 SetActive(); |
|
283 } |
|
284 |
|
285 |
|
286 void CClientSideMessGeneratorTester ::InitialiseTesterL() |
|
287 { |
|
288 // Get the NB if we don't need this two step process, use SetSmsServiceL(). |
|
289 //iBIOGenerator->SetSmsServiceIdL(); |
|
290 iBIOGenerator->SetBIOServiceIdL(); |
|
291 // Empty the Inbox |
|
292 iBIOGenerator->EmptyInboxMessagesL(); |
|
293 QueueOperationAsync(KErrNone); |
|
294 } |
|
295 |
|
296 |
|
297 void CClientSideMessGeneratorTester ::CreateFilenameArrayL() |
|
298 { |
|
299 // Creates an array of descriptors for the body parts of our messages |
|
300 //Check that the source directory exists, if not warn the user and create one |
|
301 TInt err; |
|
302 if (iDir) |
|
303 delete iDir; |
|
304 err = rFs.GetDir(KBIOTxtFilePath, KEntryAttMatchMask, ESortByName, iDir); |
|
305 |
|
306 if (err == KErrPathNotFound) |
|
307 { |
|
308 test.Printf(_L("Error - source file directory not found\n\n")); |
|
309 TInt makeDirErr = rFs.MkDirAll(KBIOTxtFilePath); |
|
310 if (makeDirErr==KErrNone) |
|
311 { |
|
312 test.Printf(_L("Creating directory for files\nPlease add files to %S\n"), KBIOTxtFilePath); |
|
313 User::After(1000000); |
|
314 User::Leave(KErrNotFound); |
|
315 } |
|
316 else |
|
317 { |
|
318 test.Printf(_L("Error %d occurred when making directory %S"),makeDirErr, &KBIOTxtFilePath); |
|
319 User::Leave(makeDirErr); |
|
320 } |
|
321 } |
|
322 else if (err!=KErrNone) |
|
323 { |
|
324 test.Printf(_L("Error %d occurred"),err ); |
|
325 User::After(100000); |
|
326 User::Leave(err); |
|
327 } |
|
328 |
|
329 // Set the session path for the RF |
|
330 |
|
331 rFs.SetSessionPath(KBIOTxtFilePath); |
|
332 test.Printf(_L("Set Session path to %S \n"), &KBIOTxtFilePath); |
|
333 |
|
334 // Get a directory listing for the textfiles... |
|
335 if (iDir) |
|
336 delete iDir; |
|
337 User::LeaveIfError(rFs.GetDir(_L("*.txt"), KEntryAttNormal, ESortByName, iDir)); |
|
338 TInt count = iDir->Count(); |
|
339 if(count == 0) |
|
340 { |
|
341 test.Printf(_L("No files in the source directory %S !!"), &KBIOTxtFilePath); |
|
342 User::Leave(KErrNotFound); // No files to process |
|
343 } |
|
344 iNumFiles = count; |
|
345 iCurrentMessageType = ENoMessage; // Set to error condition |
|
346 // Display some info for the user |
|
347 test.Printf(_L("Have %d text files in directory \n"), count); |
|
348 test.Printf(_L("\n")); //move down one line |
|
349 } |
|
350 |
|
351 // |
|
352 // // |
|
353 // Creating one message stuff. // |
|
354 // // |
|
355 // |
|
356 |
|
357 void CClientSideMessGeneratorTester ::GenerateNextMessageL() |
|
358 { |
|
359 TBufC<KMaxFileName> currentFile; |
|
360 TEntry tempEntry; |
|
361 HBufC* tempDesc; |
|
362 |
|
363 // Check if there are any more files of the current type |
|
364 if (iFilesProcessed < iNumFiles) |
|
365 { |
|
366 tempEntry = (*iDir)[iFilesProcessed]; |
|
367 currentFile=( tempEntry.iName ); |
|
368 // Not processed all the messages - so keep the current state |
|
369 SetMessageType(currentFile); |
|
370 iFilesProcessed++; // Here because need to update the counter promptly |
|
371 if (iCurrentMessageType!=ENoMessage) // skip any dodgy filenames |
|
372 { |
|
373 tempDesc = currentFile.AllocL(); |
|
374 CleanupStack::PushL(tempDesc); |
|
375 test.Console()->SetPos(0, 8); |
|
376 test.Printf(_L("Reading file %S"), tempDesc); |
|
377 iBIOGenerator->CreateBIOEntryFromFileL(currentFile, iCurrentMessageType); |
|
378 iMessagesCreated++; |
|
379 test.Console()->SetPos(0, 10); |
|
380 test.Printf(_L("Created entry No. %d\n"), (iMessagesCreated)); |
|
381 test.Printf(_L("So far have discarded %d files out of a total of %d\n"), (iFilesProcessed-iMessagesCreated), iNumFiles); |
|
382 CleanupStack::PopAndDestroy(); // tempDesc; |
|
383 } |
|
384 } |
|
385 else if (iFilesProcessed == iNumFiles) // Completed everything |
|
386 { |
|
387 iState =EGeneratingResults; // Done creating messages |
|
388 } |
|
389 else // shouldn't be anything else as iMessagesProcessed |
|
390 { |
|
391 User::Leave(KErrUnknown); // Have an error but don't know how |
|
392 } |
|
393 } |
|
394 |
|
395 void CClientSideMessGeneratorTester ::SetMessageType(const TDesC& aFileName) |
|
396 { |
|
397 |
|
398 // Check each file prefix in turn with the filename passed as a parameter. |
|
399 // If cannot find the correct type set to ENoMessage to indicate an error. |
|
400 // GenerateNextMessage will then skip the file! |
|
401 |
|
402 if (aFileName.MatchF(KBIOIapPrefix)==0) // File starts with "iap" |
|
403 { |
|
404 iCurrentMessageType = EBioIapSettingsMessage; |
|
405 return; |
|
406 } |
|
407 if(aFileName.MatchF(KBIOEnpPrefix)==0) // File name starts "enp" |
|
408 { |
|
409 iCurrentMessageType = EBioEnpMessage; |
|
410 return; |
|
411 } |
|
412 if (aFileName.MatchF(KBIORingTonePrefix)==0)//Filename begins "rtone" |
|
413 { |
|
414 iCurrentMessageType = EBioRingTonesMessage; |
|
415 return; |
|
416 } |
|
417 if (aFileName.MatchF(KBIOOpLogoPrefix)==0) // Filename begins "oplogo" |
|
418 { |
|
419 iCurrentMessageType = EBioOpLogoMessage; |
|
420 return; |
|
421 } |
|
422 if (aFileName.MatchF(KBIOcBusinessCardPrefix)==0)// Filename begins "cbc" |
|
423 { |
|
424 iCurrentMessageType = EBioCompBusCardMessage; |
|
425 return; |
|
426 } |
|
427 if (aFileName.MatchF(KBIOvCardPrefix)==0) |
|
428 { |
|
429 iCurrentMessageType = EBiovCardMessage; |
|
430 return; |
|
431 } |
|
432 if (aFileName.MatchF(KBIOvCalenderPrefix)==0) |
|
433 { |
|
434 iCurrentMessageType = EBiovCalenderMessage; |
|
435 return; |
|
436 } |
|
437 // if we've reached this point it's an unknown filename |
|
438 iCurrentMessageType = ENoMessage; |
|
439 } |
|
440 |
|
441 TInt CClientSideMessGeneratorTester ::GenerateResults() |
|
442 { |
|
443 TInt err = KErrNone; |
|
444 TRAP(err, DoGenerateResultsL()); |
|
445 return err; |
|
446 } |
|
447 |
|
448 |
|
449 void CClientSideMessGeneratorTester ::DoGenerateResultsL() |
|
450 { |
|
451 } |
|
452 |
|
453 //***************************************************************************** |
|
454 // |
|
455 // Implementation; global stuff |
|
456 // |
|
457 //***************************************************************************** |
|
458 |
|
459 GLDEF_C TInt E32Main() |
|
460 { |
|
461 __UHEAP_MARK; |
|
462 theCleanup = CTrapCleanup::New(); |
|
463 TRAPD(err,doMainL()); |
|
464 test(err==KErrNone); |
|
465 delete theCleanup; |
|
466 test.End(); |
|
467 test.Close(); |
|
468 __UHEAP_MARKEND; |
|
469 return(KErrNone); |
|
470 } |
|
471 |
|
472 GLDEF_C void doMainL() |
|
473 { |
|
474 // Create an active scheduler for the program session |
|
475 theScheduler = new (ELeave) CTestScheduler(); |
|
476 CleanupStack::PushL(theScheduler); |
|
477 CActiveScheduler::Install(theScheduler); |
|
478 test.Title(); |
|
479 test.Start(_L("Starting test harness")); |
|
480 rFs.Connect(); |
|
481 |
|
482 // Can't actually lock a message client side |
|
483 CClientSideMessGeneratorTester * theTester = |
|
484 CClientSideMessGeneratorTester ::NewLC(100000); // release context on create |
|
485 theTester->StartL(); |
|
486 CActiveScheduler::Start(); |
|
487 |
|
488 CleanupStack::PopAndDestroy(); //theTester |
|
489 |
|
490 CleanupStack::PopAndDestroy(); //theScheduler |
|
491 rFs.Close(); |
|
492 } |
|
493 |