os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_023_01.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 023.01
    15 
    16 // EPOC includes
    17 #include <e32base.h>
    18 
    19 // Test system includes
    20 #include "teststepcomsdbg.h"
    21 #include "step_023_01.h"
    22 
    23 
    24 #include <comms-infras/commsdebugutility.h>
    25 
    26 
    27 /**
    28 * Function  Name	: CFloggerTest023_01
    29 * Input parameters	: None
    30 * Output parameters : None
    31 * Description		: This is the constructor
    32 */
    33 
    34 CFloggerTest023_01::CFloggerTest023_01()
    35 	{
    36 	// store the name of this test case
    37 	SetTestStepName(_L("step_023_01"));
    38 	}
    39 
    40 
    41 /**
    42 * Function  Name	:~ CFloggerTest023_01
    43 * Input parameters	: None
    44 * Output parameters : None
    45 * Description		: This is the Destructor
    46 */
    47 
    48 
    49 CFloggerTest023_01::~CFloggerTest023_01()
    50 	{
    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 023_01 has 
    60 * 					  passed or failed
    61 
    62 */
    63 
    64 
    65 TVerdict CFloggerTest023_01::doTestStepL( )
    66 	{
    67 	if ( executeStepL() == KErrNone )
    68 		SetTestStepResult(EPass);
    69 
    70 	else
    71 		SetTestStepResult(EFail);
    72 
    73 	
    74 	return TestStepResult();
    75 	}
    76 
    77 TInt CFloggerTest023_01::executeStepL(TBool)
    78 	{
    79 	return KErrGeneral;
    80 	}
    81 
    82 TInt CFloggerTest023_01::executeStepL( )
    83 	{
    84 	TInt ret = KErrGeneral;
    85 	ret = DoTestWrite();
    86 	if ( ret == KErrNone)
    87 		{
    88 		TRAPD(r, ret = DoTestCheckWriteL());
    89 		if ( r != KErrNone)
    90 			ret = r;
    91 		}
    92 	return ret;
    93 	}
    94 
    95 
    96 /**
    97 * Function  Name		: DoTestWrite
    98 * Input parameters		: None
    99 * Output parameters		: TInt 
   100 * Description 			: This function writes the test data in to the log file 
   101 					  
   102 */
   103 
   104 
   105 TInt CFloggerTest023_01::DoTestWrite()
   106 	{
   107 	INFO_PRINTF1(_L("Step 023.01 called "));
   108 
   109 	RFileLogger theFlogger;
   110 	TPtrC8 ptrSubSystem;
   111 	TPtrC8 ptrComponent;
   112 	ptrSubSystem.Set(_L8("SubSystem")); //Test system name
   113 	ptrComponent.Set(_L8("Component")); //Test component name
   114 	_LIT8(KTestMessage,"This is the test message"); //Test decriptor
   115 
   116 	TInt ret = KErrGeneral;
   117 	ret = theFlogger.Connect();
   118 
   119 	if (ret == KErrNone) // To Write the test descriptor the following lines are used.
   120 	{
   121 		ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent); //To set the tags 
   122 		if (ret == KErrNone)
   123 		{
   124 			theFlogger.Write(KTestMessage);
   125 			theFlogger.__DbgShutDownServer();
   126 			theFlogger.Close();	
   127 		}
   128 	}
   129 
   130 	User::After(100*1000);	//Need this or connect will return KErrServerTerminated
   131 
   132 	if (ret == KErrNone) // To actually test the ClearLog() functionality
   133 		ret = theFlogger.Connect();
   134 		if (ret == KErrNone)
   135 			ret = theFlogger.SetLogTags(ptrSubSystem,ptrComponent);
   136 			if (ret == KErrNone)
   137 			{
   138 				theFlogger.ClearLog(); //ClearLog called to clear the log message
   139 				theFlogger.__DbgShutDownServer();
   140 				User::After(100*1000);	//need this to give server time to clear the log
   141 				theFlogger.Close();
   142 			}
   143 
   144 	theFlogger.Close();
   145 	return ret;
   146 	}
   147 
   148 
   149 /**
   150 * Function  Name		: DoTestCheckWriteL
   151 * Input parameters		: None
   152 * Output parameters		: TInt 
   153 * Description 			: This function writes the data to the file logger
   154  
   155 */
   156 
   157 
   158 TInt CFloggerTest023_01::DoTestCheckWriteL()
   159 	{
   160 	RFile theFile;
   161 	HBufC8 * hBuffer;
   162 	TInt listfilesize;
   163 	TInt returnCode;
   164 	RFs fileSystem; //For file operation create a file system
   165 	TBuf8<256> testData; //To hold the test descriptor
   166 	_LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
   167 
   168 	_LIT8(KTestMessage,"This is the test message"); //Test decriptor
   169 	_LIT8(KSystemName,"SubSystem"); //Test subsystem name
   170 	_LIT8(KComponentName,"Component");// Test component name
   171 
   172 	User::LeaveIfError(fileSystem.Connect()); //Connect to the file server
   173 	
   174 	//Open the file in the read mode
   175 	User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead)); 
   176 	CleanupClosePushL(theFile);
   177 	
   178 	User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
   179 	hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
   180 	CleanupStack::PushL(hBuffer);
   181 	TPtr8 ptrString = hBuffer->Des();  ; //To hold the buffer
   182 
   183 	// Read from position 0: start of file
   184 	returnCode = theFile.Read(ptrString);
   185 	
   186 	testData.Copy(KTestMessage); //Copy the test descriptor
   187 	returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
   188 									//from the file
   189 	
   190 	if (returnCode < 0) //Note test message should not be present
   191 		{
   192 		testData.Copy(KSystemName); //Note test system name should not be present
   193 		returnCode = ptrString.Find(testData); //find the test system in the buffer read
   194 									//from the file
   195 		}
   196 	
   197 	if (returnCode < 0) //Note test component name should not be present
   198 		{
   199 		testData.Copy(KComponentName); //Note test message should not be present
   200 		returnCode = ptrString.Find(testData); //find the test component in the buffer read
   201 									//from the file
   202 		}
   203 
   204 	CleanupStack::PopAndDestroy(hBuffer);
   205 	CleanupStack::PopAndDestroy();	//theFile
   206 
   207 	if (returnCode < 0)
   208 		return KErrNone;
   209 	else 
   210 		return KErrGeneral;
   211 
   212 	}
   213 
   214 
   215 /**
   216 * Function  Name	: CFloggerTest023_02
   217 * Input parameters	: None
   218 * Output parameters : None
   219 * Description		: This is the Constructor
   220 */
   221 
   222 
   223 CFloggerTest023_02::CFloggerTest023_02()
   224 	{
   225 	// store the name of this test case
   226 	SetTestStepName(_L("step_023_02"));
   227 	}
   228 
   229 
   230 
   231 /**
   232 * Function  Name	:~ CFloggerTest023_02
   233 * Input parameters	: None
   234 * Output parameters : None
   235 * Description		: This is the Destructor
   236 */ 
   237 
   238 
   239 CFloggerTest023_02::~CFloggerTest023_02()
   240 	{
   241 	}
   242 
   243 
   244 
   245 /**
   246 * Function  Name	: doTestStepL
   247 * Input parameters	: None
   248 * Output parameters : TVerdict 
   249 * Description		: This function returns weather the test case 023_02 has 
   250 * 					  passed or failed
   251 
   252 */
   253 
   254 
   255 TVerdict CFloggerTest023_02::doTestStepL( )
   256 	{
   257 	// INFO_PRINTF1(_L("Step 023.01 called ")); // This line was panicing in release mode testing
   258 
   259 	if ( executeStepL() == KErrNone )
   260 		SetTestStepResult(EPass);
   261 
   262 	else
   263 		SetTestStepResult(EFail);
   264 
   265 	
   266 	return TestStepResult();
   267 	}
   268 
   269 TInt CFloggerTest023_02::executeStepL(TBool)
   270 	{
   271 	return KErrGeneral;
   272 	}
   273 	
   274 TInt CFloggerTest023_02::executeStepL( )
   275 	{
   276 	TPtrC8 ptrSubSystemTmp;
   277 	TPtrC8 ptrComponentTmp;
   278 	ptrSubSystemTmp.Set(_L8("SubSystem"));
   279 	ptrComponentTmp.Set(_L8("Component"));
   280 
   281 		RFileLogger theLogger;
   282 		theLogger.Connect();
   283 		theLogger.ClearLog(); // This line of code panics since it is called prior to SetLogTags()!!!!
   284 		theLogger.SetLogTags(ptrSubSystemTmp,ptrComponentTmp);
   285 		return KErrNone;
   286 	}
   287