os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_003_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 003.xx
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 
    20 // Test system includes
    21 #include "teststepcomsdbg.h"
    22 #include "step_003_xx.h"
    23 
    24 #include <comms-infras/commsdebugutility.h>
    25 
    26 
    27 /**
    28 * Function  Name	: CFloggerTest003_01
    29 * Input parameters	: None
    30 * Output parameters : None
    31 * Description		: This is the constructor
    32 */
    33 
    34 
    35 CFloggerTest003_01::CFloggerTest003_01()
    36 	{
    37 	// Store the name of this test case
    38 	SetTestStepName(_L("step_003_01"));
    39 	}
    40 
    41 
    42 /**
    43 * Function  Name	:~ CFloggerTest003_01
    44 * Input parameters	: None
    45 * Output parameters : None
    46 * Description		: This is the Destructor
    47 */
    48 
    49 
    50 CFloggerTest003_01::~CFloggerTest003_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 003_01 has 
    60 *					  passed or failed
    61 
    62 */
    63 
    64 
    65 TVerdict CFloggerTest003_01::doTestStepL( )
    66 	{
    67 	User::After(KTimeForDisplay1);
    68 	INFO_PRINTF1(_L("Step 003.01 called "));
    69 
    70 	if ( executeStepL(EFalse) == KErrNone  )
    71 		SetTestStepResult(EPass);
    72 	else
    73 		SetTestStepResult(EFail);
    74 	
    75 	return TestStepResult();
    76 	}
    77 
    78 
    79 /**
    80 * Function  Name		: executeStepL
    81 * Input parameters		: None
    82 * Output parameters		: TInt 
    83 * Description 			: This function sets the subsystem and component name
    84 *						  checks weather they are set in the log file correctly
    85 
    86 */					  
    87 
    88 
    89 TInt CFloggerTest003_01::executeStepL(TBool heapTest)
    90 	{
    91 	return DoTestWrite(heapTest);
    92 	}
    93 
    94 /**
    95 * Function  Name		: executeStepL
    96 * Input parameters		: None
    97 * Output parameters		: TInt 
    98 * Description 			: This function sets the subsystem and component name
    99 *						  checks weather they are set in the log file correctly
   100 
   101 */					  
   102 
   103 
   104 TInt CFloggerTest003_01::executeStepL()
   105 	{
   106 	return KErrGeneral;
   107 	}
   108 
   109 /**
   110 * Function  Name		: DoTestWriteL
   111 * Input parameters		: None
   112 * Output parameters		: TInt 
   113 * Description 			: This function checks the weather test data was written
   114 						  in to the log file by DoTestWriteL() or not.
   115 					  
   116 */
   117 
   118 
   119 TInt CFloggerTest003_01::DoTestWrite(TBool heapTest)
   120 	{
   121 	_LIT8(KTestMessage ,"TC 3.01 :This is test msg");
   122 	TPtrC8 ptrSubSystem;
   123 	TPtrC8 ptrComponent;
   124 	ptrSubSystem.Set(_L8("SubSystem"));
   125 	ptrComponent.Set(_L8("Component"));
   126 
   127 	TInt ret = KErrNone;
   128 	RFileLogger theFlogger;
   129 
   130 	ret = theFlogger.Connect();
   131 	
   132 	if (ret == KErrNone)
   133 		{
   134 		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
   135 		if (ret == KErrNone)
   136 			{
   137 			ret = theFlogger.ClearLog();
   138 			if (ret == KErrNone)
   139 				{
   140 				theFlogger.Write(KTestMessage);
   141 				ForceLogFlush(theFlogger);
   142 				User::After(KTimeToLogLargeData);
   143 
   144 				TRAPD(r, ret = DoTestCheckWriteL());
   145 				if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
   146 					{
   147 					ret = KErrNoMemory;
   148 					}
   149 				else if (r != KErrNone)
   150 					{
   151 					ret = r;
   152 					}
   153 				}
   154 			}
   155 		}
   156 	theFlogger.Close();		
   157 	return ret;
   158 	}
   159 
   160 
   161 /**
   162 * Function  Name		: DoTestCheckWriteL
   163 * Input parameters		: None
   164 * Output parameters		: TInt 
   165 * Description 			: This function checks the weather test data was written
   166 * 						  in to the log file by DoTestWriteL() or not.
   167 					  
   168 */
   169 
   170 
   171 TInt CFloggerTest003_01::DoTestCheckWriteL()
   172 	{
   173 	TPtrC8 ptrSubSystem;
   174 	TPtrC8 ptrComponent;
   175 	ptrSubSystem.Set(_L8("SubSystem"));
   176 	ptrComponent.Set(_L8("Component"));
   177 	RFile theFile;
   178 
   179 	HBufC8 * hBuffer;
   180 	TInt listfilesize,returnCode;
   181 	RFs iFileSystem; //For file operation create a file system
   182 	TBuf8<256> testData; //To hold the test descriptor
   183 	_LIT(KLogFile,"c:\\logs\\log.txt"); 
   184 
   185 	_LIT(KTestSystem, "SubSystem"); //Test sytem name
   186 	_LIT(KTestComponent, "Component"); //Test component name
   187 	_LIT8(KTestMessage ,"TC 3.01 :This is test msg"); // Test descriptor
   188 	_LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
   189 
   190 	User::LeaveIfError(iFileSystem.Connect());
   191 	
   192 	//Open the file in the read mode
   193 	User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny)); 
   194 	CleanupClosePushL(theFile);
   195 	
   196 	User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
   197 	
   198 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   199 	CleanupStack::PushL(hBuffer);
   200 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   201 
   202 	// Read from position 0: start of file
   203 	returnCode = theFile.Read(ptrString);
   204 	
   205 	testData.Copy(KTestMessage); //Copy the test message name
   206 	returnCode = ptrString.Find(KTestMessage);	//find the test system name in the 
   207 											//buffer read from the file
   208 	if (returnCode == KErrNotFound)
   209 		{
   210 		User::Leave(KErrNotFound);
   211 		}
   212 
   213 	returnCode = ptrString.Find(KOOMError);
   214 	if (returnCode > 0)
   215 		{
   216 		User::Leave(KErrNoMemory);
   217 		}
   218 
   219 	testData.Copy(KTestSystem);				//Copy the test subsystem name
   220 	returnCode = ptrString.Find(testData);	//Find the test subsystem name in the 
   221 												//buffer read from the file
   222 
   223 	if (returnCode > 0) // Test subsystem name present
   224 		{
   225 		testData.Copy(KTestComponent);			//Copy the test component name
   226 		returnCode = ptrString.Find(testData);	//Find the test component name in the 
   227 												//buffer read from the file
   228 		}
   229 	
   230 	CleanupStack::PopAndDestroy(hBuffer);
   231 	CleanupStack::PopAndDestroy();	//theFile
   232 
   233 	if (returnCode > 0) // Test component name present
   234 		return KErrNone;
   235 	else 
   236 		return KErrNotFound;
   237 	}
   238 
   239 
   240 
   241 
   242 
   243 /**
   244 * Function  Name	: CFloggerTest003_02
   245 * Input parameters	: None
   246 * Output parameters : None
   247 * Description		: This is the constructor
   248 */
   249 
   250 
   251 CFloggerTest003_02::CFloggerTest003_02()
   252 	{	
   253 	// store the name of this test case
   254 	SetTestStepName(_L("step_003_02"));
   255 	}
   256 
   257 
   258 /**
   259 * Function  Name	:~ CFloggerTest003_02
   260 * Input parameters	: None
   261 * Output parameters : None
   262 * Description		: This is the Destructor
   263 */
   264 
   265 
   266 CFloggerTest003_02::~CFloggerTest003_02()
   267 	{
   268 	}
   269 
   270 
   271 /**
   272 * Function  Name	: doTestStepL
   273 * Input parameters	: None
   274 * Output parameters : TVerdict 
   275 * Description		: This function returns weather the test case 003_02 has 
   276 *					  passed or failed
   277 
   278 */
   279 
   280 
   281 TVerdict CFloggerTest003_02::doTestStepL( )
   282 	{	
   283 	// INFO_PRINTF1(_L("Step 003.02 called ")); // This line was panicing in release mode testing
   284 		
   285 	if ( executeStepL() == KErrNone )
   286 		SetTestStepResult(EFail);
   287 	else
   288 		SetTestStepResult(EPass);
   289 
   290 	
   291 	return TestStepResult();
   292 	}
   293 
   294 
   295 /**
   296 * Function  Name		: executeStepL
   297 * Input parameters		: None
   298 * Output parameters		: TInt 
   299 * Description 			: This function writes the test data in to the log file 
   300 *						  This function check the test message is present in the 
   301 * 						  log file 
   302 
   303 */
   304 
   305 
   306 TInt CFloggerTest003_02::executeStepL()
   307 	{
   308 	return DoTestWrite() ;
   309 	}
   310 
   311 /**
   312 * Function  Name		: executeStepL
   313 * Input parameters		: None
   314 * Output parameters		: TInt 
   315 * Description 			: This function writes the test data in to the log file 
   316 *						  This function check the test message is present in the 
   317 * 						  log file 
   318 
   319 */
   320 
   321 
   322 TInt CFloggerTest003_02::executeStepL(TBool)
   323 	{
   324 	return KErrGeneral;
   325 	}
   326 /**
   327 * Function  Name		: DoTestWriteL
   328 * Input parameters		: None
   329 * Output parameters		: TInt 
   330 * Description 			: This function writees the data to the file logger
   331  
   332 */
   333 
   334 
   335 TInt CFloggerTest003_02::DoTestWrite()
   336 	{
   337 	_LIT(KTestMessage,"This is test message ");
   338 
   339 	//Call Write() before SetLogTags(), this will cause a PANIC
   340 
   341 	iFlogger.Connect();
   342 	iFlogger.Write(KTestMessage);
   343 	iFlogger.Close();
   344 			
   345 	//This test will cause a PANIC, so we will never get here
   346 	return KErrNone;
   347 	}
   348 
   349 
   350 /**
   351 * Function  Name	: CFloggerTest003_03
   352 * Input parameters	: None
   353 * Output parameters : None
   354 * Description		: This is the constructor
   355 */
   356 
   357 
   358 CFloggerTest003_03::CFloggerTest003_03()
   359 	{
   360 	// store the name of this test case
   361 	SetTestStepName(_L("step_003_03"));
   362 	}
   363 
   364 
   365 /**
   366 * Function  Name :~ CFloggerTest003_03
   367 * Input parameters : None
   368 * Output parameters : None
   369 * Description : This is the Destructor
   370 */
   371 
   372 
   373 CFloggerTest003_03::~CFloggerTest003_03()
   374 	{
   375 	}
   376 
   377 
   378 /**
   379 * Function  Name	: doTestStepL
   380 * Input parameters	: None
   381 * Output parameters : TVerdict 
   382 * Description		: This function is responsible for doing the heap test analysis 
   383 
   384 */
   385 
   386 TVerdict CFloggerTest003_03::doTestStepL( )
   387 	{
   388 	INFO_PRINTF1(_L("Step 003.03 called "));
   389 
   390 	CFloggerTest003_01* step003_01 = new CFloggerTest003_01;
   391 	CleanupStack::PushL(step003_01);
   392 	if (doTestStepWithHeapFailureL( *step003_01, 450, 465, KErrNone, ETrue) != KErrNone)
   393 		{
   394 		SetTestStepResult(EFail);
   395 		}
   396 	
   397 	CleanupStack::PopAndDestroy(step003_01);
   398 	User::After(KTimeForDisplay);
   399 	return TestStepResult();
   400 	}
   401