os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_016_xx.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_016_xx.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,475 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This contains Flogger Unit Test Case 016.xx
1.18 +
1.19 +// EPOC includes
1.20 +#include <e32base.h>
1.21 +
1.22 +// Test system includes
1.23 +#include "TestMessage.h"
1.24 +#include <comms-infras/commsdebugutility.h>
1.25 +#include <f32file.h>
1.26 +
1.27 +
1.28 +//User includes
1.29 +#include "teststepcomsdbg.h"
1.30 +#include "step_016_xx.h"
1.31 +
1.32 +
1.33 +/**
1.34 +* Function Name : CFloggerTest016_01
1.35 +* Input parameters : None
1.36 +* Output parameters : None
1.37 +* Description : This is the constructor
1.38 +*/
1.39 +
1.40 +
1.41 +CFloggerTest016_01::CFloggerTest016_01()
1.42 + {
1.43 + // store the name of this test case
1.44 + SetTestStepName(_L("step_016_01"));
1.45 + }
1.46 +
1.47 +
1.48 +/**
1.49 +* Function Name :~ CFloggerTest016_01
1.50 +* Input parameters : None
1.51 +* Output parameters : None
1.52 +* Description : This is the Destructor
1.53 +*/
1.54 +
1.55 +
1.56 +CFloggerTest016_01::~CFloggerTest016_01()
1.57 + {
1.58 + }
1.59 +
1.60 +/**
1.61 +* Function Name : doTestStepL
1.62 +* Input parameters : None
1.63 +* Output parameters : TVerdict
1.64 +* Description : This function returns weather the test case 016_01 has
1.65 +* passed or failed
1.66 +
1.67 +*/
1.68 +
1.69 +
1.70 +TVerdict CFloggerTest016_01::doTestStepL( )
1.71 + {
1.72 + INFO_PRINTF1(_L("Step 016.01 called "));
1.73 +
1.74 + if ( executeStepL(EFalse) == KErrNone )
1.75 + SetTestStepResult(EPass);
1.76 +
1.77 + else
1.78 + SetTestStepResult(EFail);
1.79 +
1.80 +
1.81 + User::After(KTimeForDisplay1);
1.82 + return TestStepResult();
1.83 + }
1.84 +
1.85 +
1.86 +/**
1.87 +* Function Name : executeStepL
1.88 +* Input parameters : None
1.89 +* Output parameters : TInt
1.90 +* Description : This function writes the test data in to the log file
1.91 +* This function check the test message is present in the
1.92 +* log file
1.93 +
1.94 +*/
1.95 +
1.96 +
1.97 +TInt CFloggerTest016_01::executeStepL(TBool heapTest)
1.98 + {
1.99 + TInt ret = KErrGeneral;
1.100 +
1.101 + ret = DoTestWrite();
1.102 + if (ret == KErrNone )
1.103 + {
1.104 + User::After(KTimeToLog);
1.105 + TRAPD(r, ret = DoTestCheckWriteL() );
1.106 + if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
1.107 + {
1.108 + ret = KErrNoMemory;
1.109 + }
1.110 + else if (r != KErrNone)
1.111 + {
1.112 + ret = r;
1.113 + }
1.114 + }
1.115 + return ret;
1.116 + }
1.117 +/**
1.118 +* Function Name : executeStepL
1.119 +* Input parameters : None
1.120 +* Output parameters : TInt
1.121 +* Description : This function writes the test data in to the log file
1.122 +* This function check the test message is present in the
1.123 +* log file
1.124 +
1.125 +*/
1.126 +
1.127 +
1.128 +TInt CFloggerTest016_01::executeStepL()
1.129 + {
1.130 + return KErrGeneral;
1.131 + }
1.132 +
1.133 +/**
1.134 +* Function Name : DoTestWrite
1.135 +* Input parameters : None
1.136 +* Output parameters : TInt
1.137 +* Description : This function writes the data to the file logger
1.138 +
1.139 +*/
1.140 +
1.141 +
1.142 +TInt CFloggerTest016_01::DoTestWrite()
1.143 + {
1.144 + _LIT8(KTestMessageOne,"TC 16_01: The value of test integer variable :%d");
1.145 + DoTestWriteFormat(KTestMessageOne, 100); //Write 8 bit formatted test descriptor
1.146 +
1.147 + // connect so we can flush file buffer for heap check since timer is killed in heap checks
1.148 + RFileLogger theFlogger;
1.149 + theFlogger.Connect();
1.150 + theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
1.151 + ForceLogFlush(theFlogger);
1.152 + theFlogger.Close();
1.153 + return KErrNone;
1.154 + }
1.155 +
1.156 +
1.157 +/**
1.158 +* Function Name : DoTestWriteFormat
1.159 +* Input parameters : TRefByValue<const TDesC8>
1.160 +* Output parameters : TInt
1.161 +* Description : This function writes formatted data to the file logger
1.162 +*/
1.163 +
1.164 +
1.165 +TInt CFloggerTest016_01::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
1.166 + {
1.167 + VA_LIST list;
1.168 + VA_START(list,aFmt);
1.169 + RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list);
1.170 + return KErrNone;
1.171 + }
1.172 +
1.173 +
1.174 +/**
1.175 +* Function Name : DoTestCheckWriteL
1.176 +* Input parameters : None
1.177 +* Output parameters : TInt
1.178 +* Description : This function checks the weather test data was written
1.179 +* in to the log file by DoTestWrite() or not.
1.180 +
1.181 +*/
1.182 +
1.183 +
1.184 +TInt CFloggerTest016_01::DoTestCheckWriteL()
1.185 + {
1.186 + User::After(KTimeToLog);
1.187 +
1.188 + RFile theFile;
1.189 + HBufC8 * hBuffer;
1.190 + TInt listfilesize;
1.191 + TInt returnCode;
1.192 + RFs fileSystem; //For file operation create a file system
1.193 + TBuf8<256> testData; //To hold the test descriptor
1.194 +
1.195 + _LIT8(KTestMessageOne,"TC 16_01: The value of test integer variable :%d");
1.196 + testData.Format(KTestMessageOne, 100);
1.197 +
1.198 + _LIT(KLogFile,"c:\\logs\\log.txt"); // the log file path
1.199 +
1.200 + User::LeaveIfError(fileSystem.Connect());
1.201 +
1.202 + //Open the file in the read mode
1.203 + User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
1.204 +
1.205 +
1.206 + User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
1.207 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.208 + CleanupStack::PushL(hBuffer);
1.209 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.210 +
1.211 + // Read from position 0: start of file
1.212 + returnCode = theFile.Read(ptrString);
1.213 +
1.214 + returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
1.215 + //from the file
1.216 + theFile.Close();
1.217 + fileSystem.Close(); //Close the file server
1.218 + CleanupStack::PopAndDestroy(hBuffer);
1.219 + if (returnCode > 0)
1.220 + return KErrNone;
1.221 + else
1.222 + return KErrNotFound;
1.223 + }
1.224 +
1.225 +
1.226 +
1.227 +
1.228 +/**
1.229 +* Function Name : CFloggerTest016_02
1.230 +* Input parameters : None
1.231 +* Output parameters : None
1.232 +* Description : This is the constructor
1.233 +*/
1.234 +
1.235 +
1.236 +CFloggerTest016_02::CFloggerTest016_02()
1.237 + {
1.238 + // store the name of this test case
1.239 + SetTestStepName(_L("step_016_02"));
1.240 + }
1.241 +
1.242 +
1.243 +/**
1.244 +* Function Name :~ CFloggerTest016_02
1.245 +* Input parameters : None
1.246 +* Output parameters : None
1.247 +* Description : This is the Destructor
1.248 +*/
1.249 +
1.250 +
1.251 +CFloggerTest016_02::~CFloggerTest016_02()
1.252 + {
1.253 + iFlogger.Close();
1.254 + }
1.255 +
1.256 +
1.257 +/**
1.258 +* Function Name : doTestStepL
1.259 +* Input parameters : None
1.260 +* Output parameters : TVerdict
1.261 +* Description : This function returns weather the test case 016_01 has
1.262 +* passed or failed
1.263 +
1.264 +*/
1.265 +
1.266 +
1.267 +TVerdict CFloggerTest016_02::doTestStepL( )
1.268 + {
1.269 + INFO_PRINTF1(_L("Step 016.02 called "));
1.270 + if ( executeStepL() == KErrNone )
1.271 + SetTestStepResult(EPass);
1.272 +
1.273 + else
1.274 + SetTestStepResult(EFail);
1.275 +
1.276 +
1.277 + User::After(KTimeForDisplay1);
1.278 + return TestStepResult();
1.279 + }
1.280 +
1.281 +/**
1.282 +* Function Name : executeStepL
1.283 +* Input parameters : None
1.284 +* Output parameters : TInt
1.285 +* Description : This function writes the test data in to the log file
1.286 +* This function check the test message is present in the
1.287 +* log file
1.288 +
1.289 +*/
1.290 +
1.291 +
1.292 +TInt CFloggerTest016_02::executeStepL(TBool)
1.293 + {
1.294 + return KErrGeneral;
1.295 + }
1.296 +/**
1.297 +* Function Name : executeStepL
1.298 +* Input parameters : None
1.299 +* Output parameters : TInt
1.300 +* Description : This function writes the test data in to the log file
1.301 +* This function check the test message is present in the
1.302 +* log file
1.303 +
1.304 +*/
1.305 +
1.306 +
1.307 +TInt CFloggerTest016_02::executeStepL()
1.308 + {
1.309 + User::After(1000*1000); //Need this or connect will return KErrServerTerminated
1.310 + TInt j = 0;
1.311 + for(TInt i=0; i < 100000000; i++)
1.312 + j++;
1.313 +
1.314 + TInt ret = KErrGeneral;
1.315 + ret = DoTestWrite();
1.316 + if (ret == KErrNone )
1.317 + {
1.318 + TRAPD(r, ret = DoTestCheckWriteL());
1.319 + if ( r != KErrNone)
1.320 + ret = r;
1.321 + }
1.322 + return ret;
1.323 + }
1.324 +
1.325 +
1.326 +TInt CFloggerTest016_02::DoTestWrite()
1.327 + {
1.328 + _LIT8(KTestLongMessage,"TEST 16.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 This is the long message %d"); //8 bit test decriptor
1.329 + DoTestWriteFormat(KTestLongMessage, 100); //Write 8 bit formatted test descriptor
1.330 + return KErrNone;
1.331 + }
1.332 +
1.333 +
1.334 +/**
1.335 +* Function Name : DoTestWriteFormat
1.336 +* Input parameters : TRefByValue<const TDesC16>
1.337 +* Output parameters : TInt
1.338 +* Description : This function writes formatted data to the file logger
1.339 +*/
1.340 +
1.341 +
1.342 +TInt CFloggerTest016_02::DoTestWriteFormat(TRefByValue<const TDesC8> aFmt,...)
1.343 + {
1.344 +
1.345 + RFileLogger theFlogger;
1.346 + TInt ret = KErrGeneral;
1.347 + ret = theFlogger.Connect(); //Just to clear the old log message
1.348 + if ( ret == KErrNone)
1.349 + ret = theFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8);
1.350 + if ( ret == KErrNone)
1.351 + ret = theFlogger.ClearLog();
1.352 + if ( ret == KErrNone)
1.353 + theFlogger.Close();
1.354 +
1.355 + User::After(100000);
1.356 +
1.357 + if (ret == KErrNone)
1.358 + {
1.359 + VA_LIST list;
1.360 + VA_START(list,aFmt);
1.361 +
1.362 + RFileLogger::WriteFormat(KStdSubsysTag8, KStdCompTag8, aFmt, list);
1.363 + User::After(100000);
1.364 + return KErrNone;
1.365 + }
1.366 +
1.367 + return ret;
1.368 + }
1.369 +
1.370 +
1.371 +/**
1.372 +* Function Name : DoTestCheckWriteL
1.373 +* Input parameters : None
1.374 +* Output parameters : TInt
1.375 +* Description : This function checks the weather test data was written
1.376 +* in to the log file by DoTestWrite() or not.
1.377 +
1.378 +*/
1.379 +
1.380 +
1.381 +TInt CFloggerTest016_02::DoTestCheckWriteL()
1.382 + {
1.383 + User::After(KTimeToLog);
1.384 +
1.385 + RFile theFile;
1.386 + HBufC8 * hBuffer;
1.387 + TInt listfilesize,returnCode;
1.388 + RFs fileSystem; //For file operation create a file system
1.389 + TBuf8<256> testData; //To hold the test descriptor
1.390 + _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
1.391 +
1.392 + //The following contains the string of length 200(max)
1.393 + //which is written to the log file
1.394 + //_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");
1.395 + _LIT(KTestLongMessage, "TEST 16.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 l");
1.396 +
1.397 + //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
1.398 +
1.399 + User::LeaveIfError(fileSystem.Connect());
1.400 +
1.401 + //Open the file in the read mode
1.402 + User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
1.403 +
1.404 + CleanupClosePushL(theFile);
1.405 +
1.406 + User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
1.407 +
1.408 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.409 + CleanupStack::PushL(hBuffer);
1.410 +
1.411 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.412 +
1.413 + // Read from position 0: start of file
1.414 + User::LeaveIfError(returnCode = theFile.Read(ptrString));
1.415 +
1.416 + testData.Copy(KTestLongMessage); //Copy the test descriptor
1.417 + returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
1.418 + //from the file
1.419 +
1.420 + CleanupStack::PopAndDestroy(hBuffer);
1.421 + CleanupStack::PopAndDestroy(); //theFile
1.422 + if (returnCode > 0)
1.423 + return KErrNone;
1.424 + else
1.425 + return KErrGeneral;
1.426 + }
1.427 +
1.428 +
1.429 +/**
1.430 +* Function Name : CFloggerTest016_03
1.431 +* Input parameters : None
1.432 +* Output parameters : None
1.433 +* Description : This is the constructor
1.434 +*/
1.435 +
1.436 +
1.437 +CFloggerTest016_03::CFloggerTest016_03()
1.438 + {
1.439 + // store the name of this test case
1.440 + SetTestStepName(_L("step_016_03"));
1.441 + }
1.442 +
1.443 +
1.444 +/**
1.445 +* Function Name :~ CFloggerTest016_03
1.446 +* Input parameters : None
1.447 +* Output parameters : None
1.448 +* Description : This is the Destructor
1.449 +*/
1.450 +
1.451 +
1.452 +CFloggerTest016_03::~CFloggerTest016_03()
1.453 + {
1.454 + }
1.455 +
1.456 +
1.457 +/**
1.458 +* Function Name : doTestStepL
1.459 +* Input parameters : None
1.460 +* Output parameters : TVerdict
1.461 +* Description : This function is responsible for doing the heap test analysis
1.462 +
1.463 +*/
1.464 +
1.465 +
1.466 +TVerdict CFloggerTest016_03::doTestStepL( )
1.467 + {
1.468 + INFO_PRINTF1(_L("Step 016.03 called "));
1.469 +
1.470 + CFloggerTest016_01* step016_01 = new CFloggerTest016_01;
1.471 + CleanupStack::PushL(step016_01);
1.472 + doTestStepWithHeapFailureL( *step016_01, 1, 20, KErrNone, ETrue);
1.473 +
1.474 + CleanupStack::PopAndDestroy(step016_01);
1.475 + User::After(KTimeForDisplay);
1.476 + return TestStepResult();
1.477 + }
1.478 +