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