os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_004_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_004_xx.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,511 @@
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 004.xx
1.18 +
1.19 +// EPOC includes
1.20 +#include <e32base.h>
1.21 +#include <f32file.h>
1.22 +
1.23 +// Test system includes
1.24 +#include "teststepcomsdbg.h"
1.25 +#include "step_004_xx.h"
1.26 +#include "TestMessage.h"
1.27 +
1.28 +#include <comms-infras/commsdebugutility.h>
1.29 +
1.30 +
1.31 +/**
1.32 +* Function Name : CFloggerTest004_01
1.33 +* Input parameters : None
1.34 +* Output parameters : None
1.35 +* Description : This is the constructor
1.36 +*/
1.37 +
1.38 +
1.39 +CFloggerTest004_01::CFloggerTest004_01()
1.40 + {
1.41 + SetTestStepName(_L("step_004_01"));
1.42 + }
1.43 +
1.44 +
1.45 +/**
1.46 +* Function Name :~ CFloggerTest004_01
1.47 +* Input parameters : None
1.48 +* Output parameters : None
1.49 +* Description : This is the Destructor
1.50 +*/
1.51 +
1.52 +
1.53 +CFloggerTest004_01::~CFloggerTest004_01()
1.54 + {
1.55 + }
1.56 +
1.57 +
1.58 +/**
1.59 +* Function Name : doTestStepL
1.60 +* Input parameters : None
1.61 +* Output parameters : TVerdict
1.62 +* Description : This function returns weather the test case 004_01 has
1.63 +* passed or failed
1.64 +
1.65 +*/
1.66 +
1.67 +
1.68 +TVerdict CFloggerTest004_01::doTestStepL( )
1.69 + {
1.70 + INFO_PRINTF1(_L("Step 004.01 called "));
1.71 +
1.72 + if ( executeStepL(EFalse) == KErrNone )
1.73 + SetTestStepResult(EPass);
1.74 + else
1.75 + SetTestStepResult(EFail);
1.76 +
1.77 + User::After(KTimeForDisplay);
1.78 + return TestStepResult();
1.79 + }
1.80 +
1.81 +
1.82 +/**
1.83 +* Function Name : executeStepL
1.84 +* Input parameters : None
1.85 +* Output parameters : TInt
1.86 +* Description : This function writes the test data in to the log file
1.87 +* This function check the test message is present in the
1.88 +* log file or not.
1.89 +
1.90 +*/
1.91 +
1.92 +
1.93 +TInt CFloggerTest004_01::executeStepL(TBool heapTest)
1.94 + {
1.95 + TInt ret = KErrNone;
1.96 +
1.97 + ret = iFlogger.Connect(); //Call connect() of Flogger
1.98 + if (ret == KErrNone) if (ret == KErrNone)
1.99 + {
1.100 + CleanupClosePushL(iFlogger);
1.101 + ret = iFlogger.SetLogTags(KStdSubsysTag8, KStdCompTag8); //SetLogTags() of Flogger called
1.102 + if (ret == KErrNone)
1.103 + {
1.104 + ret = iFlogger.ClearLog();
1.105 + if (ret == KErrNone)
1.106 + {
1.107 + if (ret == KErrNone)
1.108 + {
1.109 + ret = DoTestWrite();
1.110 + User::After(KTimeToLog);
1.111 +
1.112 + if ( ret == KErrNone)
1.113 + {
1.114 + TRAPD(r, ret = DoTestCheckWriteL() );
1.115 + if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
1.116 + {
1.117 + ret = KErrNoMemory;
1.118 + }
1.119 + else if (r != KErrNone)
1.120 + {
1.121 + ret = r;
1.122 + }
1.123 + }
1.124 + }
1.125 + }
1.126 + }
1.127 + CleanupStack::PopAndDestroy(); //logger
1.128 + }
1.129 + return ret;
1.130 + }
1.131 +
1.132 +/**
1.133 +* Function Name : executeStepL
1.134 +* Input parameters : None
1.135 +* Output parameters : TInt
1.136 +* Description : This function writes the test data in to the log file
1.137 +* This function check the test message is present in the
1.138 +* log file or not.
1.139 +
1.140 +*/
1.141 +
1.142 +
1.143 +TInt CFloggerTest004_01::executeStepL()
1.144 + {
1.145 + return KErrGeneral;
1.146 + }
1.147 +
1.148 +
1.149 +/**
1.150 +* Function Name : DoTestWrite
1.151 +* Input parameters : None
1.152 +* Output parameters : TInt
1.153 +* Description : This function writes the test data in to the log file
1.154 +
1.155 +*/
1.156 +
1.157 +
1.158 +TInt CFloggerTest004_01::DoTestWrite()
1.159 + {
1.160 + _LIT(KTestMessage,"TC 4.01 :This is test msg"); //unicode test decriptor
1.161 + iFlogger.Write(KTestMessage);
1.162 + ForceLogFlush(iFlogger);
1.163 +
1.164 + return KErrNone;
1.165 + }
1.166 +
1.167 +
1.168 +/**
1.169 +* Function Name : DoTestCheckWriteL
1.170 +* Input parameters : None
1.171 +* Output parameters : TInt
1.172 +* Description : This function checks the weather test data was written
1.173 +* in to the log file by DoTestWriteL() or not.
1.174 +
1.175 +*/
1.176 +
1.177 +
1.178 +TInt CFloggerTest004_01::DoTestCheckWriteL()
1.179 + {
1.180 + RFile theFile;
1.181 + HBufC8 * hBuffer;
1.182 + TInt listfilesize,returnCode;
1.183 + RFs fileSystem; //For file operation create a file system
1.184 + TBuf8<256> testData; //To hold the test descriptor
1.185 + _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
1.186 + TInt numSuccessful = 0;
1.187 +
1.188 + _LIT(KTestMessage,"TC 4.01 :This is test msg"); //unicode test decriptor
1.189 +
1.190 + User::LeaveIfError(fileSystem.Connect());
1.191 +
1.192 + //Open the file in the read mode
1.193 + User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
1.194 +
1.195 + CleanupClosePushL(theFile);
1.196 +
1.197 + User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
1.198 +
1.199 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.200 + CleanupStack::PushL(hBuffer);
1.201 +
1.202 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.203 +
1.204 + // Read from position 0: start of file
1.205 + User::LeaveIfError(returnCode = theFile.Read(ptrString));
1.206 +
1.207 + testData.Copy(KTestMessage); //Copy the test descriptor
1.208 + returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
1.209 + //from the file
1.210 +
1.211 + if (returnCode != KErrNotFound)
1.212 + {
1.213 + numSuccessful++;
1.214 + }
1.215 +
1.216 + returnCode = ptrString.Find(KErrOOM);
1.217 + if (returnCode > 0)
1.218 + {
1.219 + User::Leave(KErrNoMemory);
1.220 + }
1.221 +
1.222 +
1.223 +
1.224 + CleanupStack::PopAndDestroy(hBuffer);
1.225 + CleanupStack::PopAndDestroy(); //theFile
1.226 + if (numSuccessful == 1)
1.227 + {
1.228 + return KErrNone;
1.229 + }
1.230 + else
1.231 + {
1.232 + return KErrNotFound;
1.233 + }
1.234 +
1.235 +
1.236 +}
1.237 +
1.238 +
1.239 +
1.240 +
1.241 +
1.242 +
1.243 +
1.244 +
1.245 +
1.246 +/**
1.247 +* Function Name : CFloggerTest004_02
1.248 +* Input parameters : None
1.249 +* Output parameters : None
1.250 +* Description : This is the constructor
1.251 +*/
1.252 +
1.253 +
1.254 +CFloggerTest004_02::CFloggerTest004_02()
1.255 + {
1.256 + // store the name of this test case
1.257 + SetTestStepName(_L("step_004_02"));
1.258 +
1.259 + }
1.260 +
1.261 +
1.262 +/**
1.263 +* Function Name :~ CFloggerTest004_01
1.264 +* Input parameters : None
1.265 +* Output parameters : None
1.266 +* Description : This is the Destructor
1.267 +*/
1.268 +
1.269 +
1.270 +CFloggerTest004_02::~CFloggerTest004_02()
1.271 + {
1.272 + }
1.273 +
1.274 +
1.275 +/**
1.276 +* Function Name : doTestStepL
1.277 +* Input parameters : None
1.278 +* Output parameters : TVerdict
1.279 +* Description : This function returns weather the test case 004_02 is
1.280 +* passed or failed
1.281 +
1.282 +*/
1.283 +
1.284 +
1.285 +TVerdict CFloggerTest004_02::doTestStepL( )
1.286 + {
1.287 + INFO_PRINTF1(_L("Step 004.02 called "));
1.288 +
1.289 + if ( executeStepL() == KErrNone )
1.290 + SetTestStepResult(EPass);
1.291 + else
1.292 + SetTestStepResult(EFail);
1.293 +
1.294 + User::After(KTimeForDisplay);
1.295 + return TestStepResult();
1.296 + }
1.297 +
1.298 +
1.299 +/**
1.300 +* Function Name : executeStepL
1.301 +* Input parameters : None
1.302 +* Output parameters : TInt
1.303 +* Description : This function writes the test data in to the log file
1.304 +* This function check the test message is present in the
1.305 +* log file or not.
1.306 +
1.307 +*/
1.308 +
1.309 +
1.310 +TInt CFloggerTest004_02::executeStepL()
1.311 + {
1.312 + TInt ret = KErrGeneral;
1.313 +
1.314 + ret = DoTestConnect();
1.315 + CleanupClosePushL(iFlogger);
1.316 + if (ret == KErrNone)
1.317 + {
1.318 + ret = DoTestWrite();
1.319 + // wait to give flogger time to log
1.320 + User::After(KTimeToLog);
1.321 + // catch any memory leaks
1.322 + iFlogger.__DbgShutDownServer();
1.323 +
1.324 + if (ret == KErrNone)
1.325 + {
1.326 + ret = DoTestCheckWriteL();
1.327 + }
1.328 + }
1.329 +
1.330 + CleanupStack::PopAndDestroy(); //logger
1.331 +
1.332 + return ret;
1.333 + }
1.334 +
1.335 +/**
1.336 +* Function Name : executeStepL
1.337 +* Input parameters : None
1.338 +* Output parameters : TInt
1.339 +* Description : This function writes the test data in to the log file
1.340 +* This function check the test message is present in the
1.341 +* log file or not.
1.342 +
1.343 +*/
1.344 +
1.345 +
1.346 +TInt CFloggerTest004_02::executeStepL(TBool)
1.347 + {
1.348 + return KErrGeneral;
1.349 + }
1.350 +
1.351 +/**
1.352 +* Function Name : DoTestConnect
1.353 +* Input parameters : None
1.354 +* Output parameters : TInt
1.355 +* Description : This function establishes a connection to file logger
1.356 +* and sets the system and component name in file logger.
1.357 +
1.358 +*/
1.359 +
1.360 +
1.361 +TInt CFloggerTest004_02::DoTestConnect()
1.362 + {
1.363 + TInt ret;
1.364 + TPtrC8 ptrSubSystem;
1.365 + TPtrC8 ptrComponent;
1.366 + ptrSubSystem.Set(_L8("SubSystem"));
1.367 + ptrComponent.Set(_L8("Component"));
1.368 +
1.369 + ret = iFlogger.Connect(); //Call connect() of Flogger
1.370 + if (ret == KErrNone)
1.371 + {
1.372 + ret = iFlogger.SetLogTags(ptrSubSystem, ptrComponent); //SetLogTags() of Flogger called
1.373 + }
1.374 +
1.375 + if (ret == KErrNone)
1.376 + {
1.377 + ret = iFlogger.ClearLog(); //clear the contents from the log
1.378 + }
1.379 +
1.380 + return ret;
1.381 + }
1.382 +
1.383 +
1.384 +/**
1.385 +* Function Name : DoTestWrite
1.386 +* Input parameters : None
1.387 +* Output parameters : TInt
1.388 +* Description : This function writees the data to the file logger
1.389 +
1.390 +*/
1.391 +
1.392 +
1.393 +TInt CFloggerTest004_02::DoTestWrite()
1.394 + {
1.395 + //KTestLongMessage contains a very lengthy message
1.396 + _LIT(KTestLongMessage,"TC 4_02: This is the long message This is the long message This is the long message This is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long messageThis is ");
1.397 +
1.398 + iFlogger.Write(KTestLongMessage);
1.399 + return KErrNone;
1.400 + }
1.401 +
1.402 +
1.403 +/**
1.404 +* Function Name : DoTestCheckWriteL
1.405 +* Input parameters : None
1.406 +* Output parameters : TInt
1.407 +* Description : This function checks the weather test data was written
1.408 +* in to the log file by DoTestWriteL() or not.
1.409 +
1.410 +*/
1.411 +
1.412 +
1.413 +TInt CFloggerTest004_02::DoTestCheckWriteL()
1.414 + {
1.415 + RFile theFile;
1.416 + HBufC8 * hBuffer;
1.417 + TInt listfilesize,returnCode;
1.418 + RFs fileSystem; //For file operation create a file system
1.419 + TBuf8<256> testData; //To hold the test descriptor
1.420 + _LIT(KLogFile,"c:\\logs\\log.txt"); // log file name and path
1.421 +
1.422 + //The following contains the string of length 200(max)
1.423 + //which is written to the log file
1.424 + //_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.425 + _LIT(KTestLongMessage, "TC 4_02: This is the long message This is the long message This is the long message This is the long messageThis is the long messageThis is the long messageThis is the long messageThis is the long me");
1.426 +
1.427 + //_LIT8(KOOMError, "#Logs may be lost out of memory!!");
1.428 +
1.429 + User::LeaveIfError(fileSystem.Connect());
1.430 +
1.431 + //Open the file in the read mode
1.432 + User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
1.433 +
1.434 + CleanupClosePushL(theFile);
1.435 +
1.436 + User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
1.437 +
1.438 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.439 + CleanupStack::PushL(hBuffer);
1.440 +
1.441 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.442 +
1.443 + // Read from position 0: start of file
1.444 + User::LeaveIfError(returnCode = theFile.Read(ptrString));
1.445 +
1.446 + testData.Copy(KTestLongMessage); //Copy the test descriptor
1.447 + returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
1.448 + //from the file
1.449 +
1.450 +
1.451 + CleanupStack::PopAndDestroy(hBuffer);
1.452 + CleanupStack::PopAndDestroy(); //theFile
1.453 + if (returnCode > 0)
1.454 + return KErrNone;
1.455 + else
1.456 + return KErrGeneral;
1.457 +
1.458 +
1.459 +}
1.460 +
1.461 +
1.462 +
1.463 +
1.464 +
1.465 +/**
1.466 +* Function Name : CFloggerTest004_03
1.467 +* Input parameters : None
1.468 +* Output parameters : None
1.469 +* Description : This is the constructor
1.470 +*/
1.471 +
1.472 +
1.473 +CFloggerTest004_03::CFloggerTest004_03()
1.474 + {
1.475 + // store the name of this test case
1.476 + SetTestStepName(_L("step_004_03"));
1.477 + }
1.478 +
1.479 +
1.480 +/**
1.481 +* Function Name :~ CFloggerTest004_01
1.482 +* Input parameters : None
1.483 +* Output parameters : None
1.484 +* Description : This is the Destructor
1.485 +*/
1.486 +
1.487 +
1.488 +CFloggerTest004_03::~CFloggerTest004_03()
1.489 + {
1.490 + }
1.491 +
1.492 +
1.493 +/**
1.494 +* Function Name : doTestStepL
1.495 +* Input parameters : None
1.496 +* Output parameters : TVerdict
1.497 +* Description : This function is responsible for doing the heap test analysis
1.498 +
1.499 +*/
1.500 +
1.501 +
1.502 +TVerdict CFloggerTest004_03::doTestStepL( )
1.503 + {
1.504 + INFO_PRINTF1(_L("Step 004.03 called "));
1.505 +
1.506 + CFloggerTest004_01* step004_01 = new CFloggerTest004_01;
1.507 + CleanupStack::PushL(step004_01);
1.508 + doTestStepWithHeapFailureL( *step004_01, 450, 470, KErrNone, ETrue);
1.509 +
1.510 + CleanupStack::PopAndDestroy(step004_01);
1.511 + User::After(KTimeForDisplay);
1.512 + return TestStepResult();
1.513 + }
1.514 +