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