os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_029_xx.cpp
First public contribution.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // See the test specification for details of what these test cases do.
16 #include "teststepcomsdbg.h"
17 #include "TestMessage.h"
18 #include "step_029_xx.h"
21 #include <comms-infras/commsdebugutility.h>
26 * 029_IniFile01: Test that flogger handles ini change to debugport and file
29 CFloggerTest029_IniFile01::CFloggerTest029_IniFile01()
31 // Store the name of this test case
32 SetTestStepName(_L("step_029_IniFile01"));
38 CFloggerTest029_IniFile01::~CFloggerTest029_IniFile01()
45 TVerdict CFloggerTest029_IniFile01::doTestStepL( )
47 if ( executeStepL() == KErrNone )
48 SetTestStepResult(EPass);
51 SetTestStepResult(EFail);
53 User::After(KTimeForDisplay);
56 return TestStepResult();
59 TInt CFloggerTest029_IniFile01::executeStepL(TBool)
65 TInt CFloggerTest029_IniFile01::executeStepL()
69 RFileLogger theFlogger;
71 ret = theFlogger.Connect();
75 theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
76 theFlogger.ClearLog();
77 theFlogger.Write(KLogFillerMessage8);
78 theFlogger.Write(KLogFillerMessage8);
81 replaceFloggerIniL( KIniConfigWithFileAndDebugPort );
82 RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
84 User::After(KTimeToLog);
85 TRAP(r, ret = DoTestCheckWriteL());
90 constructFloggerIniL( KDefaultIniFileSettings );
99 TInt CFloggerTest029_IniFile01::DoTestCheckWriteL()
103 TInt listfilesize,returnCode;
104 RFs fileSystem; //For file operation create a file system
105 TUint numSuccessful = 0;
108 User::LeaveIfError(fileSystem.Connect());
109 CleanupClosePushL(fileSystem);
111 //Open the file in the read mode
112 User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
114 CleanupClosePushL(theFile);
116 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
118 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
119 CleanupStack::PushL(hBuffer);
121 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
123 // Read from position 0: start of file
124 User::LeaveIfError(returnCode = theFile.Read(ptrString));
126 returnCode = ptrString.Find(KMessageIniHasChanged); //find the test descriptor in the buffer read
133 else if (returnCode == KErrNotFound)
135 returnCode = ptrString.Find(KErrOOM);
137 User::Leave(KErrNoMemory);
140 returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read
149 // flogger should not have had a problem reading the ini file
150 returnCode = ptrString.Find(KErrIniProblemMessage);
152 if (returnCode == KErrNotFound)
157 CleanupStack::PopAndDestroy(hBuffer);
158 CleanupStack::PopAndDestroy(); //theFile
159 CleanupStack::PopAndDestroy(); //fileSystem
161 if (numSuccessful == 3)
170 * 029_IniFile02: Test that flogger handles ini change to debugport and serial
173 CFloggerTest029_IniFile02::CFloggerTest029_IniFile02()
175 // Store the name of this test case
176 SetTestStepName(_L("step_029_IniFile02"));
182 CFloggerTest029_IniFile02::~CFloggerTest029_IniFile02()
189 TVerdict CFloggerTest029_IniFile02::doTestStepL( )
191 if ( executeStepL() == KErrNone )
192 SetTestStepResult(EPass);
195 SetTestStepResult(EFail);
197 User::After(KTimeForDisplay);
200 return TestStepResult();
204 TInt CFloggerTest029_IniFile02::executeStepL(TBool)
209 TInt CFloggerTest029_IniFile02::executeStepL()
212 RFileLogger theFlogger;
214 ret = theFlogger.Connect();
216 if ( ret == KErrNone)
218 theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
219 theFlogger.ClearLog();
220 theFlogger.Write(KLogFillerMessage8);
221 theFlogger.Write(KLogFillerMessage8);
224 replaceFloggerIniL( KIniConfigWithSerialAndDebugPort );
225 RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
227 // serial logging means there isn't actually anything to check
228 // since we can't check the serial output
229 User::After(KTimeToLog);
232 constructFloggerIniL( KDefaultIniFileSettings );
246 * 029_IniFile03: Test that flogger handles ini change to debugport and file
249 CFloggerTest029_IniFile03::CFloggerTest029_IniFile03()
251 // Store the name of this test case
252 SetTestStepName(_L("step_029_IniFile03"));
258 CFloggerTest029_IniFile03::~CFloggerTest029_IniFile03()
265 TVerdict CFloggerTest029_IniFile03::doTestStepL( )
267 if ( executeStepL() == KErrNone )
268 SetTestStepResult(EPass);
271 SetTestStepResult(EFail);
273 User::After(KTimeForDisplay);
276 return TestStepResult();
280 TInt CFloggerTest029_IniFile03::executeStepL(TBool)
285 TInt CFloggerTest029_IniFile03::executeStepL()
289 RFileLogger theFlogger;
291 ret = theFlogger.Connect();
293 if ( ret == KErrNone)
295 theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
296 theFlogger.ClearLog();
297 theFlogger.Write(KLogFillerMessage8);
298 theFlogger.Write(KLogFillerMessage8);
301 TRAP(r,constructFloggerIniL( KSyncTestsIniFileSettings ));
302 RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessage8);
304 User::After(KTimeToLog); // although we asked for synchronous mode, we cannot switch to it while flogger is running
305 TRAP(r, ret = DoTestCheckWriteL());
312 TRAP(r,constructFloggerIniL( KDefaultIniFileSettings ));
325 TInt CFloggerTest029_IniFile03::DoTestCheckWriteL()
329 TInt listfilesize,returnCode;
330 RFs fileSystem; //For file operation create a file system
331 TUint numSuccessful = 0;
334 User::LeaveIfError(fileSystem.Connect());
335 CleanupClosePushL(fileSystem);
337 //Open the file in the read mode
338 User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
340 CleanupClosePushL(theFile);
342 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
344 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
345 CleanupStack::PushL(hBuffer);
347 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
349 // Read from position 0: start of file
350 User::LeaveIfError(returnCode = theFile.Read(ptrString));
352 returnCode = ptrString.Find(KMessageIniHasChanged); //find the test descriptor in the buffer read
359 else if (returnCode == KErrNotFound)
361 returnCode = ptrString.Find(KErrOOM);
363 User::Leave(KErrNoMemory);
366 returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read
375 // flogger should not have had a problem reading the ini file
376 returnCode = ptrString.Find(KErrIniProblemMessage);
378 if (returnCode == KErrNotFound)
383 CleanupStack::PopAndDestroy(hBuffer);
384 CleanupStack::PopAndDestroy(); //theFile
385 CleanupStack::PopAndDestroy(); //fileSystem
387 if (numSuccessful == 3)
395 029_IniFile04 - test changing ini file on the fly and removing a tag from it
396 doTestStep returns whether test case passed or failed.
397 When running heapcheck, doTestStep is not called - only executeStepL is called,
398 and it must return either KErrNoMemory or KErrNone to pass the heap check.
401 CFloggerTest029_IniFile04::CFloggerTest029_IniFile04()
403 // store the name of this test case
404 SetTestStepName(_L("step_029_IniFile04"));
408 CFloggerTest029_IniFile04::~CFloggerTest029_IniFile04()
414 // do Test step 029.01
415 TVerdict CFloggerTest029_IniFile04::doTestStepL( )
417 if (executeStepL(EFalse) == KErrNone)
418 SetTestStepResult(EPass);
421 SetTestStepResult(EFail);
424 INFO_PRINTF1(_L("leaving Step 029.IniFile04 "));
426 return TestStepResult() ;
429 TInt CFloggerTest029_IniFile04::executeStepL()
434 TInt CFloggerTest029_IniFile04::executeStepL(TBool heapTest)
436 @param heapTest supplied as ETrue when heap checking so that
437 we can catch instances of data not being in the file and let harness know
438 that perhaps its because no memory yet.
441 TInt ret = KErrGeneral;
443 TRAPD(r, ret = DoTestWrite(0))
445 if (r == KErrNone && ret == KErrNone)
447 User::After(KTimeToLog);
448 TRAP(r, ret = DoTestCheckWriteL(0));
450 if ((heapTest) && (ret == KErrNotFound))
455 else if (r == KErrNone && ret == KErrNone)
457 constructFloggerIniL( KIniFileChangeIniFileSettings );
458 TRAP(r, ret = DoTestWrite(1))
460 User::After(KTimeToLog);
461 TRAP(r, ret = DoTestCheckWriteL(1));
462 if ((heapTest) && (ret == KErrNotFound))
470 // regardless of what happens, we need to ensure we close the connection
472 TRAP(r, DoTestWrite(2))
473 constructFloggerIniL( KDefaultIniFileSettings );
483 // If aStatus is 0 then first modification
484 // If aStatus is 1 then second modification
486 TInt CFloggerTest029_IniFile04::DoTestWrite(TInt aStatus)
491 ptrSubSystem.Set(_L8("SubSystem"));
492 ptrComponent.Set(_L8("Component"));
493 TInt ret = KErrGeneral;
498 ret = iFlogger.Connect(); //Connect
502 //Set tags by passing the subsystem and component name as parameters
503 ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent);
504 if ( ret == KErrNone)
506 ret = iFlogger.ClearLog(); //Clear old log messages in the log
508 else if (ret == KErrNotFound)
510 ret = KErrNoMemory; // keep heap checker happy
512 if ( ret == KErrNone)
514 iFlogger.Write(KFirstTestMessage); //Write the test descriptor
515 ForceLogFlush(iFlogger);
524 //Set tags by passing the subsystem and component name as parameters
525 iFlogger.SetLogTags(ptrSubSystem, ptrComponent);
526 iFlogger.Write(KSecondTestMessage); //Write the test descriptor
527 iFlogger.SetLogTags(_L8("Esock"),_L8("Esock.txt"));
528 iFlogger.Write(KHexTestHeader); //Write the test descriptor
540 // If aFileStatus is 0 then status before modification
541 // If aFileStatus is 1 then status after modification
543 TInt CFloggerTest029_IniFile04::DoTestCheckWriteL(TInt aFileStatus)
547 TInt listfilesize = KErrGeneral;
548 TInt returnCode = KErrNotFound;
549 RFs fileSystem; //For file operation create a file system
550 TInt numSuccessful = 0;
553 User::LeaveIfError(fileSystem.Connect()); //Connect to the file server
555 //Open the file in the read mode
556 User::LeaveIfError(theFile.Open(fileSystem, KFloggerOutputFile, EFileRead));
558 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
560 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
561 CleanupStack::PushL(hBuffer);
562 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
564 // Read from position 0: starting of file
565 returnCode = theFile.Read(ptrString);
567 if (aFileStatus == 0)
569 // as a little extra test, the subsystem tag in the "ini" file is "Subsystem"
570 // but we wrote the data as "SubSystem" so it should still be in the file,
571 // but we need to search non-case sensitive
572 returnCode = ptrString.FindF(KStdSubsysTag8); //find the test system name in
573 //the buffer read from the file
576 if (returnCode > 0) //Note test system should be present before/After the ini is modified
579 returnCode = ptrString.Find(KStdCompTag8); //find the test component name in the buffer read
582 if (returnCode > 0) //Note test descriptor should be present before the ini is modified
584 returnCode = ptrString.Find(KFirstTestMessage); //find the test descriptor in the buffer read
588 CleanupStack::PopAndDestroy(hBuffer);
593 if (returnCode > 0) //Note test descriptor should be present before the ini is modified
594 returnCode = KErrNone;
599 else if (aFileStatus == 1)
601 returnCode = ptrString.Find(KFirstTestMessage); //find the first test descriptor in
602 //the buffer read from the file
604 if (returnCode > 0) //Note first test message should be present even after
605 //the ini is modified
609 returnCode = ptrString.Find(KErrIniProblemMessage);
610 if (returnCode > 0) //Note as a bonus the ini we supplied has an error, so a message as such should be there
615 returnCode = ptrString.Find(KSecondTestMessage);
616 if ( returnCode == KErrNotFound ) // The second test msg should not be there since there is no associated tag in the ini file
621 returnCode = ptrString.Find(KMessageIniHasChanged);
622 if ( returnCode > 0 ) // Flogger should see that the ini file has changed
627 CleanupStack::PopAndDestroy(hBuffer);
631 if (numSuccessful == 4)
632 returnCode = KErrNone;
642 CFloggerTest029_IniFile04H::CFloggerTest029_IniFile04H()
644 // store the name of this test case
645 SetTestStepName(_L("step_029_IniFile04H"));
650 CFloggerTest029_IniFile04H::~CFloggerTest029_IniFile04H()
656 TVerdict CFloggerTest029_IniFile04H::doTestStepL( )
658 INFO_PRINTF1(_L("Step 029.IniFile04H called "));
659 User::After(KTimeForDisplay1);
661 CFloggerTest029_IniFile04* step029_IniFile04 = new CFloggerTest029_IniFile04;
662 CleanupStack::PushL(step029_IniFile04);
663 doTestStepWithHeapFailureL( *step029_IniFile04, 523, 550, KErrNone, ETrue);
665 CleanupStack::PopAndDestroy(step029_IniFile04);
666 INFO_PRINTF1(_L("leaving Step 029.IniFile04H "));
669 return TestStepResult();