os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_016_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 016.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 // Test system includes
    20 #include "TestMessage.h"
    21 #include <comms-infras/commsdebugutility.h>
    22 #include <f32file.h>
    23 
    24 
    25 //User includes
    26 #include "teststepcomsdbg.h"
    27 #include "step_016_xx.h"
    28 
    29 
    30 /**
    31 * Function  Name	: CFloggerTest016_01
    32 * Input parameters	: None
    33 * Output parameters : None
    34 * Description		: This is the constructor
    35 */
    36 
    37 
    38 CFloggerTest016_01::CFloggerTest016_01()
    39 	{
    40 	// store the name of this test case
    41 	SetTestStepName(_L("step_016_01"));
    42 	}
    43 
    44 
    45 /**
    46 * Function  Name	:~ CFloggerTest016_01
    47 * Input parameters	: None
    48 * Output parameters : None
    49 * Description		: This is the Destructor
    50 */
    51 
    52 
    53 CFloggerTest016_01::~CFloggerTest016_01()
    54 	{
    55 	}
    56 
    57 /**
    58 * Function  Name	: doTestStepL
    59 * Input parameters	: None
    60 * Output parameters : TVerdict 
    61 * Description		: This function returns weather the test case 016_01 has 
    62 * 					  passed or failed
    63 
    64 */
    65 
    66 
    67 TVerdict CFloggerTest016_01::doTestStepL( )
    68 	{
    69 	INFO_PRINTF1(_L("Step 016.01 called "));
    70 	
    71 	if ( executeStepL(EFalse) == KErrNone )
    72 		SetTestStepResult(EPass);
    73 
    74 	else
    75 		SetTestStepResult(EFail);
    76 
    77 	
    78 	User::After(KTimeForDisplay1);
    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 
    90 
    91 */
    92 
    93 
    94 TInt CFloggerTest016_01::executeStepL(TBool heapTest)
    95 	{
    96 	TInt ret = KErrGeneral;
    97 	
    98 	ret = DoTestWrite();
    99 	if (ret == KErrNone )
   100 		{
   101 		User::After(KTimeToLog);
   102 		TRAPD(r, ret = DoTestCheckWriteL() );
   103 		if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   104 			{
   105 			ret = KErrNoMemory;
   106 			}
   107 		else if (r != KErrNone)
   108 			{
   109 			ret = r;
   110 			}
   111 		}
   112 	return ret;
   113 	}
   114 /**
   115 * Function  Name		: executeStepL
   116 * Input parameters		: None
   117 * Output parameters		: TInt 
   118 * Description 			: This function writes the test data in to the log file 
   119 * 						  This function check the test message is present in the 
   120 * 						  log file 
   121 
   122 */
   123 
   124 
   125 TInt CFloggerTest016_01::executeStepL()
   126 	{
   127 	return KErrGeneral;
   128 	}
   129 
   130 /**
   131 * Function  Name		: DoTestWrite
   132 * Input parameters		: None
   133 * Output parameters		: TInt 
   134 * Description 			: This function writes the data to the file logger
   135  
   136 */
   137 
   138 
   139 TInt CFloggerTest016_01::DoTestWrite()
   140 	{
   141 	_LIT8(KTestMessageOne,"TC 16_01: The value of test integer variable :%d");
   142 	DoTestWriteFormat(KTestMessageOne, 100);  //Write 8 bit formatted test descriptor
   143 
   144 	// connect so we can flush file buffer for heap check since timer is killed in heap checks
   145 	RFileLogger theFlogger;
   146 	theFlogger.Connect();
   147 	theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   148 	ForceLogFlush(theFlogger);
   149 	theFlogger.Close();
   150 	return KErrNone; 
   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 TInt CFloggerTest016_01::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
   163 	{
   164 	VA_LIST list;
   165 	VA_START(list,aFmt);
   166 	RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list);
   167 	return KErrNone;
   168 	}
   169 
   170 
   171 /**
   172 * Function  Name		: DoTestCheckWriteL
   173 * Input parameters		: None
   174 * Output parameters		: TInt 
   175 * Description 			: This function checks the weather test data was written
   176 * 						  in to the log file by DoTestWrite() or not.
   177 					  
   178 */
   179 
   180 
   181 TInt CFloggerTest016_01::DoTestCheckWriteL()
   182 	{
   183 	User::After(KTimeToLog);
   184 
   185 	RFile theFile;
   186 	HBufC8 * hBuffer;
   187 	TInt listfilesize;
   188 	TInt returnCode;
   189 	RFs fileSystem; //For file operation create a file system	
   190 	TBuf8<256> testData; //To hold the test descriptor
   191 
   192 	_LIT8(KTestMessageOne,"TC 16_01: The value of test integer variable :%d");
   193 	testData.Format(KTestMessageOne, 100);
   194 
   195 	_LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
   196 
   197 	User::LeaveIfError(fileSystem.Connect());
   198 	
   199 	//Open the file in the read mode
   200 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   201 
   202 	
   203 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   204 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   205 	CleanupStack::PushL(hBuffer);
   206 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   207 
   208 	// Read from position 0: start of file
   209 	returnCode = theFile.Read(ptrString);
   210 	
   211 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   212 										//from the file
   213 	theFile.Close();
   214 	fileSystem.Close(); //Close the file server
   215 	CleanupStack::PopAndDestroy(hBuffer);
   216 	if (returnCode > 0)
   217 		return KErrNone;
   218 	else 
   219 		return KErrNotFound;
   220 	}
   221 
   222 
   223 
   224 
   225 /**
   226 * Function  Name	: CFloggerTest016_02
   227 * Input parameters	: None
   228 * Output parameters : None
   229 * Description		: This is the constructor
   230 */ 
   231 
   232 
   233 CFloggerTest016_02::CFloggerTest016_02()
   234 	{
   235 	// store the name of this test case
   236 	SetTestStepName(_L("step_016_02"));
   237 	}
   238 
   239 
   240 /**
   241 * Function  Name	:~ CFloggerTest016_02
   242 * Input parameters	: None
   243 * Output parameters : None
   244 * Description		: This is the Destructor
   245 */ 
   246 
   247 
   248 CFloggerTest016_02::~CFloggerTest016_02()
   249 	{
   250 	iFlogger.Close();
   251 	}
   252 
   253 
   254 /**
   255 * Function  Name	: doTestStepL
   256 * Input parameters	: None
   257 * Output parameters : TVerdict 
   258 * Description		: This function returns weather the test case 016_01 has 
   259 * 					  passed or failed
   260 
   261 */
   262 
   263 
   264 TVerdict CFloggerTest016_02::doTestStepL( )
   265 	{
   266 	INFO_PRINTF1(_L("Step 016.02 called "));
   267 	if ( executeStepL() == KErrNone )
   268 		SetTestStepResult(EPass);
   269 
   270 	else
   271 		SetTestStepResult(EFail);
   272 
   273 	
   274 	User::After(KTimeForDisplay1);
   275 	return TestStepResult();				
   276 	}
   277 
   278 /**
   279 * Function  Name		: executeStepL
   280 * Input parameters		: None
   281 * Output parameters		: TInt 
   282 * Description 			: This function writes the test data in to the log file 
   283 * 						  This function check the test message is present in the 
   284 * 						  log file 
   285 
   286 */
   287 
   288 
   289 TInt CFloggerTest016_02::executeStepL(TBool)
   290 	{
   291 	return KErrGeneral;
   292 	}
   293 /**
   294 * Function  Name		: executeStepL
   295 * Input parameters		: None
   296 * Output parameters		: TInt 
   297 * Description 			: This function writes the test data in to the log file 
   298 * 						  This function check the test message is present in the 
   299 * 						  log file 
   300 
   301 */
   302 
   303 
   304 TInt CFloggerTest016_02::executeStepL()
   305 	{
   306 	User::After(1000*1000);	//Need this or connect will return KErrServerTerminated
   307 	TInt j = 0;
   308 	for(TInt i=0; i < 100000000; i++)
   309 		j++;
   310 
   311 	TInt ret = KErrGeneral;
   312 	ret = DoTestWrite();
   313 	if (ret == KErrNone )
   314 		{
   315 		TRAPD(r, ret = DoTestCheckWriteL());
   316 		if ( r != KErrNone)
   317 			ret = r;
   318 		}
   319 	return ret;
   320 	}
   321 
   322 
   323 TInt CFloggerTest016_02::DoTestWrite()
   324 	{
   325 	_LIT8(KTestLongMessage,"TEST 16.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"); //8 bit test decriptor
   326 	DoTestWriteFormat(KTestLongMessage, 100);  //Write 8 bit formatted test descriptor
   327 	return KErrNone; 
   328 	}
   329 
   330 
   331 /**
   332 * Function  Name		: DoTestWriteFormat
   333 * Input parameters		: TRefByValue<const TDesC16>
   334 * Output parameters		: TInt 
   335 * Description 			: This function writes formatted data to the file logger
   336 */
   337 
   338 
   339 TInt CFloggerTest016_02::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
   340 	{
   341 
   342 	RFileLogger theFlogger;
   343 	TInt ret = KErrGeneral;
   344 	ret = theFlogger.Connect(); //Just to clear the old log message
   345 	if ( ret == KErrNone)
   346 		ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
   347 		if ( ret == KErrNone)
   348 			ret = theFlogger.ClearLog();
   349 			if ( ret == KErrNone)
   350 				theFlogger.Close();
   351 	
   352 	User::After(100000);
   353 	
   354 	if (ret == KErrNone)
   355 		{
   356 		VA_LIST list;
   357 		VA_START(list,aFmt);
   358 		
   359 		RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list);
   360 		User::After(100000);
   361 		return KErrNone;
   362 		}
   363 
   364 	return ret;
   365 	}
   366 
   367 
   368 /**
   369 * Function  Name		: DoTestCheckWriteL
   370 * Input parameters		: None
   371 * Output parameters		: TInt 
   372 * Description 			: This function checks the weather test data was written
   373 * 						  in to the log file by DoTestWrite() or not.
   374 					  
   375 */
   376 
   377 
   378 TInt CFloggerTest016_02::DoTestCheckWriteL()
   379 	{
   380 	User::After(KTimeToLog);
   381 
   382 	RFile theFile;
   383 	HBufC8 * hBuffer;
   384 	TInt listfilesize,returnCode;
   385 	RFs fileSystem; //For file operation create a file system
   386 	TBuf8<256> testData; //To hold the test descriptor
   387 	_LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
   388 
   389 	//The following contains the string of length 200(max) 
   390 	//which is  written to the log file
   391 	//_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");
   392 	_LIT(KTestLongMessage, "TEST 16.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 l");
   393 	
   394 	//_LIT8(KOOMError, "#Logs may be lost out of memory!!");
   395 	
   396 	User::LeaveIfError(fileSystem.Connect());
   397 	
   398 	//Open the file in the read mode
   399 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   400 
   401 	CleanupClosePushL(theFile);
   402 
   403 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   404 	
   405 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   406 	CleanupStack::PushL(hBuffer);
   407 
   408 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   409 
   410 	// Read from position 0: start of file
   411 	User::LeaveIfError(returnCode = theFile.Read(ptrString));
   412 	
   413 	testData.Copy(KTestLongMessage); //Copy the test descriptor
   414 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   415 											//from the file
   416 	
   417 	CleanupStack::PopAndDestroy(hBuffer);
   418 	CleanupStack::PopAndDestroy();	//theFile
   419 	if (returnCode > 0)
   420 		return KErrNone;
   421 	else 
   422 		return KErrGeneral;
   423 	}
   424 
   425 
   426 /**
   427 * Function  Name	: CFloggerTest016_03
   428 * Input parameters	: None
   429 * Output parameters : None
   430 * Description		: This is the constructor
   431 */ 
   432 
   433 
   434 CFloggerTest016_03::CFloggerTest016_03()
   435 	{
   436 	// store the name of this test case
   437 	SetTestStepName(_L("step_016_03"));
   438 	}
   439 
   440 
   441 /**
   442 * Function  Name	:~ CFloggerTest016_03
   443 * Input parameters	: None
   444 * Output parameters : None
   445 * Description		: This is the Destructor
   446 */ 
   447 
   448 
   449 CFloggerTest016_03::~CFloggerTest016_03()
   450 	{
   451 	}
   452 
   453 
   454 /**
   455 * Function  Name : doTestStepL
   456 * Input parameters : None
   457 * Output parameters : TVerdict 
   458 * Description : This function is responsible for doing the heap test analysis 
   459 
   460 */
   461 
   462 
   463 TVerdict CFloggerTest016_03::doTestStepL( )
   464 	{
   465 	INFO_PRINTF1(_L("Step 016.03 called "));
   466 
   467 	CFloggerTest016_01* step016_01 = new CFloggerTest016_01;
   468 	CleanupStack::PushL(step016_01);
   469 	doTestStepWithHeapFailureL( *step016_01, 1, 20, KErrNone, ETrue);
   470 
   471 	CleanupStack::PopAndDestroy(step016_01);
   472 	User::After(KTimeForDisplay);
   473 	return TestStepResult();
   474 	}
   475