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