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