os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_026_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 026.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 
    20 // Test system includes
    21 #include "teststepcomsdbg.h"
    22 #include "step_026_xx.h"
    23 
    24 #include <comms-infras/commsdebugutility.h>
    25 
    26 
    27 /**
    28 * Function  Name : CFloggerTest026_01
    29 * Input parameters : None
    30 * Output parameters : None
    31 * Description : This is the constructor
    32 */
    33 
    34 
    35 CFloggerTest026_01::CFloggerTest026_01()
    36 	{
    37 	// Store the name of this test case
    38 	SetTestStepName(_L("step_026_01"));
    39 	}
    40 
    41 
    42 /**
    43 * Function  Name :~ CFloggerTest026_01
    44 * Input parameters : None
    45 * Output parameters : None
    46 * Description : This is the Destructor
    47 */ 
    48 
    49 
    50 CFloggerTest026_01::~CFloggerTest026_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 026_01 has 
    60 * 					  passed or failed
    61 
    62 */
    63 
    64 
    65 TVerdict CFloggerTest026_01::doTestStepL( )
    66 	{
    67 	INFO_PRINTF1(_L("Step 026.01 called "));
    68 	User::After(KTimeForDisplay);
    69 
    70 
    71 	if ( executeStepL(EFalse) == KErrNone  )
    72 		SetTestStepResult(EPass);
    73 
    74 	else
    75 		SetTestStepResult(EFail);
    76 
    77 	INFO_PRINTF1(_L("leaving Step 026.01 "));
    78 	User::After(KTimeForDisplay);
    79 
    80 	
    81 	return TestStepResult();
    82 	}
    83 
    84 /**
    85 * Function  Name		: executeStepL
    86 * Input parameters		: None
    87 * Output parameters		: TInt 
    88 * Description 			: This function sets the subsystem and component name
    89 * 						  checks weather they are set in the log file correctly
    90 
    91 */
    92 
    93 
    94 TInt CFloggerTest026_01::executeStepL()
    95 	{
    96 	return KErrGeneral;
    97 	}
    98 /**
    99 * Function  Name		: executeStepL
   100 * Input parameters		: None
   101 * Output parameters		: TInt 
   102 * Description 			: This function sets the subsystem and component name
   103 * 						  checks weather they are set in the log file correctly
   104 
   105 */
   106 
   107 
   108 TInt CFloggerTest026_01::executeStepL(TBool heapTest)
   109 	{
   110 	return DoTestWrite(heapTest);
   111 	}
   112 
   113 
   114 /**
   115 * Function  Name		: DoTestWriteL
   116 * Input parameters		: None
   117 * Output parameters		: TInt 
   118 * Description 			: This function writes the data to the file logger
   119 					  
   120 */
   121 
   122 
   123 TInt CFloggerTest026_01::DoTestWrite(TBool heapTest)
   124 	{
   125 
   126 	_LIT8(KTestMessage ,"TC no 26: This is test message");
   127 	TPtrC8 ptrSubSystem;
   128 	TPtrC8 ptrComponent;
   129 	ptrSubSystem.Set(_L8("SubSystem"));
   130 	ptrComponent.Set(_L8("Component"));
   131 	
   132 	TInt ret = KErrNone;
   133 	RFileLogger theFlogger;
   134 
   135 	ret = theFlogger.Connect();
   136 	
   137 	if (ret == KErrNone)
   138 		{
   139 		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   140 		if (ret == KErrNone)
   141 			{
   142 			ret = theFlogger.ClearLog();
   143 			if (ret == KErrNone)
   144 				{
   145 				theFlogger.WriteBinary(KTestMessage);
   146 				ForceLogFlush(theFlogger);
   147 				TRAPD(r, ret = DoTestCheckWriteL());
   148 				if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   149 					{
   150 					ret = KErrNoMemory;
   151 					}
   152 				else if (r != KErrNone)
   153 					{
   154 					ret = r;
   155 					}
   156 				}
   157 			}
   158 		}
   159 		
   160 	theFlogger.Close();
   161 	return ret;
   162 
   163 	}
   164 
   165 
   166 /**
   167 * Function  Name		: DoTestCheckWriteL
   168 * Input parameters		: None
   169 * Output parameters		: TInt 
   170 * Description 			: This function checks the weather test data was written
   171 * 						  in to the log file by DoTestWriteL() or not.
   172 					  
   173 */
   174 
   175 
   176 TInt CFloggerTest026_01::DoTestCheckWriteL()
   177 	{
   178 	User::After(1000*1000);
   179 	RFile theFile;
   180 	HBufC8 * hBuffer;
   181 	TInt listfilesize,returnCode;
   182 	RFs iFileSystem; //For file operation create a file system
   183 	TBuf8<256> testData; //To hold the test descriptor
   184 	_LIT(KLogFile,"c:\\logs\\log.txt"); 
   185 
   186 	_LIT(KTestSystem, "SubSystem"); //Test sytem name
   187 	_LIT(KTestComponent, "Component"); //Test component name
   188 	_LIT8(KTestMessage ,"TC no 26: This is test message"); // Test descriptor
   189 
   190 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
   191 
   192 	User::LeaveIfError(iFileSystem.Connect());
   193 	
   194 	//Open the file in the read mode
   195 	User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny)); 
   196 	CleanupClosePushL(theFile);
   197 	
   198 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   199 	
   200 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   201 	CleanupStack::PushL(hBuffer);
   202 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   203 
   204 	// Read from position 0: start of file
   205 	returnCode = theFile.Read(ptrString);
   206 	
   207 	testData.Copy(KTestMessage); //Copy the test message 
   208 	returnCode = ptrString.Find(KTestMessage);	//find the test message  in the 
   209 											//buffer read from the file
   210 	if (returnCode == KErrNotFound)
   211 		{
   212 		returnCode = ptrString.Find(KOOMError);
   213 		if (returnCode > 0)
   214 			User::Leave(KErrNoMemory);
   215 		}
   216 
   217 	if (returnCode > 0) // Test message present
   218 		{
   219 		testData.Copy(KTestSystem); //Copy the test tag
   220 		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   221 												//buffer read from the file
   222 		}
   223 	if (returnCode > 0) // Test tag present
   224 		{
   225 		testData.Copy(KTestComponent); //Copy the test tag
   226 		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   227 												//buffer read from the file
   228 		}
   229 	CleanupStack::PopAndDestroy(hBuffer);
   230 	CleanupStack::PopAndDestroy();	//theFile
   231 
   232 	if (returnCode > 0) // Test tag present
   233 		return KErrNone;
   234 	else 
   235 		return KErrNotFound;
   236 	}
   237 
   238 
   239 
   240 
   241 
   242 /**
   243 * Function  Name : CFloggerTest026_02
   244 * Input parameters : None
   245 * Output parameters : None
   246 * Description : This is the constructor
   247 */
   248 
   249 
   250 CFloggerTest026_02::CFloggerTest026_02()
   251 	{
   252 	// store the name of this test case
   253 	SetTestStepName(_L("step_026_02"));
   254 	}
   255 
   256 
   257 /**
   258 * Function  Name :~ CFloggerTest026_02
   259 * Input parameters : None
   260 * Output parameters : None
   261 *Description : This is the Destructor
   262 */
   263 
   264 
   265 CFloggerTest026_02::~CFloggerTest026_02()
   266 	{
   267 	}
   268 
   269 
   270 /**
   271 * Function  Name : doTestStepL
   272 * Input parameters : None
   273 * Output parameters : TVerdict 
   274 * Description : This function is responsible for doing the heap test analysis 
   275 
   276 */
   277 
   278 TVerdict CFloggerTest026_02::doTestStepL( )
   279 	{
   280 	INFO_PRINTF1(_L("Step 026.02 called "));
   281 	User::After(KTimeForDisplay);
   282 
   283 	CFloggerTest026_01* step026_01 = new CFloggerTest026_01;
   284 	CleanupStack::PushL(step026_01);
   285 	doTestStepWithHeapFailureL( *step026_01, 1, 20, KErrNone, ETrue);
   286 	
   287 	CleanupStack::PopAndDestroy(step026_01);
   288 
   289 	return TestStepResult();
   290 	}
   291 
   292 
   293 /**
   294 * Function  Name : CFloggerTest026_03
   295 * Input parameters : None
   296 * Output parameters : None
   297 * Description : This is the constructor
   298 */
   299 
   300 
   301 CFloggerTest026_03::CFloggerTest026_03()
   302 	{
   303 	// Store the name of this test case
   304 	SetTestStepName(_L("step_026_03"));
   305 	}
   306 
   307 
   308 /**
   309 * Function  Name :~ CFloggerTest026_03
   310 * Input parameters : None
   311 * Output parameters : None
   312 * Description : This is the Destructor
   313 */ 
   314 
   315 
   316 CFloggerTest026_03::~CFloggerTest026_03()
   317 	{
   318 	}
   319 
   320 
   321 /**
   322 * Function  Name	: doTestStepL
   323 * Input parameters	: None
   324 * Output parameters : TVerdict 
   325 * Description		: This function returns weather the test case 026_01 has 
   326 * 					  passed or failed
   327 
   328 */
   329 
   330 
   331 TVerdict CFloggerTest026_03::doTestStepL( )
   332 	{
   333 	INFO_PRINTF1(_L("Step 026.03 called "));
   334 	User::After(KTimeForDisplay);
   335 
   336 
   337 	if ( executeStepL() == KErrNone  )
   338 		SetTestStepResult(EPass);
   339 
   340 	else
   341 		SetTestStepResult(EFail);
   342 
   343 	INFO_PRINTF1(_L("leaving Step 026.03 "));
   344 	User::After(KTimeForDisplay);
   345 
   346 	
   347 	return TestStepResult();
   348 	}
   349 
   350 
   351 /**
   352 * Function  Name		: executeStepL
   353 * Input parameters		: None
   354 * Output parameters		: TInt 
   355 * Description 			: This function sets the subsystem and component name
   356 * 						  checks weather they are set in the log file correctly
   357 
   358 */
   359 
   360 
   361 TInt CFloggerTest026_03::executeStepL()
   362 	{
   363 	return DoTestWrite();
   364 	}
   365 
   366 /**
   367 * Function  Name		: executeStepL
   368 * Input parameters		: None
   369 * Output parameters		: TInt 
   370 * Description 			: This function sets the subsystem and component name
   371 * 						  checks weather they are set in the log file correctly
   372 
   373 */
   374 
   375 
   376 TInt CFloggerTest026_03::executeStepL(TBool)
   377 	{
   378 	return KErrGeneral;
   379 	}
   380 
   381 /**
   382 * Function  Name		: DoTestWriteL
   383 * Input parameters		: None
   384 * Output parameters		: TInt 
   385 * Description 			: This function writes the data to the file logger
   386 					  
   387 */
   388 
   389 
   390 TInt CFloggerTest026_03::DoTestWrite()
   391 	{
   392 
   393 	_LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
   394 	TPtrC8 ptrSubSystem;
   395 	TPtrC8 ptrComponent;
   396 	ptrSubSystem.Set(_L8("SubSystem"));
   397 	ptrComponent.Set(_L8("Component"));
   398 	
   399 	TInt ret = KErrNone;
   400 	RFileLogger theFlogger;
   401 
   402 	ret = theFlogger.Connect();
   403 
   404 	if (ret == KErrNone)
   405 		{
   406 		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   407 		if (ret == KErrNone)
   408 			{
   409 			ret = theFlogger.ClearLog();
   410 			if (ret == KErrNone)
   411 				{
   412 				theFlogger.WriteBinary(KTestLongMessage);
   413 //				ForceLogFlush(theFlogger);
   414 				TRAPD(r, ret = DoTestCheckWriteL());
   415 				if (r != KErrNone)
   416 					ret = r;
   417 				}
   418 			}
   419 		}
   420 		
   421 	theFlogger.Close();
   422 
   423 	return ret;
   424 
   425 	}
   426 
   427 
   428 /**
   429 * Function  Name		: DoTestCheckWriteL
   430 * Input parameters		: None
   431 * Output parameters		: TInt 
   432 * Description 			: This function checks the weather test data was written
   433 * 						  in to the log file by DoTestWriteL() or not.
   434 					  
   435 */
   436 
   437 
   438 TInt CFloggerTest026_03::DoTestCheckWriteL()
   439 	{
   440 	_LIT8(KTestLongMessage,"TEST 26.3:#À!}!}!} }4}%}&´zß}}&} } } } }'}}(}!æ~.=¢ÛR.... .~ÿ}#À!}!}!} }4}%}&„¥T}9}}&}}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~)... .~. .ÿ}#À!}!}} }$µZ}'}}(}U­~... .~. -ÿ}#À!}}!} }4}%}&„¥T}9}}&} } } } }'}}(}¾Ä~... .~. .ÿ}#À!}!}$µZ"); //8 bit test decriptor
   441 	User::After(KTimeToLogLargeData);	// occasionally, KTimeToLog isn't quite long enough, so use longer time.
   442 	RFile theFile;
   443 	HBufC8 * hBuffer;
   444 	TInt listfilesize,returnCode;
   445 	RFs iFileSystem; //For file operation create a file system
   446 	_LIT(KLogFile,"c:\\logs\\log.txt"); 
   447 	TBuf8<256> testData; //To hold the test descriptor
   448 
   449 	_LIT(KTestSystem, "SubSystem"); //Test sytem name
   450 	_LIT(KTestComponent, "Component"); //Test component name
   451 	//_LIT8(KTestLongMessage,"TEST 26.3: 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"); //8 bit test decriptor
   452 	
   453 	
   454 	User::LeaveIfError(iFileSystem.Connect());
   455 	
   456 	//Open the file in the read mode
   457 	User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny)); 
   458 	CleanupClosePushL(theFile);
   459 	
   460 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   461 	
   462 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   463 	CleanupStack::PushL(hBuffer);
   464 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   465 
   466 	// Read from position 0: start of file
   467 	returnCode = theFile.Read(ptrString);
   468 	
   469 	//testData.Copy(KTestLongMessage); //Copy the test message 
   470 	returnCode = ptrString.Find(KTestLongMessage);	//find the test message in the 
   471 											//buffer read from the file
   472 
   473 	if (returnCode > 0) // Test message present
   474 		{
   475 		testData.FillZ();
   476 		testData.Copy(KTestSystem); //Copy the test tag
   477 		returnCode = ptrString.Find(testData);	//Find the test tag in the 
   478 												//buffer read from the file
   479 		}
   480 	if (returnCode > 0) // Test tag present
   481 		{
   482 		testData.FillZ();
   483 		testData.Copy(KTestComponent); //Copy the component name
   484 		returnCode = ptrString.Find(testData);	//Find the component name in the 
   485 												//buffer read from the file
   486 		}
   487 	
   488 	CleanupStack::PopAndDestroy(hBuffer);
   489 	CleanupStack::PopAndDestroy();	//theFile
   490 
   491 	if (returnCode > 0) // Test tag present
   492 		return KErrNone;
   493 	else 
   494 		return KErrGeneral;
   495 	}
   496 
   497 
   498 
   499