os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_008_xx.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 008.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 // Test system includes
    20 #include <comms-infras/commsdebugutility.h>
    21 #include <f32file.h>
    22 
    23 
    24 //User includes
    25 #include "teststepcomsdbg.h"
    26 #include "step_008_xx.h"
    27 
    28 
    29 /**
    30 * Function  Name	: CFloggerTest008_01
    31 * Input parameters	: None
    32 * Output parameters : None
    33 * Description		: This is the constructor
    34 */
    35 
    36 
    37 CFloggerTest008_01::CFloggerTest008_01()
    38 	{
    39 	// store the name of this test case
    40 	SetTestStepName(_L("step_008_01"));
    41 
    42 	}
    43 
    44 
    45 
    46 /**
    47 * Function  Name	:~ CFloggerTest008_01
    48 * Input parameters	: None
    49 * Output parameters : None
    50 * Description		: This is the Destructor
    51 */
    52 
    53 
    54 CFloggerTest008_01::~CFloggerTest008_01()
    55 	{
    56 		
    57 	}
    58 
    59 
    60 /**
    61 * Function  Name	: doTestStepL
    62 * Input parameters	: None
    63 * Output parameters : TVerdict 
    64 * Description		: This function returns weather the test case 008_01 has 
    65 * 					  passed or failed
    66 
    67 */
    68 
    69 
    70 TVerdict CFloggerTest008_01::doTestStepL( )
    71 	{	
    72 	INFO_PRINTF1(_L("Step 008.01 called "));
    73 	
    74 	if ( executeStepL(EFalse) == KErrNone )
    75 		SetTestStepResult(EPass);
    76 
    77 	else
    78 		SetTestStepResult(EFail);
    79 
    80 	
    81 	User::After(KTimeForDisplay);
    82 	return TestStepResult();
    83 	}
    84 
    85 
    86 /**
    87 * Function  Name		: executeStepL
    88 * Input parameters		: None
    89 * Output parameters		: TInt 
    90 * Description 			: This function writes the test data in to the log file 
    91 * 						  This function check the test message is present in the 
    92 * 						  log file 
    93 
    94 */
    95 
    96 
    97 TInt CFloggerTest008_01::executeStepL(TBool heapTest)
    98 	{
    99 	TInt ret = KErrNone;
   100 	ret = DoTestConnect();
   101 	if (ret == KErrNone)
   102 		{
   103 		ret = DoTestWrite();
   104 		if ( ret == KErrNone)
   105 			{
   106 			TRAPD(r, ret = DoTestCheckWriteL());
   107 			if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   108 				{
   109 				ret = KErrNoMemory;
   110 				}
   111 			else if (r != KErrNone)
   112 				{
   113 				ret = r;
   114 				}
   115 			}
   116 		}
   117 
   118 //	if (ret == KErrNone)
   119 	iFlogger.Close();
   120 	return ret;
   121 	}
   122 
   123 /**
   124 * Function  Name		: executeStepL
   125 * Input parameters		: None
   126 * Output parameters		: TInt 
   127 * Description 			: This function writes the test data in to the log file 
   128 * 						  This function check the test message is present in the 
   129 * 						  log file 
   130 
   131 */
   132 
   133 
   134 TInt CFloggerTest008_01::executeStepL()
   135 	{
   136 	return KErrGeneral;
   137 	}
   138 
   139 /**
   140 * Function  Name		: DoTestWrite
   141 * Input parameters		: None
   142 * Output parameters		: TInt 
   143 * Description 			: This function writes the data to the file logger
   144  
   145 */
   146 
   147 
   148 TInt CFloggerTest008_01::DoTestWrite()
   149 	{
   150 	_LIT8(KTestMessageOne,"TC 8_01: The value of test integer variable :%d");
   151 	iFlogger.WriteFormat(KTestMessageOne, 100);  //Write 8 bit test descriptor
   152 	
   153 	ForceLogFlush(iFlogger);
   154 
   155 	return KErrNone; 
   156 	}
   157 
   158 
   159 /**
   160 * Function  Name		: DoTestCheckWriteL
   161 * Input parameters		: None
   162 * Output parameters		: TInt 
   163 * Description 			: This function checks the weather test data was written
   164 						  in to the log file by DoTestWriteL() or not.
   165 					  
   166 */
   167 
   168 
   169 TInt CFloggerTest008_01::DoTestCheckWriteL()
   170 	{
   171 	User::After(1000*1000);
   172 	RFile theFile;
   173 	HBufC8 * hBuffer;
   174 	TInt listfilesize;
   175 	TInt returnCode;
   176 	RFs fileSystem; //For file operation create a file system	
   177 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   178 
   179 	TBuf8<256> testData; //To hold the test descriptor
   180 
   181 	_LIT8(KTestMessageOne,"TC 8_01: The value of test integer variable :%d");
   182 	testData.Format(KTestMessageOne,100);
   183 
   184 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
   185 
   186 	User::LeaveIfError(fileSystem.Connect());
   187 	
   188 	//Open the file in the read mode
   189 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   190 
   191 	CleanupClosePushL(theFile);	
   192 	
   193 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   194 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   195 	CleanupStack::PushL(hBuffer);
   196 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   197 
   198 	// Read from position 0: start of file
   199 	returnCode = theFile.Read(ptrString);
   200 	
   201 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   202 									//from the file
   203 
   204 	if (returnCode == KErrNotFound)  //Find the error message
   205 		{
   206 		returnCode = ptrString.Find(KOOMError);
   207 		if (returnCode > 0)
   208 			User::Leave(KErrNoMemory);
   209 		}
   210 
   211 	CleanupStack::PopAndDestroy(hBuffer);
   212 	CleanupStack::PopAndDestroy(); // For theFile object
   213 	if (returnCode > 0)
   214 		return KErrNone;
   215 	else 
   216 		return KErrNotFound;
   217 	}
   218 
   219 
   220 
   221 /**
   222 * Function  Name		: DoTestConnect
   223 * Input parameters		: None
   224 * Output parameters		: TInt 
   225 * Description 			: This function establishes a connection to file logger
   226 * 						  and sets the system and component name in file logger.
   227 					  
   228 */
   229 
   230 
   231 TInt CFloggerTest008_01::DoTestConnect()
   232 	{
   233 	TInt ret = EFail;
   234 	TPtrC8 ptrSubSystem;
   235 	TPtrC8 ptrComponent;
   236 	ptrSubSystem.Set(_L8("SubSystem"));
   237 	ptrComponent.Set(_L8("Component"));
   238 
   239 	ret = iFlogger.Connect(); //Call connect() of Flogger
   240 	if (ret == KErrNone)
   241 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   242 
   243 	if (ret == KErrNone)
   244 		ret = iFlogger.ClearLog(); //clear the contents from the log
   245 	
   246 	return ret;
   247 	}
   248 
   249 
   250 
   251 
   252 
   253 /**
   254 * Function  Name	: CFloggerTest008_02
   255 * Input parameters	: None
   256 * Output parameters : None
   257 * Description		: This is the constructor
   258 */
   259 
   260 
   261 CFloggerTest008_02::CFloggerTest008_02()
   262 	{
   263 	// store the name of this test case
   264 	SetTestStepName(_L("step_008_02"));
   265 	}
   266 
   267 
   268 /**
   269 * Function  Name	:~ CFloggerTest008_02
   270 * Input parameters	: None
   271 * Output parameters : None
   272 * Description		: This is the Destructor
   273 */
   274 
   275 
   276 CFloggerTest008_02::~CFloggerTest008_02()
   277 	{
   278 	
   279 	}
   280 
   281 
   282 /**
   283 * Function  Name	: doTestStepL
   284 * Input parameters	: None
   285 * Output parameters : TVerdict 
   286 * Description		: This function returns weather the test case 008_02 has 
   287 * 					  passed or failed
   288 
   289 */
   290 
   291 
   292 TVerdict CFloggerTest008_02::doTestStepL( )
   293 	{
   294 	INFO_PRINTF1(_L("Step 008.02 called "));
   295 	
   296 	if ( executeStepL() == KErrNone )
   297 		SetTestStepResult(EPass);
   298 
   299 	else
   300 		SetTestStepResult(EFail);
   301 
   302 	
   303 	User::After(KTimeForDisplay);
   304 	return TestStepResult();
   305 	}
   306 
   307 
   308 /**
   309 * Function  Name		: executeStepL
   310 * Input parameters		: None
   311 * Output parameters		: TInt 
   312 * Description 			: This function writes the test data in to the log file 
   313 * 						  This function check the test message is present in the 
   314 * 						  log file 
   315 
   316 */
   317 
   318 
   319 TInt CFloggerTest008_02::executeStepL()
   320 	{
   321 	TInt ret = KErrGeneral;
   322 	ret = DoTestConnect();
   323 	 CleanupClosePushL(iFlogger);
   324 	if (ret == KErrNone)
   325 		{
   326 		ret = DoTestWrite() ;
   327 		if ( ret == KErrNone)
   328 			{
   329 			iFlogger.Close();
   330 			TRAPD(r, ret = DoTestCheckWriteL() );
   331 			if ( r != KErrNone)
   332 				ret = r;
   333 			}
   334 		}
   335 	CleanupStack::PopAndDestroy();	//logger
   336 	return ret;
   337 	}
   338 
   339 /**
   340 * Function  Name		: executeStepL
   341 * Input parameters		: None
   342 * Output parameters		: TInt 
   343 * Description 			: This function writes the test data in to the log file 
   344 * 						  This function check the test message is present in the 
   345 * 						  log file 
   346 
   347 */
   348 
   349 
   350 TInt CFloggerTest008_02::executeStepL(TBool)
   351 	{
   352 	return KErrGeneral;
   353 	}
   354 
   355 /**
   356 * Function  Name		: DoTestConnect
   357 * Input parameters		: None
   358 * Output parameters		: TInt 
   359 * Description 			: This function establishes a connection to file logger
   360 * 						  and sets the system and component name in file logger.
   361 					  
   362 */ 
   363 
   364 
   365 TInt CFloggerTest008_02::DoTestConnect()
   366 	{
   367 	TInt ret;
   368 	TPtrC8 ptrSubSystem, ptrComponent;
   369 	ptrSubSystem.Set(_L8("SubSystem"));
   370 	ptrComponent.Set(_L8("Component"));
   371 
   372 	ret = iFlogger.Connect(); //Call connect() of Flogger
   373 	if (ret == KErrNone)
   374 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   375 
   376 	if (ret == KErrNone)
   377 		ret = iFlogger.ClearLog(); //clear the contents from the log
   378 
   379 	return ret;
   380 
   381 	}
   382 
   383 
   384 /**
   385 * Function  Name		: DoTestWrite
   386 * Input parameters		: None
   387 * Output parameters		: TInt 
   388 * Description 			: This function writes the data to the file logger
   389  
   390 */
   391 
   392 
   393 TInt CFloggerTest008_02::DoTestWrite()
   394 	{
   395 	_LIT8(KTestMessageTwo,"TC 8_02: The value of first test integer variable :%d The value of second test integer variable : %d");
   396 	iFlogger.WriteFormat(KTestMessageTwo, 100, 200); //Writes a 8 bit test descriptor
   397 	
   398 	ForceLogFlush(iFlogger);
   399 	return KErrNone; 
   400 	}
   401 
   402 
   403 /**
   404 //Function  Name		: DoTestCheckWriteL
   405 //Input parameters		: None
   406 //Output parameters		: TInt 
   407 //Description 			: This function checks the weather test data was written
   408 //						  in to the log file by DoTestWriteL() or not.
   409 					  
   410 */
   411 
   412 
   413 TInt CFloggerTest008_02::DoTestCheckWriteL()
   414 	{
   415 	User::After(1000*1000);
   416 	RFile theFile;
   417 	HBufC8 * hBuffer;
   418 	TInt listfilesize;
   419 	TInt returnCode;
   420 
   421 	RFs fileSystem; //For file operation create a file system
   422 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   423 
   424 	TBuf8<256> testData; //To hold the test descriptor
   425 	_LIT8(KTestMessageTwo,"TC 8_02: The value of first test integer variable :%d The value of second test integer variable : %d");
   426 	testData.Format(KTestMessageTwo,100, 200);
   427 
   428 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message 
   429 
   430 	User::LeaveIfError(fileSystem.Connect());//Connect to the file server
   431 	
   432 	//Open the file in the read mode
   433 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   434 
   435 	CleanupClosePushL(theFile);
   436 
   437 	
   438 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   439 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   440 	CleanupStack::PushL(hBuffer);
   441 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   442 
   443 	// Read from position 0: start of file
   444 	returnCode = theFile.Read(ptrString);
   445 	
   446 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   447 										 //from the file
   448 
   449 	if (returnCode == KErrNotFound) // Check for the error message in the log
   450 		{
   451 		returnCode = ptrString.Find(KOOMError);
   452 		if (returnCode > 0)
   453 			User::Leave(KErrNoMemory);
   454 		}
   455 
   456 
   457 	CleanupStack::PopAndDestroy(hBuffer);
   458 	CleanupStack::PopAndDestroy();	//theFile
   459 	if (returnCode > 0)
   460 		return KErrNone;
   461 	else 
   462 		return KErrGeneral;
   463 	}
   464 
   465 
   466 
   467 
   468 
   469 /**
   470 * Function  Name	: CFloggerTest008_03
   471 * Input parameters	: None
   472 * Output parameters : None
   473 * Description		: This is the constructor
   474 */
   475 
   476 
   477 CFloggerTest008_03::CFloggerTest008_03()
   478 	{
   479 	// store the name of this test case
   480 	SetTestStepName(_L("step_008_03"));
   481 	
   482 	}
   483 
   484 
   485 
   486 /**
   487 * Function  Name	:~ CFloggerTest008_03
   488 * Input parameters	: None
   489 * Output parameters : None
   490 * Description		: This is the Destructor
   491 */
   492 
   493 
   494 CFloggerTest008_03::~CFloggerTest008_03()
   495 	{
   496 	}
   497 
   498 
   499 
   500 /**
   501 * Function  Name	: doTestStepL
   502 * Input parameters	: None
   503 * Output parameters : TVerdict 
   504 * Description		: This function returns weather the test case 004_01 has 
   505 * 					  passed or failed
   506 
   507 */
   508 
   509 
   510 TVerdict CFloggerTest008_03::doTestStepL( )
   511 	{
   512 	if ( executeStepL() == KErrNone )
   513 		SetTestStepResult(EPass);
   514 
   515 	else
   516 		SetTestStepResult(EFail);
   517 
   518 	User::After(KTimeForDisplay);
   519 	return TestStepResult();
   520 	}
   521 
   522 
   523 /**
   524 * Function  Name		: executeStepL
   525 * Input parameters		: None
   526 * Output parameters		: TInt 
   527 * Description 			: This function writes the test data in to the log file 
   528 * 						  This function check the test message is present in the 
   529 *						  log file 
   530 
   531 */
   532 
   533 
   534 TInt CFloggerTest008_03::executeStepL()
   535 	{
   536 	TInt ret = KErrGeneral;
   537 	
   538 	ret = DoTestConnect();
   539 	CleanupClosePushL(iFlogger);
   540 	if (ret == KErrNone)
   541 		ret = DoTestWrite();
   542 		if (ret == KErrNone)
   543 			ret = DoTestCheckWriteL();
   544 	
   545 	CleanupStack::PopAndDestroy();	//logger
   546 
   547 	User::After(1000000);
   548 	return ret;
   549 	}
   550 
   551 /**
   552 * Function  Name		: executeStepL
   553 * Input parameters		: None
   554 * Output parameters		: TInt 
   555 * Description 			: This function writes the test data in to the log file 
   556 * 						  This function check the test message is present in the 
   557 *						  log file 
   558 
   559 */
   560 
   561 
   562 TInt CFloggerTest008_03::executeStepL(TBool)
   563 	{
   564 	return KErrGeneral;
   565 	}
   566 
   567 /**
   568 * Function  Name		: DoTestConnect
   569 * Input parameters		: None
   570 * Output parameters		: TInt 
   571 * Description 			: This function establishes a connection to file logger
   572 * 						  and sets the system and component name in file logger.
   573 					  
   574 */
   575 
   576 
   577 TInt CFloggerTest008_03::DoTestConnect()
   578 	{	
   579 	TInt ret;
   580 	TPtrC8 ptrSubSystem;
   581 	TPtrC8 ptrComponent;
   582 	ptrSubSystem.Set(_L8("SubSystem"));
   583 	ptrComponent.Set(_L8("Component"));
   584 
   585 	ret = iFlogger.Connect(); //Call connect() of Flogger
   586 	
   587 	if (ret == KErrNone)
   588 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   589 	
   590 	return ret;
   591 	}
   592 
   593 
   594 /**
   595 Function  Name		: DoTestWrite
   596 * Input parameters		: None
   597 * Output parameters		: TInt 
   598 * Description 			: This function writes the data to the file logger
   599  
   600 */
   601 
   602 
   603 TInt CFloggerTest008_03::DoTestWrite()
   604 	{
   605 	//KTestLongMessage contains a very long test message 
   606 	_LIT(KTestLongMessage,"TC 8_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 ");
   607 
   608 	iFlogger.Write(KTestLongMessage); //this causes a PANIC
   609 	ForceLogFlush(iFlogger);	
   610 	return KErrNone; 
   611 	}
   612 
   613 
   614 /**
   615 * Function  Name		: DoTestCheckWriteL
   616 * Input parameters		: None
   617 * Output parameters		: TInt 
   618 * Description 			: This function checks the weather test data was written
   619 *						  in to the log file by DoTestWriteL() or not.
   620 					  
   621 */
   622 
   623 
   624 TInt CFloggerTest008_03::DoTestCheckWriteL()
   625 	{
   626 	User::After(KTimeToLog);
   627 	RFile theFile;
   628 	HBufC8 * hBuffer;
   629 	TInt listfilesize,returnCode;
   630 	RFs fileSystem; //For file operation create a file system
   631 	TBuf8<256> testData; //To hold the test descriptor
   632 	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   633 
   634 	//The following contains the string of length 200(max) 
   635 	//which is  written to the log file
   636 	//_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");
   637 	_LIT(KTestLongMessage, "TC 8_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");
   638 	
   639 	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   640 	
   641 	User::LeaveIfError(fileSystem.Connect());
   642 	
   643 	//Open the file in the read mode
   644 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   645 
   646 	CleanupClosePushL(theFile);
   647 
   648 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   649 	
   650 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   651 	CleanupStack::PushL(hBuffer);
   652 
   653 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   654 
   655 	// Read from position 0: start of file
   656 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   657 	
   658 	testData.Copy(KTestLongMessage); //Copy the test descriptor
   659 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   660 											//from the file
   661 
   662 	
   663 	CleanupStack::PopAndDestroy(hBuffer);
   664 	CleanupStack::PopAndDestroy();	//theFile
   665 	if (returnCode > 0)
   666 		return KErrNone;
   667 	else 
   668 		return KErrGeneral;
   669 	}
   670 
   671 
   672 
   673 
   674 
   675 /**
   676 * Function  Name	: CFloggerTest008_04
   677 * Input parameters	: None
   678 * Output parameters : None
   679 * Description		: This is the constructor
   680 */
   681 
   682 
   683 CFloggerTest008_04::CFloggerTest008_04()
   684 	{
   685 	// store the name of this test case
   686 	SetTestStepName(_L("step_008_04"));
   687 	}
   688 
   689 
   690 
   691 /**
   692 * Function  Name	:~ CFloggerTest008_04
   693 * Input parameters	: None
   694 * Output parameters : None
   695 * Description		: This is the Destructor
   696 */
   697 
   698 
   699 CFloggerTest008_04::~CFloggerTest008_04()
   700 	{
   701 	}
   702 
   703 
   704 
   705 /**
   706 
   707 *Function  Name : doTestStepL
   708 * Input parameters : None
   709 * Output parameters : TVerdict 
   710 * Description : This function is responsible for doing the heap test analysis 
   711 
   712 */
   713 
   714 TVerdict CFloggerTest008_04::doTestStepL( )
   715 	{
   716 	INFO_PRINTF1(_L("Step 008.04 called "));
   717 
   718 	CFloggerTest008_01* step008_01 = new CFloggerTest008_01;
   719 	CleanupStack::PushL(step008_01);
   720 	doTestStepWithHeapFailureL( *step008_01, 1, 20, KErrNone, ETrue);
   721 
   722 	CleanupStack::PopAndDestroy(step008_01);
   723 	
   724 	User::After(KTimeForDisplay);
   725 	return TestStepResult();
   726 	}
   727