os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_006_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 006.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_006_xx.h"
    27 
    28 
    29 /**
    30 * Function  Name	: CFloggerTest006_01
    31 * Input parameters	: None
    32 * Output parameters : None
    33 * Description		: This is the constructor
    34 */
    35 
    36 
    37 CFloggerTest006_01::CFloggerTest006_01()
    38 	{
    39 	SetTestStepName(_L("step_006_01"));
    40 
    41 	}
    42 
    43 
    44 /**
    45 * Function  Name	:~ CFloggerTest006_01
    46 * Input parameters	: None
    47 * Output parameters : None
    48 * Description		: This is the Destructor
    49 */
    50 
    51 
    52 CFloggerTest006_01::~CFloggerTest006_01()
    53 	{
    54 	
    55 	}
    56 
    57 
    58 /**
    59 * Function  Name	: doTestStepL
    60 * Input parameters	: None
    61 * Output parameters : TVerdict 
    62 * Description		: This function returns weather the test case 006_01 has 
    63 * 					  passed or failed
    64 
    65 */
    66 
    67 
    68 TVerdict CFloggerTest006_01::doTestStepL( )
    69 	{
    70 	RFileLogger logger;
    71 	INFO_PRINTF1(_L("Step 006.01 called "));
    72 	
    73 	if ( executeStepL(EFalse) == KErrNone )
    74 		SetTestStepResult(EPass);
    75 
    76 	else
    77 		SetTestStepResult(EFail);
    78 
    79 	User::After(KTimeForDisplay);
    80 	return TestStepResult();
    81 	}
    82 
    83 
    84 /**
    85 * Function  Name		: executeStepL
    86 * Input parameters		: None
    87 * Output parameters		: TInt 
    88 * Description 			: This function writes the test data in to the log file 
    89 *						  This function check the test message is present in the 
    90 *						  log file or not.
    91 
    92 */
    93 
    94 
    95 TInt CFloggerTest006_01::executeStepL(TBool heapTest)
    96 	{
    97 	TInt ret = KErrNone;
    98 
    99 	ret = DoTestConnect();
   100 	CleanupClosePushL(iFlogger);
   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 	CleanupStack::PopAndDestroy();	//logger
   119 	return ret;
   120 	}
   121 
   122 /**
   123 * Function  Name		: executeStepL
   124 * Input parameters		: None
   125 * Output parameters		: TInt 
   126 * Description 			: This function writes the test data in to the log file 
   127 *						  This function check the test message is present in the 
   128 *						  log file or not.
   129 
   130 */
   131 
   132 
   133 TInt CFloggerTest006_01::executeStepL()
   134 	{
   135 	return KErrGeneral;
   136 	}
   137 
   138 /**
   139 * Function  Name		: DoTestWrite
   140 * Input parameters		: None
   141 * Output parameters		: TInt 
   142 * Description 			: This function writes the data to the file logger
   143  
   144 */
   145 
   146 
   147 TInt CFloggerTest006_01::DoTestWrite()
   148 	{
   149 	_LIT16(KTestMessageOne,"TC 006_01: The value of test integer variable :%d");// The value of second test integer variable : %d");
   150 	return DoTestWriteFormat(KTestMessageOne, 100);  //Write unicode formatted test descriptor
   151 	}
   152 
   153 
   154 /**
   155 * Function  Name		: DoTestWriteFormat
   156 * Input parameters		: TRefByValue<const TDesC16>
   157 * Output parameters		: TInt 
   158 * Description 			: This function writes formatted data to the file logger
   159  
   160 */
   161 
   162 
   163 TInt CFloggerTest006_01::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...)
   164 	{
   165 	VA_LIST list;
   166 	VA_START(list,aFmt);
   167 	iFlogger.WriteFormat(aFmt,list);
   168 
   169 	ForceLogFlush(iFlogger);
   170 	return KErrNone;
   171 	}
   172 
   173 
   174 /**
   175 * Function  Name		: DoTestCheckWriteL
   176 * Input parameters		: None
   177 * Output parameters		: TInt 
   178 * Description 			: This function checks the weather test data was written
   179 *						  in to the log file by DoTestWriteL() or not.
   180 					  
   181 */
   182 
   183 
   184 TInt CFloggerTest006_01::DoTestCheckWriteL()
   185 	{
   186 	User::After(KTimeToLog);
   187 
   188 	RFile theFile;
   189 	HBufC8 * hBuffer;
   190 	TInt listfilesize;
   191 	TInt returnCode;
   192 	RFs fileSystem; //For file operation create a file system	
   193 	TBuf8<256> testData; //To hold the test descriptor
   194 
   195 	_LIT8(KTestMessageOne,"TC 006_01: The value of test integer variable :%d");
   196 	testData.Format(KTestMessageOne,100);
   197 
   198 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); //Error message
   199 
   200 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   201 
   202 	User::LeaveIfError(fileSystem.Connect());
   203 	
   204 	//Open the file in the read mode
   205 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   206 
   207 	CleanupClosePushL(theFile);
   208 
   209 	
   210 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   211 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   212 	CleanupStack::PushL(hBuffer);
   213 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   214 
   215 	// Read from position 0: start of file
   216 	returnCode = theFile.Read(ptrString);
   217 	
   218 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   219 									//from the file
   220 
   221 	if (returnCode == KErrNotFound)  //Find the error message
   222 		{
   223 		returnCode = ptrString.Find(KOOMError);
   224 		if (returnCode > 0)
   225 			User::Leave(KErrNoMemory);
   226 		}
   227 
   228 
   229 	CleanupStack::PopAndDestroy(hBuffer);
   230 	CleanupStack::PopAndDestroy(); // For theFile object
   231 	if (returnCode > 0)
   232 		return KErrNone;
   233 	else 
   234 		return KErrNotFound;
   235 	}
   236 
   237 
   238 
   239 /**
   240 * Function  Name		: DoTestConnect
   241 * Input parameters		: None
   242 * Output parameters		: TInt 
   243 * Description 			: This function establishes a connection to file logger
   244 *						  and sets the system and component name in file logger.
   245 					  
   246 */
   247 
   248 
   249 TInt CFloggerTest006_01::DoTestConnect()
   250 	{
   251 	TInt ret = EFail;
   252 	TPtrC8 ptrSubSystem;
   253 	TPtrC8 ptrComponent;
   254 	ptrSubSystem.Set(_L8("SubSystem"));
   255 	ptrComponent.Set(_L8("Component"));
   256 
   257 	ret = iFlogger.Connect(); //Call connect() of Flogger
   258 	if (ret == KErrNone)
   259 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   260 
   261 	if (ret == KErrNone)
   262 		ret = iFlogger.ClearLog(); //clear the contents from the log
   263 	return ret;
   264 	}
   265 
   266 
   267 
   268 
   269 
   270 /**
   271 * Function  Name	: CFloggerTest006_02
   272 * Input parameters	: None
   273 * Output parameters : None
   274 * Description		: This is the constructor
   275 */
   276 
   277 
   278 CFloggerTest006_02::CFloggerTest006_02()
   279 	{
   280 	// store the name of this test case
   281 	SetTestStepName(_L("step_006_02"));
   282 	}
   283 
   284 
   285 /**
   286 * Function  Name	:~ CFloggerTest006_02
   287 * Input parameters	: None
   288 * Output parameters : None
   289 * Description		: This is the Destructor
   290 */
   291 
   292 
   293 CFloggerTest006_02::~CFloggerTest006_02()
   294 	{
   295 	}
   296 
   297 
   298 /**
   299 * Function  Name	: doTestStepL
   300 * Input parameters	: None
   301 * Output parameters : TVerdict 
   302 * Description		: This function returns weather the test case 006_02 has 
   303 * 					  passed or failed
   304 
   305 */
   306 
   307 
   308 TVerdict CFloggerTest006_02::doTestStepL( )
   309 	{
   310 	INFO_PRINTF1(_L("Step 006.02 called "));
   311 		
   312 	if ( executeStepL() == KErrNone )
   313 		SetTestStepResult(EPass);
   314 
   315 	else
   316 		SetTestStepResult(EFail);
   317 
   318 	
   319 	User::After(KTimeForDisplay);
   320 	return TestStepResult();
   321 	}
   322 
   323 
   324 /**
   325 * Function  Name		: executeStepL
   326 * Input parameters		: None
   327 * Output parameters		: TInt 
   328 * Description 			: This function writes the test data in to the log file 
   329 * 						  This function check the test message is present in the 
   330 *						  log file 
   331 
   332 */
   333 
   334 
   335 TInt CFloggerTest006_02::executeStepL()
   336 	{
   337 	TInt ret = KErrGeneral;
   338 	
   339 	ret = DoTestConnect();
   340 	CleanupClosePushL(iFlogger);
   341 	if (ret == KErrNone)
   342 		ret = DoTestWrite();
   343 		if (ret == KErrNone)
   344 			ret = DoTestCheckWriteL();
   345 	
   346 	CleanupStack::PopAndDestroy();	//logger
   347 
   348 	User::After(1000000);
   349 	return ret;
   350 	}
   351 
   352 /**
   353 * Function  Name		: executeStepL
   354 * Input parameters		: None
   355 * Output parameters		: TInt 
   356 * Description 			: This function writes the test data in to the log file 
   357 * 						  This function check the test message is present in the 
   358 *						  log file 
   359 
   360 */
   361 
   362 
   363 TInt CFloggerTest006_02::executeStepL(TBool)
   364 	{
   365 	return KErrGeneral;
   366 	}
   367 
   368 /**
   369 * Function  Name		: DoTestConnect
   370 * Input parameters		: None
   371 * Output parameters		: TInt 
   372 * Description 			: This function establishes a connection to file logger
   373 * 						  and sets the system and component name in file logger.
   374 					  
   375 */
   376 
   377 
   378 TInt CFloggerTest006_02::DoTestConnect()
   379 	{
   380 	TInt ret = KErrGeneral;
   381 	TPtrC8 ptrSubSystem;
   382 	TPtrC8 ptrComponent;
   383 	ptrSubSystem.Set(_L8("SubSystem"));
   384 	ptrComponent.Set(_L8("Component"));
   385 
   386 	ret = iFlogger.Connect(); //Call connect() of Flogger
   387 	if (ret == KErrNone)
   388 		ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
   389 
   390 	if (ret == KErrNone)
   391 		ret = iFlogger.ClearLog(); //clear the contents from the log
   392 	
   393 	return ret;
   394 	}
   395 
   396 
   397 /**
   398 * Function  Name		: DoTestWrite
   399 * Input parameters		: None
   400 * Output parameters		: TInt 
   401 * Description 			: This function writes the data to the file logger
   402  
   403 */
   404 
   405 
   406 TInt CFloggerTest006_02::DoTestWrite()
   407 	{
   408 	//KTestLongMessage contains a very long test message 
   409 	_LIT(KTestLongMessage,"TC 6_02: 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 %d");
   410 	DoTestWriteFormat(KTestLongMessage, 100); //this causes a PANIC
   411 	ForceLogFlush(iFlogger);	
   412 	
   413 	return KErrNone; 
   414 	}
   415 
   416 
   417 /**
   418 * Function  Name		: DoTestWriteFormat
   419 * Input parameters		: TRefByValue<const TDesC16>
   420 * Output parameters		: TInt 
   421 * Description 			: This function writes formatted data to the file logger
   422  
   423 */
   424 
   425 
   426 TInt CFloggerTest006_02::DoTestWriteFormat(TRefByValue<const TDesC16> aFmt,...)
   427 	{
   428 	VA_LIST list;
   429 	VA_START(list,aFmt);
   430 	TRAPD(res, iFlogger.WriteFormat(aFmt,list)); 
   431 	return res;
   432 	}
   433 
   434 
   435 /**
   436 * Function  Name		: DoTestCheckWriteL
   437 * Input parameters		: None
   438 * Output parameters		: TInt 
   439 * Description 			: This function checks the weather test data was written
   440 *						  in to the log file by DoTestWriteL() or not.
   441 					  
   442 */
   443 
   444 
   445 TInt CFloggerTest006_02::DoTestCheckWriteL()
   446 	{
   447 	User::After(KTimeToLog);
   448 	RFile theFile;
   449 	HBufC8 * hBuffer;
   450 	TInt listfilesize,returnCode;
   451 	RFs fileSystem; //For file operation create a file system
   452 	TBuf8<256> testData; //To hold the test descriptor
   453 	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   454 
   455 	//The following contains the string of length 200(max) 
   456 	//which is  written to the log file
   457 	//_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");
   458 	_LIT(KTestLongMessage, "TC 6_02: 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");
   459 	
   460 	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   461 	
   462 	User::LeaveIfError(fileSystem.Connect());
   463 	
   464 	//Open the file in the read mode
   465 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   466 
   467 	CleanupClosePushL(theFile);
   468 
   469 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   470 	
   471 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   472 	CleanupStack::PushL(hBuffer);
   473 
   474 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   475 
   476 	// Read from position 0: start of file
   477 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   478 	
   479 	testData.Copy(KTestLongMessage); //Copy the test descriptor
   480 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   481 											//from the file
   482 
   483 	
   484 	CleanupStack::PopAndDestroy(hBuffer);
   485 	CleanupStack::PopAndDestroy();	//theFile
   486 	if (returnCode > 0)
   487 		return KErrNone;
   488 	else 
   489 		return KErrGeneral;
   490 	
   491 
   492 }
   493 
   494 
   495 
   496 
   497 /**
   498 //Function  Name	: CFloggerTest006_03
   499 //Input parameters	: None
   500 //Output parameters : None
   501 //Description		: This is the constructor
   502 */
   503 
   504 
   505 CFloggerTest006_03::CFloggerTest006_03()
   506 	{
   507 	// store the name of this test case
   508 	SetTestStepName(_L("step_006_03"));
   509 	}
   510 
   511 
   512 /**
   513 * Function  Name	:~ CFloggerTest006_03
   514 * Input parameters	: None
   515 * Output parameters : None
   516 * Description		: This is the Destructor
   517 */
   518 
   519 
   520 CFloggerTest006_03::~CFloggerTest006_03()
   521 	{
   522 	
   523 	}
   524 
   525 
   526 
   527 /**
   528 * Function  Name : doTestStepL
   529 * Input parameters : None
   530 * Output parameters : TVerdict 
   531 * Description : This function is responsible for doing the heap test analysis 
   532 
   533 */
   534 
   535 
   536 TVerdict CFloggerTest006_03::doTestStepL( )
   537 	{
   538 	INFO_PRINTF1(_L("Step 006.03 called "));
   539 
   540 	CFloggerTest006_01* step006_01 = new CFloggerTest006_01;
   541 	CleanupStack::PushL(step006_01);
   542 	doTestStepWithHeapFailureL( *step006_01, 1, 20, KErrNone, ETrue);
   543 
   544 	CleanupStack::PopAndDestroy(step006_01);
   545 	User::After(KTimeForDisplay);
   546 	return TestStepResult();
   547 	}
   548