os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_024_xx.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2003-2010 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 // This contains Flogger Unit Test Case 024.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 
    20 // Test system includes
    21 #include "teststepcomsdbg.h"
    22 #include "TestMessage.h"
    23 #include "step_024_xx.h"
    24 
    25 #include <comms-infras/commsdebugutility.h>
    26 
    27 
    28 const TInt KFiveSeconds = 5000000;
    29 const TInt KMaxConnection = 500; ///< specify a lot of connections for the connection stress test 
    30 const TInt KTimeBetConnection = 100000; //Some time between connection
    31 const TInt KDelayToCheckWrite = 10000000; //Give some time for the flogger to write the message before checking. Replaces KTimeToLog which is normally used.
    32 
    33 
    34 /**
    35 * Function  Name : CFloggerTest024_01
    36 * Input parameters : None
    37 * Output parameters : None
    38 * Description : This is the constructor
    39 */
    40 
    41 
    42 CFloggerTest024_01::CFloggerTest024_01()
    43 	{
    44 	// Store the name of this test case
    45 	SetTestStepName(_L("step_024_01"));
    46 	}
    47 
    48 
    49 /**
    50 * Function  Name :~ CFloggerTest024_01
    51 * Input parameters : None
    52 * Output parameters : None
    53 * Description : This is the Destructor
    54 */
    55 
    56 
    57 CFloggerTest024_01::~CFloggerTest024_01()
    58 	{
    59 	}
    60 
    61 
    62 /**
    63 * Function  Name	: doTestStepL
    64 * Input parameters	: None
    65 * Output parameters : TVerdict 
    66 * Description		: This function returns weather the test case 024_01 has 
    67 * 					  passed or failed
    68 
    69 */
    70 
    71 
    72 TVerdict CFloggerTest024_01::doTestStepL( )
    73 	{
    74 
    75 	INFO_PRINTF1(_L("Step 024.01 called "));
    76 	if ( executeStepL() == KErrNone  )
    77 		SetTestStepResult(EPass);
    78 
    79 	else
    80 		SetTestStepResult(EFail);
    81 
    82 	
    83 	return TestStepResult();
    84 	}
    85 
    86 
    87 /**
    88 * Function  Name		: executeStepL
    89 * Input parameters		: None
    90 * Output parameters		: TInt 
    91 * Description 			: This function sets the subsystem and component name
    92 * 						  checks weather they are set in the log file correctly
    93 
    94 					  
    95 */
    96 
    97 
    98 TInt CFloggerTest024_01::executeStepL()
    99 	{
   100 	return DoTestWrite();
   101 	}
   102 	
   103 /**
   104 * Function  Name		: executeStepL
   105 * Input parameters		: None
   106 * Output parameters		: TInt 
   107 * Description 			: This function sets the subsystem and component name
   108 * 						  checks weather they are set in the log file correctly
   109 
   110 					  
   111 */
   112 
   113 
   114 TInt CFloggerTest024_01::executeStepL(TBool)
   115 	{
   116 	return KErrGeneral;
   117 	}
   118 /**
   119 * Function  Name		: DoTestWriteL
   120 * Input parameters		: None
   121 * Output parameters		: TInt 
   122 * Description 			: This function checks the weather test data was written
   123 * 						  in to the log file by DoTestWriteL() or not.
   124 					  
   125 */
   126 
   127 
   128 TInt CFloggerTest024_01::DoTestWrite()
   129 	{
   130 	TPtrC8 ptrSubSystem;
   131 	TPtrC8 ptrComponent;
   132 	ptrSubSystem.Set(_L8("SubSystem"));
   133 	ptrComponent.Set(_L8("Component"));
   134 
   135 	_LIT8(KTestMessage1 ,"TC NO 24: This is test message before sleep");
   136 	_LIT8(KTestMessage2 ,"TC NO 24: This is test message After sleep");
   137 
   138 	TInt ret = KErrGeneral;
   139 	RFileLogger theFlogger;
   140 
   141 	ret = theFlogger.Connect();
   142 	if (ret == KErrNone)
   143 		{
   144 		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   145 		if (ret == KErrNone)
   146 			{
   147 			ret = theFlogger.ClearLog();
   148 			if (ret == KErrNone)
   149 				{
   150 				theFlogger.Write(KTestMessage1); //Write the test descriptor before sleep
   151 				User::After(KFiveSeconds); // Call After() function
   152 				theFlogger.Write(KTestMessage2); //Write the test descriptor after sleep
   153 				User::After(KFiveSeconds);
   154 
   155 				TRAPD(r, ret = DoTestCheckWriteL()); // Check whether the message is present in log
   156 			
   157 				
   158 				if (r != KErrNone)
   159 					ret = r;
   160 				}
   161 			}
   162 		}
   163 	if (ret == KErrNone)
   164 		theFlogger.__DbgShutDownServer();
   165 	theFlogger.Close();
   166 	return ret;
   167 	}
   168 
   169 
   170 /**
   171 * Function  Name		: DoTestCheckWriteL
   172 * Input parameters		: None
   173 * Output parameters		: TInt 
   174 * Description 			: This function checks the weather test data was written
   175 * 						  in to the log file by DoTestWriteL() or not.
   176 					  
   177 */
   178 
   179 
   180 TInt CFloggerTest024_01::DoTestCheckWriteL()
   181 	{
   182 	RFile theFile;
   183 
   184 	_LIT(KTestString,"Time");
   185 
   186 	HBufC8 * hBuffer;
   187 	TInt listfilesize;
   188 	RFs iFileSystem; //For file operation create a file system
   189 	TBuf8<256> testData; //To hold the test descriptor
   190 
   191 	User::LeaveIfError(iFileSystem.Connect());
   192 	
   193 	//Open the file in the read mode
   194 	User::LeaveIfError(theFile.Open(iFileSystem, KFloggerOutputFile, EFileWrite|EFileShareAny)); 
   195 	CleanupClosePushL(theFile);
   196 	
   197 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   198 	
   199 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   200 	CleanupStack::PushL(hBuffer);
   201 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   202 
   203 	// Read from position 0: start of file
   204 	User::LeaveIfError(theFile.Read(ptrString));
   205 	
   206 	testData.Copy(KTestString); //Copy the test string to be tested
   207 
   208 	TPtrC8 ptrTmpBuffer = ptrString.Right(listfilesize); //Copy of the orginal buffer read from the file
   209 	TInt charCount1 = 0;
   210 	TInt charCount2 = 0;
   211 	TInt lineCount = 0;
   212 	TInt tmpCount = 0;
   213 	
   214 	charCount1 = ptrString.Find(testData);
   215 	while(charCount1 != KErrNotFound)
   216 		{
   217 		lineCount++; //Increment the line count since we just found another one
   218 		charCount2 = charCount2 + charCount1 + KSampleTimeLine().Length(); //the the number of char's present in the line which
   219 										// is constant for the line starting with "#Time" in the log file
   220 
   221 		tmpCount = listfilesize - charCount2; // Remaining string after the "Time" is read
   222 		TPtrC8 strTmp = ptrString.Right(tmpCount);
   223 		charCount1 = strTmp.Find(testData);
   224 		if (charCount1 == 0) //Since the Time is found at the zeroth position count1 will contain 0
   225 			charCount1 = charCount1 + 4; // Charecter count of Time is 4
   226 		ptrString = ptrTmpBuffer.Right(listfilesize); // Get back the orginal buffer 
   227 		}
   228 
   229 	CleanupStack::PopAndDestroy(hBuffer);
   230 	CleanupStack::PopAndDestroy();	//theFile
   231 
   232 	// we expect to find the word "TIME" 10 times (or more) - 5 during each delay.
   233 	if ((lineCount >= 10) && (lineCount <= 12))
   234 		return KErrNone;
   235 	else
   236 		return KErrGeneral;
   237 
   238 
   239 
   240 	}
   241 
   242 
   243 
   244 
   245 
   246 
   247 _LIT8(KTestStringWithPunctuation1,"                                                 /===-_---~~~~~~~~~------____"); _LIT8(KTestStringWithPunctuation26,"    `~/  )` ) ,/|                 ~-_~>--<_/-__       __-~ _/ ");
   248 _LIT8(KTestStringWithPunctuation2,"                 -==\\\\                         `//~\\\\   ~~~~`---.___.-~~"); _LIT8(KTestStringWithPunctuation27,"   ;'( ')/ ,)(                              ~~~~~~~~~~ ");
   249 _LIT8(KTestStringWithPunctuation3,"       __--~~~  ,-/-==\\\\                        | |   `\\        ,'"); _LIT8(KTestStringWithPunctuation19,"                  \\_|      /        _)   ;  ),   __--~~");
   250 _LIT8(KTestStringWithPunctuation4,"  .'        /       |   \\\\                   /' /        \\   /'");              _LIT8(KTestStringWithPunctuation21,"                  |0  0 _/) )-~     | |__>--<__|      |");
   251 _LIT8(KTestStringWithPunctuation5,"/-'~    ~~~~~---__  |     ~-/~         ( )   /'        _--~`");                    _LIT8(KTestStringWithPunctuation20,"                   {\\__--_/}    / \\\\_>- )<__\\      \\");
   252 _LIT8(KTestStringWithPunctuation6,"                    '~~--_/      _-~/-  / \\   '-~ \\");                           _LIT8(KTestStringWithPunctuation22,"                 o o _//        /-~_>---<__-~      /");
   253 _LIT8(KTestStringWithPunctuation15,"                                                |===-~___                _,-'");  _LIT8(KTestStringWithPunctuation24,"            ( ( '))          |__>--<__|    |                 /' _---_~\\");
   254 _LIT8(KTestStringWithPunctuation16,"             ______-==|                         | |  \\\\           _-~`");       _LIT8(KTestStringWithPunctuation23,"                ,/|           /__>--<__/     _-~");
   255 _LIT8(KTestStringWithPunctuation17,"    _-~       /'    |  \\\\                      / /      \\      /");           _LIT8(KTestStringWithPunctuation25,"        ,/,'//( (             \\__>--<__\\    \\            /'  //        ||");
   256 _LIT8(KTestStringWithPunctuation18," /  ____  /         |    \\`\\.__/-~~ ~ \\ _ _/'  /          \\/'");
   257 _LIT8(KTestStringWithPunctuationExpected1,"         `-)) )) (           |__>--<__|    |               /'  /     ~\\`\\");
   258 _LIT8(KTestStringWithPunctuationExpected2,"                 o o _//        /-~_>---<__-~      /");
   259 _LIT8(KTestStringWithPunctuationExpected3,"    `~/  )` ) ,/|                 ~-_~>--<_/-__       __-~ _/ ");
   260 
   261 
   262 
   263 /**
   264 * CFloggerTest024_02 - test static write with string with beeps, tabs, nulls, CR's, LFs in the tags
   265 * doTestStep returns whether test case passed or failed.
   266 */ 
   267 
   268 
   269 
   270 
   271 CFloggerTest024_02::CFloggerTest024_02()
   272 	{
   273 	// Store the name of this test case
   274 	SetTestStepName(_L("step_024_02"));
   275 	}
   276 
   277 
   278 
   279 
   280 CFloggerTest024_02::~CFloggerTest024_02()
   281 	{
   282 	}
   283 
   284 
   285 
   286 
   287 TVerdict CFloggerTest024_02::doTestStepL( )
   288 	{
   289 	if ( executeStepL() == KErrNone  )
   290 		SetTestStepResult(EPass);
   291 
   292 	else
   293 		SetTestStepResult(EFail);
   294 
   295 	
   296 	return TestStepResult();
   297 	}
   298 
   299 
   300 TInt CFloggerTest024_02::executeStepL(TBool)
   301 	{
   302 	return KErrGeneral;
   303 	}
   304 
   305 TInt CFloggerTest024_02::executeStepL()
   306 	{
   307 	TInt ret;
   308 	
   309 	// clear the old log messages
   310 	RFileLogger flogger;
   311 	ret = flogger.Connect();
   312 	
   313 	if ( ret == KErrNone )
   314 		{
   315 		flogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   316 		flogger.ClearLog();
   317 		flogger.Close();
   318 		
   319 		RFileLogger::Write(KSubsysTagWithEscapeChars8, KCompTagWithEscapeChars8,KTestMessage8);
   320 		
   321 		User::After(KTimeToLog);
   322 		
   323 		TRAPD(r, ret = DoTestCheckWriteL());
   324 		if (r != KErrNone)
   325 			ret = r;
   326 		}
   327 		
   328 	
   329 	return ret;		
   330 
   331 	}
   332 
   333 
   334 TInt CFloggerTest024_02::DoTestCheckWriteL()
   335 	{
   336 	RFile logFile;
   337 	HBufC8* hBuffer;
   338 	TInt listfilesize,returnCode;
   339 	RFs fileSystem; //For file operation create a file system
   340 	TInt numSuccessful = 0;
   341 
   342 	User::LeaveIfError(fileSystem.Connect());
   343 	
   344 	//Open the file in the read mode
   345 	User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
   346 
   347 	CleanupClosePushL(logFile);
   348 
   349 	User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file
   350 	
   351 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   352 	CleanupStack::PushL(hBuffer);
   353 
   354 	TPtr8 ptrString = hBuffer->Des();  ; //To access the buffer
   355 
   356 	// Read from position 0: start of file
   357 	User::LeaveIfError(returnCode = logFile.Read(ptrString));
   358 	
   359 	// flogger should not have logged
   360 	returnCode = ptrString.Find(KTestMessage8);
   361 	
   362 	if (returnCode == KErrNotFound)
   363 		{
   364 		numSuccessful++;
   365 		}
   366 
   367 
   368 	CleanupStack::PopAndDestroy(hBuffer);
   369 	CleanupStack::PopAndDestroy();	//logFile
   370 	if (numSuccessful == 1)
   371 		return KErrNone;
   372 	else
   373 		return KErrUnknown;
   374 	}
   375 
   376 
   377 
   378 
   379 /**
   380 * CFloggerTest024_03 - test static write with string with punctuation and spaces in the data
   381 * doTestStep returns whether test case passed or failed.
   382 */ 
   383 
   384 _LIT8(KTestStringWithPunctuation8,"                  / /~ ,_/       / /__>---<__/      |  ");
   385 _LIT8(KTestStringWithPunctuation14,"  ' ') '( (/");
   386 _LIT8(KTestStringWithPunctuation9,"                 (^(~          /~_>---<__-      _-~");
   387 _LIT8(KTestStringWithPunctuation7,"                   /'   (_/  _-~  | |__>--<__|      | ");
   388 _LIT8(KTestStringWithPunctuation11,"         `-)) )) (           |__>--<__|    |               /'  /     ~\\`\\");
   389 _LIT8(KTestStringWithPunctuation12,"      ,( ( ((, ))              ~-__>--<_~-_  ~--____---~' _/'/        /'");
   390 _LIT8(KTestStringWithPunctuation10,"             ,//('(          |__>--<__|     /                  .----_ ");
   391 _LIT8(KTestStringWithPunctuation13,"  ._-~//( )/ )) `                    ~~-'_/_/ /~~~~~~~__--~ ");
   392 
   393 
   394 CFloggerTest024_03::CFloggerTest024_03()
   395 	{
   396 	// Store the name of this test case
   397 	SetTestStepName(_L("step_024_03"));
   398 	}
   399 
   400 
   401 
   402 
   403 CFloggerTest024_03::~CFloggerTest024_03()
   404 	{
   405 	}
   406 
   407 
   408 
   409 
   410 TVerdict CFloggerTest024_03::doTestStepL( )
   411 	{
   412 	if ( executeStepL() == KErrNone  )
   413 		SetTestStepResult(EPass);
   414 
   415 	else
   416 		SetTestStepResult(EFail);
   417 
   418 	
   419 	return TestStepResult();
   420 	}
   421 
   422 
   423 TInt CFloggerTest024_03::executeStepL(TBool)
   424 	{
   425 	return KErrGeneral;
   426 	}
   427 
   428 TInt CFloggerTest024_03::executeStepL()
   429 	{
   430 	TInt ret;
   431 	
   432 	// clear the old log messages
   433 	RFileLogger flogger;
   434 	ret = flogger.Connect();
   435 	
   436 	if ( ret == KErrNone )
   437 		{
   438 		flogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   439 		flogger.ClearLog();
   440 		flogger.Close();
   441 		
   442 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation1);
   443 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation15);
   444 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation2);
   445 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation16);
   446 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation3);
   447 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation17);
   448 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation4);
   449 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation18);
   450 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation5);
   451 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation19);
   452 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation6);
   453 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation20);
   454 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation7);
   455 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation21);
   456 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation8);
   457 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation22);
   458 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation9);
   459 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation23);
   460 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation10);
   461 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation24);
   462 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation11);
   463 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation25);
   464 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation12);
   465 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation26);
   466 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation13);
   467 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation27);
   468 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestStringWithPunctuation14);
   469 		
   470 		User::After(KTimeToLog);
   471 		
   472 		TRAPD(r, ret = DoTestCheckWriteL());
   473 		if (r != KErrNone)
   474 			ret = r;
   475 		}
   476 		
   477 	
   478 	return ret;		
   479 
   480 	}
   481 
   482 
   483 TInt CFloggerTest024_03::DoTestCheckWriteL()
   484 	{
   485 	RFile logFile;
   486 	HBufC8* hBuffer;
   487 	TInt listfilesize,returnCode;
   488 	RFs fileSystem; //For file operation create a file system
   489 	TInt numSuccessful = 0;
   490 
   491 	User::LeaveIfError(fileSystem.Connect());
   492 	
   493 	//Open the file in the read mode
   494 	User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
   495 
   496 	CleanupClosePushL(logFile);
   497 
   498 	User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file
   499 	
   500 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   501 	CleanupStack::PushL(hBuffer);
   502 
   503 	TPtr8 ptrString = hBuffer->Des();  ; //To access the buffer
   504 
   505 	// Read from position 0: start of file
   506 	User::LeaveIfError(returnCode = logFile.Read(ptrString));
   507 	
   508 	// check that flogger logged the punctuation/spaces correctly by checking three samples
   509 	returnCode = ptrString.Find(KTestStringWithPunctuationExpected1);
   510 	
   511 	if (returnCode > 0)
   512 		{
   513 		numSuccessful++;
   514 		}
   515 		
   516 	returnCode = ptrString.Find(KTestStringWithPunctuationExpected2);
   517 	
   518 	if (returnCode > 0)
   519 		{
   520 		numSuccessful++;
   521 		}
   522 		
   523 	returnCode = ptrString.Find(KTestStringWithPunctuationExpected3);
   524 	
   525 	if (returnCode > 0)
   526 		{
   527 		numSuccessful++;
   528 		}
   529 
   530 
   531 	CleanupStack::PopAndDestroy(hBuffer);
   532 	CleanupStack::PopAndDestroy();	//logFile
   533 	if (numSuccessful == 3)
   534 		return KErrNone;
   535 	else
   536 		return KErrUnknown;
   537 	}
   538 
   539 
   540 
   541 
   542 /**
   543 * CFloggerTest024_04 - test static write with data string with beeps, tabs, nulls, CR's, LFs in it
   544 * doTestStep returns whether test case passed or failed.
   545 */ 
   546 
   547 CFloggerTest024_04::CFloggerTest024_04()
   548 	{
   549 	// Store the name of this test case
   550 	SetTestStepName(_L("step_024_04"));
   551 	}
   552 
   553 
   554 
   555 
   556 CFloggerTest024_04::~CFloggerTest024_04()
   557 	{
   558 	}
   559 
   560 
   561 
   562 
   563 TVerdict CFloggerTest024_04::doTestStepL( )
   564 	{
   565 	if ( executeStepL() == KErrNone  )
   566 		SetTestStepResult(EPass);
   567 
   568 	else
   569 		SetTestStepResult(EFail);
   570 
   571 	
   572 	return TestStepResult();
   573 	}
   574 
   575 
   576 TInt CFloggerTest024_04::executeStepL(TBool)
   577 	{
   578 	return KErrGeneral;
   579 	}
   580 
   581 TInt CFloggerTest024_04::executeStepL()
   582 	{
   583 	TInt ret;
   584 	
   585 	// clear the old log messages
   586 	RFileLogger flogger;
   587 	ret = flogger.Connect();
   588 	
   589 	if ( ret == KErrNone )
   590 		{
   591 		flogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   592 		flogger.ClearLog();
   593 		flogger.Close();
   594 		
   595 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KTestMessageWithEscapeChars8);
   596 		
   597 		User::After(KTimeToLog);
   598 		
   599 		TRAPD(r, ret = DoTestCheckWriteL());
   600 		if (r != KErrNone)
   601 			ret = r;
   602 		}
   603 		
   604 	
   605 	return ret;		
   606 
   607 	}
   608 
   609 
   610 TInt CFloggerTest024_04::DoTestCheckWriteL()
   611 	{
   612 	RFile logFile;
   613 	HBufC8* hBuffer;
   614 	TInt listfilesize,returnCode;
   615 	RFs fileSystem; //For file operation create a file system
   616 	TInt numSuccessful = 0;
   617 
   618 	User::LeaveIfError(fileSystem.Connect());
   619 	
   620 	//Open the file in the read mode
   621 	User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
   622 
   623 	CleanupClosePushL(logFile);
   624 
   625 	User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file
   626 	
   627 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   628 	CleanupStack::PushL(hBuffer);
   629 
   630 	TPtr8 ptrString = hBuffer->Des();  ; //To access the buffer
   631 
   632 	// Read from position 0: start of file
   633 	User::LeaveIfError(returnCode = logFile.Read(ptrString));
   634 	
   635 	// flogger will have logged the string exactly as it was sent. The CR/LF will not
   636 	// cause a line feed because they are not adjacent
   637 	returnCode = ptrString.Find(KTestMessageWithEscapeChars8);
   638 	
   639 	if (returnCode > 0)
   640 		{
   641 		numSuccessful++;
   642 		}
   643 
   644 
   645 	CleanupStack::PopAndDestroy(hBuffer);
   646 	CleanupStack::PopAndDestroy();	//logFile
   647 	if (numSuccessful == 1)
   648 		return KErrNone;
   649 	else
   650 		return KErrUnknown;
   651 	}
   652 
   653 
   654 
   655 
   656 
   657 /**
   658 * CFloggerTest024_05 - test static write with data string with char 255, nulls, and escapes in it
   659 * doTestStep returns whether test case passed or failed.
   660 */ 
   661 
   662 CFloggerTest024_05::CFloggerTest024_05()
   663 	{
   664 	// Store the name of this test case
   665 	SetTestStepName(_L("step_024_05"));
   666 	}
   667 
   668 
   669 
   670 
   671 CFloggerTest024_05::~CFloggerTest024_05()
   672 	{
   673 	}
   674 
   675 
   676 
   677 
   678 TVerdict CFloggerTest024_05::doTestStepL( )
   679 	{
   680 	if ( executeStepL() == KErrNone  )
   681 		SetTestStepResult(EPass);
   682 
   683 	else
   684 		SetTestStepResult(EFail);
   685 
   686 	
   687 	return TestStepResult();
   688 	}
   689 
   690 TInt CFloggerTest024_05::executeStepL(TBool)
   691 	{
   692 	return KErrGeneral;
   693 	}
   694 
   695 
   696 TInt CFloggerTest024_05::executeStepL()
   697 	{
   698 	TInt ret;
   699 	
   700 	// clear the old log messages
   701 	RFileLogger flogger;
   702 	ret = flogger.Connect();
   703 	
   704 	if ( ret == KErrNone )
   705 		{
   706 		flogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   707 		flogger.ClearLog();
   708 		flogger.Close();
   709 		
   710 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,K2ndTestMessageWithEscapeChars8);
   711 		
   712 		User::After(KTimeToLog);
   713 		
   714 		TRAPD(r, ret = DoTestCheckWriteL());
   715 		if (r != KErrNone)
   716 			ret = r;
   717 		}
   718 		
   719 	
   720 	return ret;		
   721 
   722 	}
   723 
   724 
   725 TInt CFloggerTest024_05::DoTestCheckWriteL()
   726 	{
   727 	RFile logFile;
   728 	HBufC8* hBuffer;
   729 	TInt listfilesize,returnCode;
   730 	RFs fileSystem; //For file operation create a file system
   731 	TInt numSuccessful = 0;
   732 
   733 	User::LeaveIfError(fileSystem.Connect());
   734 	
   735 	//Open the file in the read mode
   736 	User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
   737 
   738 	CleanupClosePushL(logFile);
   739 
   740 	User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file
   741 	
   742 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   743 	CleanupStack::PushL(hBuffer);
   744 
   745 	TPtr8 ptrString = hBuffer->Des();  ; //To access the buffer
   746 
   747 	// Read from position 0: start of file
   748 	User::LeaveIfError(returnCode = logFile.Read(ptrString));
   749 	
   750 	// flogger will have logged the string exactly as it was sent. The CR/LF will not
   751 	// cause a line feed because they are not adjacent
   752 	returnCode = ptrString.Find(K2ndTestMessageWithEscapeChars8);
   753 	
   754 	if (returnCode > 0)
   755 		{
   756 		numSuccessful++;
   757 		}
   758 
   759 
   760 	CleanupStack::PopAndDestroy(hBuffer);
   761 	CleanupStack::PopAndDestroy();	//logFile
   762 	if (numSuccessful == 1)
   763 		return KErrNone;
   764 	else
   765 		return KErrUnknown;
   766 	}
   767 
   768 
   769 
   770 /**
   771 * CFloggerTest024_06 - test static write with empty data string
   772 * doTestStep returns whether test case passed or failed.
   773 */ 
   774 
   775 CFloggerTest024_06::CFloggerTest024_06()
   776 	{
   777 	// Store the name of this test case
   778 	SetTestStepName(_L("step_024_06"));
   779 	}
   780 
   781 
   782 
   783 
   784 CFloggerTest024_06::~CFloggerTest024_06()
   785 	{
   786 	}
   787 
   788 
   789 
   790 
   791 TVerdict CFloggerTest024_06::doTestStepL( )
   792 	{
   793 	if ( executeStepL() == KErrNone  )
   794 		SetTestStepResult(EPass);
   795 
   796 	else
   797 		SetTestStepResult(EFail);
   798 
   799 	
   800 	return TestStepResult();
   801 	}
   802 
   803 
   804 TInt CFloggerTest024_06::executeStepL(TBool)
   805 	{
   806 	return KErrGeneral;
   807 	}
   808 
   809 TInt CFloggerTest024_06::executeStepL()
   810 	{
   811 	TInt ret;
   812 	
   813 	// clear the old log messages
   814 	RFileLogger flogger;
   815 	ret = flogger.Connect();
   816 	
   817 	if ( ret == KErrNone )
   818 		{
   819 		flogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   820 		flogger.ClearLog();
   821 		flogger.Close();
   822 		
   823 		RFileLogger::Write(KStdSubsysTag8, KStdCompTag8,KNullDesC8);
   824 		
   825 		User::After(KTimeToLog);
   826 		
   827 		TRAPD(r, ret = DoTestCheckWriteL());
   828 		if (r != KErrNone)
   829 			ret = r;
   830 		}
   831 		
   832 	
   833 	return ret;		
   834 
   835 	}
   836 
   837 
   838 TInt CFloggerTest024_06::DoTestCheckWriteL()
   839 	{
   840 	RFile logFile;
   841 	HBufC8* hBuffer;
   842 	TInt listfilesize,returnCode;
   843 	RFs fileSystem; //For file operation create a file system
   844 	TInt numSuccessful = 0;
   845 
   846 	User::LeaveIfError(fileSystem.Connect());
   847 	
   848 	//Open the file in the read mode
   849 	User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead));
   850 
   851 	CleanupClosePushL(logFile);
   852 
   853 	User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file
   854 	
   855 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   856 	CleanupStack::PushL(hBuffer);
   857 
   858 	TPtr8 ptrString = hBuffer->Des();  ; //To access the buffer
   859 
   860 	// Read from position 0: start of file
   861 	User::LeaveIfError(returnCode = logFile.Read(ptrString));
   862 	
   863 	// not much to check since flogger won't have written much other than
   864 	// the tags
   865 	returnCode = ptrString.Find(KStdCompTag8);
   866 	
   867 	if (returnCode > 0)
   868 		{
   869 		numSuccessful++;
   870 		}
   871 
   872 
   873 	CleanupStack::PopAndDestroy(hBuffer);
   874 	CleanupStack::PopAndDestroy();	//logFile
   875 	if (numSuccessful == 1)
   876 		return KErrNone;
   877 	else
   878 		return KErrUnknown;
   879 	}
   880 
   881 
   882 CFloggerTest024_07::CFloggerTest024_07()
   883 	{
   884 	// Store the name of this test case
   885 	SetTestStepName(_L("step_024_07"));
   886 	}
   887 
   888 
   889 /**
   890 * Function  Name :~ CFloggerTest024_07
   891 * Input parameters : None
   892 * Output parameters : None
   893 * Description : This is the Destructor
   894 */ 
   895 
   896 
   897 CFloggerTest024_07::~CFloggerTest024_07()
   898 	{
   899 	}
   900 
   901 
   902 /**
   903 * Function  Name	: doTestStepL
   904 * Input parameters	: None
   905 * Output parameters : TVerdict 
   906 * Description		: This function returns whether the test case 024_07 has 
   907 * 					  passed or failed
   908 
   909 */
   910 
   911 
   912 TVerdict CFloggerTest024_07::doTestStepL( )
   913 	{
   914 	INFO_PRINTF1(_L("Step 027.13 called "));
   915 	if ( executeStepL() == KErrNone  )
   916 		SetTestStepResult(EPass);
   917 
   918 	else
   919 		SetTestStepResult(EFail);
   920 
   921 	INFO_PRINTF1(_L("leaving Step 027.13"));
   922 	User::After(KTimeForDisplay);
   923 
   924 	
   925 	return TestStepResult();
   926 	}
   927 
   928 /**
   929 * Function  Name		: executeStepL
   930 * Input parameters		: None
   931 * Output parameters		: TInt 
   932 * Description 			: This function checks for the flogger connection for 500 times
   933 
   934 */
   935 
   936 
   937 TInt CFloggerTest024_07::executeStepL(TBool)
   938 	{
   939 	return KErrGeneral;
   940 	}
   941 
   942 /**
   943 * Function  Name		: executeStepL
   944 * Input parameters		: None
   945 * Output parameters		: TInt 
   946 * Description 			: This function checks for the flogger connection for 500 times
   947 
   948 */
   949 
   950 
   951 TInt CFloggerTest024_07::executeStepL()
   952 	{
   953 	TInt ret = KErrNone;
   954 	ret = connectionTest();
   955 	if (ret == KErrNone)
   956 		{
   957 		TRAPD(r, ret = DoTestCheckWriteL());
   958 		if ( r != KErrNone)
   959 				ret = r;
   960 		}
   961 	return ret;
   962 	}
   963 
   964 
   965 TInt CFloggerTest024_07::connectionTest()
   966 	{
   967 	
   968 	_LIT8(KTestMessage,"TC 24_15: The flogger connection has been connected %d");
   969 	TPtrC8 ptrSubSystem;
   970 	TPtrC8 ptrComponent;
   971 	ptrSubSystem.Set(_L8("SubSystem"));
   972 	ptrComponent.Set(_L8("Component"));
   973 	TInt res = KErrNone;
   974 	RFileLogger flogger[KMaxConnection];
   975 
   976 	for(TInt i= 0; i<KMaxConnection; i++)
   977 		{
   978 		res = flogger[i].Connect();
   979 		if (res == KErrNone)
   980 			{
   981 			res = flogger[i].SetLogTags(ptrSubSystem, ptrComponent);
   982 			if (res == KErrNone)	
   983 				{
   984 				if (i == 0)
   985 					flogger[0].ClearLog();	// Clear previous test cases messages
   986 				flogger[i].WriteFormat(KTestMessage, i);
   987 				}
   988 			else
   989 				return KErrGeneral;
   990 			}
   991 		
   992 		else
   993 			{
   994 			INFO_PRINTF2(_L("Flogger connection failed for connection at -> %d "), i);
   995 			return KErrGeneral;
   996 			}
   997 	User::After(KTimeBetConnection);
   998 		}
   999 
  1000 	for(TInt j= 0; j<KMaxConnection; j++)
  1001 		flogger[j].Close();
  1002 
  1003 	User::After(KDelayToCheckWrite);
  1004 	
  1005 	return KErrNone;
  1006 
  1007 	}
  1008 
  1009 TInt CFloggerTest024_07::DoTestCheckWriteL()
  1010 	{
  1011 	User::After(KTimeToLog);
  1012 	RFile theFile;
  1013 	HBufC8 * hBuffer;
  1014 	TInt listfilesize;
  1015 	TInt returnCode;
  1016 	RFs fileSystem; //For file operation create a file system	
  1017 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
  1018 
  1019 	TBuf8<256> testData; //To hold the test descriptor
  1020 
  1021 	_LIT8(KTestMessage,"TC 24_15: The flogger connection has been connected %d");
  1022 	
  1023 
  1024 	User::LeaveIfError(fileSystem.Connect());
  1025 	
  1026 	//Open the file in the read mode
  1027 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
  1028 
  1029 	CleanupClosePushL(theFile);	
  1030 	
  1031 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
  1032 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
  1033 	CleanupStack::PushL(hBuffer);
  1034 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
  1035 
  1036 	// Read from position 0: start of file
  1037 	returnCode = theFile.Read(ptrString);
  1038 	
  1039 	for(TInt i =0; i<KMaxConnection; i++)
  1040 	{
  1041 	testData.Format(KTestMessage, i);
  1042 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
  1043 												//from the file
  1044 	if (returnCode > 0)
  1045 		continue;
  1046 	else
  1047 		User::Leave(KErrGeneral);
  1048 	}
  1049 
  1050 	CleanupStack::PopAndDestroy(hBuffer);
  1051 	CleanupStack::PopAndDestroy(); // For theFile object
  1052 	if (returnCode > 0)
  1053 		return KErrNone;
  1054 	else 
  1055 		return KErrGeneral;
  1056 	}
  1057 
  1058 
  1059 /**
  1060 * 024_08: Test that flogger handles date changes
  1061 */ 
  1062 
  1063 
  1064 CFloggerTest024_08::CFloggerTest024_08()
  1065 	{
  1066 	// Store the name of this test case
  1067 	SetTestStepName(_L("step_024_08"));
  1068 	}
  1069 
  1070 
  1071 
  1072 
  1073 CFloggerTest024_08::~CFloggerTest024_08()
  1074 	{
  1075 	}
  1076 
  1077 
  1078 
  1079 
  1080 TVerdict CFloggerTest024_08::doTestStepL( )
  1081 	{
  1082 	if ( executeStepL() == KErrNone  )
  1083 		SetTestStepResult(EPass);
  1084 
  1085 	else
  1086 		SetTestStepResult(EFail);
  1087 
  1088 	User::After(KTimeForDisplay);
  1089 
  1090 	
  1091 	return TestStepResult();
  1092 	}
  1093 
  1094 
  1095 TInt CFloggerTest024_08::executeStepL(TBool)
  1096 	{
  1097 	return KErrGeneral;
  1098 	}
  1099 
  1100 TInt CFloggerTest024_08::executeStepL()
  1101 	{
  1102 	TInt ret ;
  1103 	RFileLogger theFlogger; 
  1104 	
  1105 	//Just to clear the old log message
  1106 	ret = theFlogger.Connect(); 
  1107 	if ( ret == KErrNone)
  1108 		ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
  1109 		if ( ret == KErrNone)
  1110 			ret = theFlogger.ClearLog();
  1111 			if ( ret == KErrNone)
  1112 				theFlogger.Close();
  1113 
  1114 	// perform test. write some data, roll the date to 0 the following day. write more data.
  1115 	if ( ret == KErrNone)
  1116 		{
  1117 		RFileLogger ::Write(KStdSubsysTag16, KStdCompTag16,EFileLoggingModeAppend, KTestMessage);
  1118 		
  1119 		TTime time;
  1120 		time.HomeTime();
  1121 		TInt item;
  1122 		TDateTime dateTime(time.DateTime());
  1123 		dateTime.SetHour(0);
  1124 		dateTime.SetMinute(0);
  1125 		dateTime.SetSecond(0);
  1126 		item = dateTime.Day();
  1127 		if ((dateTime.SetDay(++item) != KErrNone))
  1128 			{
  1129 			dateTime.SetDay(0);
  1130 			item = dateTime.Month();
  1131 			if (item == EDecember)
  1132 				{
  1133 				dateTime.SetMonth(EJanuary);
  1134 				item = dateTime.Year();
  1135 				dateTime.SetYear(item++);
  1136 				}
  1137 			else
  1138 				{
  1139 				dateTime.SetMonth(TMonth(item++));
  1140 				}
  1141 			}
  1142 		time = TTime(dateTime);
  1143 	
  1144 		User::SetHomeTime(time);
  1145 		TTime currentMicrosecs;
  1146 		currentMicrosecs.HomeTime();
  1147 
  1148 		RFileLogger ::Write(KStdSubsysTag16, KStdCompTag16,EFileLoggingModeAppend, KTestMessage);
  1149 		User::After(KTimeToLog);
  1150 		TRAPD(r, ret = DoTestCheckWriteL());
  1151 		if (r != KErrNone)
  1152 			ret = r;
  1153 
  1154 		}
  1155 	return ret;
  1156 
  1157 	}
  1158 
  1159 
  1160 
  1161 /**
  1162 * This function checks whether test data was written
  1163 * 						  in to the log file .				  
  1164 */
  1165 
  1166 
  1167 TInt CFloggerTest024_08::DoTestCheckWriteL()
  1168 	{
  1169 	RFile theFile;
  1170 	HBufC8 * hBuffer;
  1171 	TInt listfilesize,returnCode;
  1172 	RFs fileSystem; //For file operation create a file system
  1173 	TBuf8<256> testData; //To hold the test descriptor
  1174 	TInt numSuccessful = 0;
  1175 
  1176 
  1177 	_LIT8(KOOMError, "#Logs may be lost out of memory!!");
  1178 	
  1179 	User::LeaveIfError(fileSystem.Connect());
  1180 	
  1181 	//Open the file in the read mode
  1182 	User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); 
  1183 
  1184 	CleanupClosePushL(theFile);
  1185 
  1186 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
  1187 	
  1188 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
  1189 	CleanupStack::PushL(hBuffer);
  1190 
  1191 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
  1192 
  1193 	// Read from position 0: start of file
  1194 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
  1195 	
  1196 	testData.Copy(KTestMessage); //Copy the test descriptor
  1197 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
  1198 											//from the file
  1199 	if (returnCode > 0)
  1200 		{
  1201 		numSuccessful++;
  1202 		}
  1203 											
  1204 	// We expect to see the string "date change"
  1205 	testData.Copy(KDateChangeMessage); //Copy the test descriptor
  1206 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
  1207 
  1208 	if (returnCode > 0)
  1209 		{
  1210 		numSuccessful++;
  1211 		}
  1212 
  1213 
  1214 	if (returnCode == KErrNotFound)
  1215 		{
  1216 		returnCode = ptrString.Find(KOOMError);
  1217 		if (returnCode > 0)
  1218 			User::Leave(KErrNoMemory);
  1219 		}
  1220 
  1221 
  1222 	
  1223 	CleanupStack::PopAndDestroy(hBuffer);
  1224 	CleanupStack::PopAndDestroy();	//theFile
  1225 	if (numSuccessful == 2)
  1226 		return KErrNone;
  1227 	else 
  1228 		return KErrNotFound;
  1229 	}
  1230 
  1231 
  1232 
  1233