os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_012_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-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 // This contains Flogger Unit Test Case 012.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 // Test system includes
    20 #include "teststepcomsdbg.h"
    21 #include "TestMessage.h"
    22 #include "step_012_xx.h"
    23 
    24 #include <comms-infras/commsdebugutility.h>
    25 
    26 
    27 /**
    28 * Function  Name	: CFloggerTest012_01
    29 * Input parameters	: None
    30 * Output parameters : None
    31 * Description		: This is the constructor
    32 */
    33 
    34 
    35 CFloggerTest012_01::CFloggerTest012_01()
    36 	{
    37 	// store the name of this test case
    38 	SetTestStepName(_L("step_012_01"));
    39 	}
    40 
    41 
    42 /**
    43 * Function  Name	:~ CFloggerTest012_01
    44 * Input parameters	: None
    45 * Output parameters : None
    46 * Description		: This is the Destructor
    47 */
    48 
    49 
    50 CFloggerTest012_01::~CFloggerTest012_01()
    51 	{
    52 	}
    53 
    54 
    55 /**
    56 * Function  Name	: doTestStepL
    57 * Input parameters	: None
    58 * Output parameters : TVerdict 
    59 * Description		: This function returns weather the test case 012_01 has 
    60 * 					  passed or failed
    61 
    62 */
    63 
    64 
    65 TVerdict CFloggerTest012_01::doTestStepL( )
    66 	{
    67 
    68 	INFO_PRINTF1(_L("Step 012.01 called "));
    69 	
    70 	if ( executeStepL(EFalse) == KErrNone )
    71 		SetTestStepResult(EPass);
    72 
    73 	else
    74 		SetTestStepResult(EFail);
    75 
    76 	
    77 	User::After(KTimeForDisplay1);
    78 	return TestStepResult();
    79 	}
    80 
    81 
    82 /**
    83 * Function  Name		: executeStepL
    84 * Input parameters		: None
    85 * Output parameters		: TInt 
    86 * Description 			: This function writes the test data in to the log file 
    87 * 						  This function check the test message is present in the 
    88 * 						  log file 
    89 
    90 */
    91 
    92 
    93 TInt CFloggerTest012_01::executeStepL(TBool heapTest)
    94 	{
    95 	TInt ret = KErrGeneral;
    96 		
    97 	ret = DoTestWrite();
    98 	if (ret == KErrNone )
    99 		{
   100 		User::After(KTimeToLog);
   101 		TRAPD(r, ret = DoTestCheckWriteL() );
   102 		if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   103 			{
   104 			ret = KErrNoMemory;
   105 			}
   106 		else if (r != KErrNone)
   107 			{
   108 			ret = r;
   109 			}
   110 		}
   111 	return ret;
   112 	}
   113 /**
   114 * Function  Name		: executeStepL
   115 * Input parameters		: None
   116 * Output parameters		: TInt 
   117 * Description 			: This function writes the test data in to the log file 
   118 * 						  This function check the test message is present in the 
   119 * 						  log file 
   120 
   121 */
   122 
   123 
   124 TInt CFloggerTest012_01::executeStepL()
   125 	{
   126 	return KErrGeneral;
   127 	}
   128 
   129 
   130 /**
   131 * Function  Name		: DoTestWrite
   132 * Function  Name		: DoTestWrite
   133 * Input parameters		: None
   134 * Output parameters		: TInt 
   135 * Description 			: This function writes the data to the file logger
   136  
   137 */
   138 
   139 
   140 TInt CFloggerTest012_01::DoTestWrite()
   141 	{
   142 	_LIT16(KTestMessageOne,"TEST 12.01: The value of test integer variable :%d"); //unicode test decriptor
   143 	RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, KTestMessageOne, 100);
   144 
   145 	// connect so we can flush file buffer for heap check
   146 	RFileLogger theFlogger;
   147 	theFlogger.Connect();
   148 	theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   149 	ForceLogFlush(theFlogger);
   150 	theFlogger.Close();	
   151 	
   152 	return KErrNone; 
   153 	}
   154 
   155 
   156 /**
   157 * Function  Name		: DoTestCheckWriteL
   158 * Input parameters		: None
   159 * Output parameters		: TInt 
   160 * Description 			: This function checks the weather test data was written
   161 * 						  in to the log file by DoTestWriteL() or not.
   162 					  
   163 */
   164 
   165 
   166 TInt CFloggerTest012_01::DoTestCheckWriteL()
   167 	{
   168 	RFile theFile;
   169 	HBufC8 * hBuffer;
   170 	TInt listfilesize;
   171 	TInt returnCode;
   172 	RFs fileSystem;				//For file operation create a file system
   173 	TBuf8<256> testData;			//To hold the test descriptor
   174 	_LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
   175 
   176 	_LIT8(KTestMessageOne,"TEST 12.01: The value of test integer variable :%d"); //unicode test decriptor
   177 	testData.Format(KTestMessageOne,100);
   178 
   179 	User::LeaveIfError(fileSystem.Connect());
   180 	
   181 	//Open the file in the read mode
   182 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   183 
   184 	
   185 	returnCode = theFile.Size(listfilesize); //Size of the file
   186 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   187 	CleanupStack::PushL(hBuffer);
   188 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer read from file
   189 
   190 	// Read from position 0: starting of file
   191 	returnCode = theFile.Read(ptrString);
   192 	
   193 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   194 									//from the file
   195 
   196 	theFile.Close();
   197 	fileSystem.Close();
   198 	CleanupStack::PopAndDestroy(hBuffer);
   199 	if (returnCode > 0)
   200 		return KErrNone;
   201 	else 
   202 		return KErrNotFound;
   203 	}	
   204 
   205 
   206 TInt CFloggerTest012_01::DoHeapTestWrite()
   207 	{
   208 
   209 	_LIT16(KTestMessageOne,"TEST 12.04: Heap Test: The value of test integer variable :%d"); //unicode test decriptor
   210 	RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, KTestMessageOne, 100);
   211 	return KErrNone;
   212 	}
   213 
   214 
   215 /**
   216 * Function  Name	: CFloggerTest012_02
   217 * Input parameters	: None
   218 * Output parameters : None
   219 * Description		: This is the constructor
   220 */
   221 
   222 
   223 CFloggerTest012_02::CFloggerTest012_02()
   224 	{
   225 	// store the name of this test case
   226 	SetTestStepName(_L("step_012_02"));
   227 	}
   228 
   229 
   230 /**
   231 * Function  Name	:~ CFloggerTest012_02
   232 * Input parameters	: None
   233 * Output parameters : None
   234 * Description		: This is the Destructor
   235 */
   236 
   237 
   238 CFloggerTest012_02::~CFloggerTest012_02()
   239 	{
   240 	iFlogger.Close();
   241 	}
   242 
   243 
   244 
   245 /**
   246 * Function  Name	: doTestStepL
   247 * Input parameters	: None
   248 * Output parameters : TVerdict 
   249 * Description		: This function returns weather the test case 012_02 has 
   250 * 					  passed or failed
   251 
   252 */
   253 
   254 
   255 TVerdict CFloggerTest012_02::doTestStepL( )
   256 	{
   257 	INFO_PRINTF1(_L("Step 011.02 called "));
   258 	
   259 	if ( executeStepL() == KErrNone )
   260 		SetTestStepResult(EPass);
   261 
   262 	else
   263 		SetTestStepResult(EFail);
   264 
   265 	
   266 	User::After(KTimeForDisplay1);
   267 	return TestStepResult();
   268 	}
   269 
   270 /**
   271 * Function  Name		: executeStepL
   272 * Input parameters		: None
   273 * Output parameters		: TInt 
   274 * Description 			: This function writes the test data in to the log file 
   275 * 						  This function check the test message is present in the 
   276 * 						  log file 
   277 
   278 */
   279 
   280 
   281 TInt CFloggerTest012_02::executeStepL(TBool)
   282 	{
   283 	return KErrGeneral;
   284 	}
   285 
   286 /**
   287 * Function  Name		: executeStepL
   288 * Input parameters		: None
   289 * Output parameters		: TInt 
   290 * Description 			: This function writes the test data in to the log file 
   291 * 						  This function check the test message is present in the 
   292 * 						  log file 
   293 
   294 */
   295 
   296 
   297 TInt CFloggerTest012_02::executeStepL()
   298 	{
   299 	TInt ret = KErrGeneral;
   300 			
   301 	ret = DoTestWrite();
   302 	if (ret == KErrNone )
   303 		{
   304 		TRAPD(r, ret = DoTestCheckWriteL());
   305 		if ( r != KErrNone)
   306 			ret = r;
   307 		}
   308 	return ret;
   309 	}
   310 
   311 /**
   312 * Function  Name		: DoTestWrite
   313 * Input parameters		: None
   314 * Output parameters		: TInt 
   315 * Description 			: This function writes the data to the file logger
   316  
   317 */
   318 
   319 
   320 TInt CFloggerTest012_02::DoTestWrite()
   321 	{
   322 	
   323 	//unicode test decriptor
   324 	_LIT16(KTestMessageTwo,"TEST 12.02: The value of first test integer variable :%d The value of second test integer variable : %d");
   325 
   326 	RFileLogger ::WriteFormat(KStdSubsysTag8, KStdCompTag8, KTestMessageTwo, 100, 200);
   327 	
   328 	
   329 	return KErrNone;
   330 	}
   331 
   332 
   333 /**
   334 * Function  Name		: DoTestCheckWriteL
   335 * Input parameters		: None
   336 * Output parameters		: TInt 
   337 * Description 			: This function checks the weather test data was written
   338 * 						  in to the log file by DoTestWriteL() or not.
   339 					  
   340 */
   341 
   342 
   343 TInt CFloggerTest012_02::DoTestCheckWriteL()
   344 	{
   345 
   346 	
   347 	User::After(KTimeToLog);
   348 
   349 	RFile theFile;
   350 	HBufC8 * hBuffer;
   351 	TInt listfilesize;
   352 	TInt returnCode;
   353 	RFs fileSystem; //For file operation create a file system
   354 	TBuf8<256> testData; //To hold the test descriptor
   355 	_LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
   356 
   357 	_LIT8(KTestMessageTwo,"TEST 12.02: The value of first test integer variable :%d The value of second test integer variable : %d");
   358 	testData.Format(KTestMessageTwo,100, 200);
   359 
   360 	User::LeaveIfError(fileSystem.Connect());
   361 	
   362 	//Open the file in the read mode
   363 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   364 
   365 	
   366 	returnCode = theFile.Size(listfilesize); //Size of the file
   367 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   368 	CleanupStack::PushL(hBuffer);
   369 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   370 
   371 	// Read from position 0: start of file
   372 	returnCode = theFile.Read(ptrString);
   373 	
   374 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   375 									//from the file
   376 	theFile.Close();
   377 	fileSystem.Close();
   378 	CleanupStack::PopAndDestroy(hBuffer);
   379 	if (returnCode > 0)
   380 		return KErrNone;
   381 	else 
   382 		return KErrGeneral;
   383 	}
   384 
   385 
   386 /**
   387 * Function  Name	: CFloggerTest012_03
   388 * Input parameters	: None
   389 * Output parameters : None
   390 * Description		: This is the constructor
   391 */
   392 
   393 
   394 CFloggerTest012_03::CFloggerTest012_03()
   395 	{
   396 	// store the name of this test case
   397 	SetTestStepName(_L("step_012_03"));
   398 	}
   399 
   400 /**
   401 * Function  Name	:~ CFloggerTest012_03
   402 * Input parameters	: None
   403 * Output parameters : None
   404 * Description		: This is the Destructor
   405 */
   406 
   407 
   408 CFloggerTest012_03::~CFloggerTest012_03()
   409 	{
   410 	}
   411 
   412 
   413 /**
   414 * Function  Name	: doTestStepL
   415 * Input parameters	: None
   416 * Output parameters : TVerdict 
   417 * Description		: This function returns weather the test case 012_03 has 
   418 * 					  passed or failed
   419 
   420 */
   421 
   422 
   423 TVerdict CFloggerTest012_03::doTestStepL( )
   424 	{
   425 	INFO_PRINTF1(_L("Step 012.03 called "));
   426 	
   427 	if ( executeStepL() == KErrNone )
   428 		SetTestStepResult(EPass);
   429 
   430 	else
   431 		SetTestStepResult(EFail);
   432 
   433 	
   434 	User::After(KTimeForDisplay1);
   435 	return TestStepResult();
   436 	}
   437 
   438 /**
   439 * Function  Name		: executeStepL
   440 * Input parameters		: None
   441 * Output parameters		: TInt 
   442 * Description 			: This function writes the test data in to the log file 
   443 *						  This function check the test message is present in the 
   444 *						  log file 
   445 
   446 */
   447 
   448 
   449 TInt CFloggerTest012_03::executeStepL(TBool)
   450 	{
   451 	return KErrGeneral;
   452 	}
   453 
   454 /**
   455 * Function  Name		: executeStepL
   456 * Input parameters		: None
   457 * Output parameters		: TInt 
   458 * Description 			: This function writes the test data in to the log file 
   459 *						  This function check the test message is present in the 
   460 *						  log file 
   461 
   462 */
   463 
   464 
   465 TInt CFloggerTest012_03::executeStepL()
   466 	{
   467 	TInt ret = KErrGeneral;
   468 	User::After(1000*100);	//Need this or connect will return KErrServerTerminated
   469 	ret = DoTestWrite();
   470 	if (ret == KErrNone )
   471 		{
   472 		TRAPD(r, ret = DoTestCheckWriteL());
   473 		if ( r != KErrNone)
   474 			ret = r;
   475 		}
   476 	return ret;
   477 
   478 	}
   479 
   480 
   481 /**
   482 * Function  Name		: DoTestWrite
   483 * Input parameters		: None
   484 * Output parameters		: TInt 
   485 * Description 			: This function writes the data to the file logger
   486  
   487 */
   488 
   489 
   490 TInt CFloggerTest012_03::DoTestWrite()
   491 	{
   492 	_LIT(KTestLongMessage,"TEST 12.03: This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message ");
   493 
   494 	RFileLogger ::WriteFormat(KStdSubsysTag8, KStdCompTag8, KTestLongMessage);
   495 	return KErrNone;
   496 	}
   497 
   498 
   499 
   500 /**
   501 * Function  Name		: DoTestCheckWriteL
   502 * Input parameters		: None
   503 * Output parameters		: TInt 
   504 * Description 			: This function checks the weather test data was written
   505 * 						  in to the log file by DoTestWriteL() or not.
   506 					  
   507 */
   508 
   509 
   510 TInt CFloggerTest012_03::DoTestCheckWriteL()
   511 	{
   512 	User::After(KTimeToLog);
   513 
   514 	RFile theFile;
   515 	HBufC8 * hBuffer;
   516 	TInt listfilesize,returnCode;
   517 	RFs fileSystem; //For file operation create a file system
   518 	TBuf8<256> testData; //To hold the test descriptor
   519 	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   520 
   521 	//The following contains the string of length 200(max) 
   522 	//which is  written to the log file
   523 	//_LIT(KTestLongMessage, "This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message");
   524 	_LIT(KTestLongMessage, "TEST 12.03: This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This is the long message This");
   525 	
   526 	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   527 	
   528 	User::LeaveIfError(fileSystem.Connect());
   529 	
   530 	//Open the file in the read mode
   531 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   532 
   533 	CleanupClosePushL(theFile);
   534 
   535 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   536 	
   537 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   538 	CleanupStack::PushL(hBuffer);
   539 
   540 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   541 
   542 	// Read from position 0: start of file
   543 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   544 	
   545 	testData.Copy(KTestLongMessage); //Copy the test descriptor
   546 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   547 											//from the file
   548 
   549 	CleanupStack::PopAndDestroy(hBuffer);
   550 	CleanupStack::PopAndDestroy();	//theFile
   551 	if (returnCode > 0)
   552 		return KErrNone;
   553 	else 
   554 		return KErrGeneral;
   555 	
   556 	}
   557 
   558 
   559 /**
   560 * Function  Name	: CFloggerTest005_02
   561 * Input parameters	: None
   562 * Output parameters : None
   563 * Description		: This is the constructor
   564 */
   565 
   566 
   567 CFloggerTest012_04::CFloggerTest012_04()
   568 	{
   569 	// store the name of this test case
   570 	SetTestStepName(_L("step_012_04"));
   571 	}
   572 
   573 
   574 /**
   575 * Function  Name	:~ CFloggerTest005_02
   576 * Input parameters	: None
   577 * Output parameters : None
   578 * Description		: This is the Destructor
   579 */
   580 
   581 
   582 CFloggerTest012_04::~CFloggerTest012_04()
   583 	{
   584 	}
   585 
   586 /**
   587 * Function  Name : doTestStepL
   588 * Input parameters : None
   589 * Output parameters : TVerdict 
   590 * Description : This function is responsible for doing the heap test analysis 
   591 
   592 */
   593 TVerdict CFloggerTest012_04::doTestStepL( )
   594 	{
   595 	INFO_PRINTF1(_L("Step 012.04 called "));
   596 
   597 	CFloggerTest012_01* step012_01 = new CFloggerTest012_01;
   598 	CleanupStack::PushL(step012_01);
   599 	doTestStepWithHeapFailureL( *step012_01, 1,20, KErrNone, ETrue);
   600 
   601 	CleanupStack::PopAndDestroy(step012_01);
   602 	User::After(KTimeForDisplay);
   603 	return TestStepResult();
   604 	}
   605 
   606 
   607 
   608