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