os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_003_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_003_xx.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,401 @@
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 003.xx
1.18 +
1.19 +// EPOC includes
1.20 +#include <e32base.h>
1.21 +
1.22 +
1.23 +// Test system includes
1.24 +#include "teststepcomsdbg.h"
1.25 +#include "step_003_xx.h"
1.26 +
1.27 +#include <comms-infras/commsdebugutility.h>
1.28 +
1.29 +
1.30 +/**
1.31 +* Function Name : CFloggerTest003_01
1.32 +* Input parameters : None
1.33 +* Output parameters : None
1.34 +* Description : This is the constructor
1.35 +*/
1.36 +
1.37 +
1.38 +CFloggerTest003_01::CFloggerTest003_01()
1.39 + {
1.40 + // Store the name of this test case
1.41 + SetTestStepName(_L("step_003_01"));
1.42 + }
1.43 +
1.44 +
1.45 +/**
1.46 +* Function Name :~ CFloggerTest003_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 +CFloggerTest003_01::~CFloggerTest003_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 003_01 has
1.63 +* passed or failed
1.64 +
1.65 +*/
1.66 +
1.67 +
1.68 +TVerdict CFloggerTest003_01::doTestStepL( )
1.69 + {
1.70 + User::After(KTimeForDisplay1);
1.71 + INFO_PRINTF1(_L("Step 003.01 called "));
1.72 +
1.73 + if ( executeStepL(EFalse) == KErrNone )
1.74 + SetTestStepResult(EPass);
1.75 + else
1.76 + SetTestStepResult(EFail);
1.77 +
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 sets the subsystem and component name
1.87 +* checks weather they are set in the log file correctly
1.88 +
1.89 +*/
1.90 +
1.91 +
1.92 +TInt CFloggerTest003_01::executeStepL(TBool heapTest)
1.93 + {
1.94 + return DoTestWrite(heapTest);
1.95 + }
1.96 +
1.97 +/**
1.98 +* Function Name : executeStepL
1.99 +* Input parameters : None
1.100 +* Output parameters : TInt
1.101 +* Description : This function sets the subsystem and component name
1.102 +* checks weather they are set in the log file correctly
1.103 +
1.104 +*/
1.105 +
1.106 +
1.107 +TInt CFloggerTest003_01::executeStepL()
1.108 + {
1.109 + return KErrGeneral;
1.110 + }
1.111 +
1.112 +/**
1.113 +* Function Name : DoTestWriteL
1.114 +* Input parameters : None
1.115 +* Output parameters : TInt
1.116 +* Description : This function checks the weather test data was written
1.117 + in to the log file by DoTestWriteL() or not.
1.118 +
1.119 +*/
1.120 +
1.121 +
1.122 +TInt CFloggerTest003_01::DoTestWrite(TBool heapTest)
1.123 + {
1.124 + _LIT8(KTestMessage ,"TC 3.01 :This is test msg");
1.125 + TPtrC8 ptrSubSystem;
1.126 + TPtrC8 ptrComponent;
1.127 + ptrSubSystem.Set(_L8("SubSystem"));
1.128 + ptrComponent.Set(_L8("Component"));
1.129 +
1.130 + TInt ret = KErrNone;
1.131 + RFileLogger theFlogger;
1.132 +
1.133 + ret = theFlogger.Connect();
1.134 +
1.135 + if (ret == KErrNone)
1.136 + {
1.137 + ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
1.138 + if (ret == KErrNone)
1.139 + {
1.140 + ret = theFlogger.ClearLog();
1.141 + if (ret == KErrNone)
1.142 + {
1.143 + theFlogger.Write(KTestMessage);
1.144 + ForceLogFlush(theFlogger);
1.145 + User::After(KTimeToLogLargeData);
1.146 +
1.147 + TRAPD(r, ret = DoTestCheckWriteL());
1.148 + if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
1.149 + {
1.150 + ret = KErrNoMemory;
1.151 + }
1.152 + else if (r != KErrNone)
1.153 + {
1.154 + ret = r;
1.155 + }
1.156 + }
1.157 + }
1.158 + }
1.159 + theFlogger.Close();
1.160 + return ret;
1.161 + }
1.162 +
1.163 +
1.164 +/**
1.165 +* Function Name : DoTestCheckWriteL
1.166 +* Input parameters : None
1.167 +* Output parameters : TInt
1.168 +* Description : This function checks the weather test data was written
1.169 +* in to the log file by DoTestWriteL() or not.
1.170 +
1.171 +*/
1.172 +
1.173 +
1.174 +TInt CFloggerTest003_01::DoTestCheckWriteL()
1.175 + {
1.176 + TPtrC8 ptrSubSystem;
1.177 + TPtrC8 ptrComponent;
1.178 + ptrSubSystem.Set(_L8("SubSystem"));
1.179 + ptrComponent.Set(_L8("Component"));
1.180 + RFile theFile;
1.181 +
1.182 + HBufC8 * hBuffer;
1.183 + TInt listfilesize,returnCode;
1.184 + RFs iFileSystem; //For file operation create a file system
1.185 + TBuf8<256> testData; //To hold the test descriptor
1.186 + _LIT(KLogFile,"c:\\logs\\log.txt");
1.187 +
1.188 + _LIT(KTestSystem, "SubSystem"); //Test sytem name
1.189 + _LIT(KTestComponent, "Component"); //Test component name
1.190 + _LIT8(KTestMessage ,"TC 3.01 :This is test msg"); // Test descriptor
1.191 + _LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
1.192 +
1.193 + User::LeaveIfError(iFileSystem.Connect());
1.194 +
1.195 + //Open the file in the read mode
1.196 + User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny));
1.197 + CleanupClosePushL(theFile);
1.198 +
1.199 + User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
1.200 +
1.201 + hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
1.202 + CleanupStack::PushL(hBuffer);
1.203 + TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
1.204 +
1.205 + // Read from position 0: start of file
1.206 + returnCode = theFile.Read(ptrString);
1.207 +
1.208 + testData.Copy(KTestMessage); //Copy the test message name
1.209 + returnCode = ptrString.Find(KTestMessage); //find the test system name in the
1.210 + //buffer read from the file
1.211 + if (returnCode == KErrNotFound)
1.212 + {
1.213 + User::Leave(KErrNotFound);
1.214 + }
1.215 +
1.216 + returnCode = ptrString.Find(KOOMError);
1.217 + if (returnCode > 0)
1.218 + {
1.219 + User::Leave(KErrNoMemory);
1.220 + }
1.221 +
1.222 + testData.Copy(KTestSystem); //Copy the test subsystem name
1.223 + returnCode = ptrString.Find(testData); //Find the test subsystem name in the
1.224 + //buffer read from the file
1.225 +
1.226 + if (returnCode > 0) // Test subsystem name present
1.227 + {
1.228 + testData.Copy(KTestComponent); //Copy the test component name
1.229 + returnCode = ptrString.Find(testData); //Find the test component name in the
1.230 + //buffer read from the file
1.231 + }
1.232 +
1.233 + CleanupStack::PopAndDestroy(hBuffer);
1.234 + CleanupStack::PopAndDestroy(); //theFile
1.235 +
1.236 + if (returnCode > 0) // Test component name present
1.237 + return KErrNone;
1.238 + else
1.239 + return KErrNotFound;
1.240 + }
1.241 +
1.242 +
1.243 +
1.244 +
1.245 +
1.246 +/**
1.247 +* Function Name : CFloggerTest003_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 +CFloggerTest003_02::CFloggerTest003_02()
1.255 + {
1.256 + // store the name of this test case
1.257 + SetTestStepName(_L("step_003_02"));
1.258 + }
1.259 +
1.260 +
1.261 +/**
1.262 +* Function Name :~ CFloggerTest003_02
1.263 +* Input parameters : None
1.264 +* Output parameters : None
1.265 +* Description : This is the Destructor
1.266 +*/
1.267 +
1.268 +
1.269 +CFloggerTest003_02::~CFloggerTest003_02()
1.270 + {
1.271 + }
1.272 +
1.273 +
1.274 +/**
1.275 +* Function Name : doTestStepL
1.276 +* Input parameters : None
1.277 +* Output parameters : TVerdict
1.278 +* Description : This function returns weather the test case 003_02 has
1.279 +* passed or failed
1.280 +
1.281 +*/
1.282 +
1.283 +
1.284 +TVerdict CFloggerTest003_02::doTestStepL( )
1.285 + {
1.286 + // INFO_PRINTF1(_L("Step 003.02 called ")); // This line was panicing in release mode testing
1.287 +
1.288 + if ( executeStepL() == KErrNone )
1.289 + SetTestStepResult(EFail);
1.290 + else
1.291 + SetTestStepResult(EPass);
1.292 +
1.293 +
1.294 + return TestStepResult();
1.295 + }
1.296 +
1.297 +
1.298 +/**
1.299 +* Function Name : executeStepL
1.300 +* Input parameters : None
1.301 +* Output parameters : TInt
1.302 +* Description : This function writes the test data in to the log file
1.303 +* This function check the test message is present in the
1.304 +* log file
1.305 +
1.306 +*/
1.307 +
1.308 +
1.309 +TInt CFloggerTest003_02::executeStepL()
1.310 + {
1.311 + return DoTestWrite() ;
1.312 + }
1.313 +
1.314 +/**
1.315 +* Function Name : executeStepL
1.316 +* Input parameters : None
1.317 +* Output parameters : TInt
1.318 +* Description : This function writes the test data in to the log file
1.319 +* This function check the test message is present in the
1.320 +* log file
1.321 +
1.322 +*/
1.323 +
1.324 +
1.325 +TInt CFloggerTest003_02::executeStepL(TBool)
1.326 + {
1.327 + return KErrGeneral;
1.328 + }
1.329 +/**
1.330 +* Function Name : DoTestWriteL
1.331 +* Input parameters : None
1.332 +* Output parameters : TInt
1.333 +* Description : This function writees the data to the file logger
1.334 +
1.335 +*/
1.336 +
1.337 +
1.338 +TInt CFloggerTest003_02::DoTestWrite()
1.339 + {
1.340 + _LIT(KTestMessage,"This is test message ");
1.341 +
1.342 + //Call Write() before SetLogTags(), this will cause a PANIC
1.343 +
1.344 + iFlogger.Connect();
1.345 + iFlogger.Write(KTestMessage);
1.346 + iFlogger.Close();
1.347 +
1.348 + //This test will cause a PANIC, so we will never get here
1.349 + return KErrNone;
1.350 + }
1.351 +
1.352 +
1.353 +/**
1.354 +* Function Name : CFloggerTest003_03
1.355 +* Input parameters : None
1.356 +* Output parameters : None
1.357 +* Description : This is the constructor
1.358 +*/
1.359 +
1.360 +
1.361 +CFloggerTest003_03::CFloggerTest003_03()
1.362 + {
1.363 + // store the name of this test case
1.364 + SetTestStepName(_L("step_003_03"));
1.365 + }
1.366 +
1.367 +
1.368 +/**
1.369 +* Function Name :~ CFloggerTest003_03
1.370 +* Input parameters : None
1.371 +* Output parameters : None
1.372 +* Description : This is the Destructor
1.373 +*/
1.374 +
1.375 +
1.376 +CFloggerTest003_03::~CFloggerTest003_03()
1.377 + {
1.378 + }
1.379 +
1.380 +
1.381 +/**
1.382 +* Function Name : doTestStepL
1.383 +* Input parameters : None
1.384 +* Output parameters : TVerdict
1.385 +* Description : This function is responsible for doing the heap test analysis
1.386 +
1.387 +*/
1.388 +
1.389 +TVerdict CFloggerTest003_03::doTestStepL( )
1.390 + {
1.391 + INFO_PRINTF1(_L("Step 003.03 called "));
1.392 +
1.393 + CFloggerTest003_01* step003_01 = new CFloggerTest003_01;
1.394 + CleanupStack::PushL(step003_01);
1.395 + if (doTestStepWithHeapFailureL( *step003_01, 450, 465, KErrNone, ETrue) != KErrNone)
1.396 + {
1.397 + SetTestStepResult(EFail);
1.398 + }
1.399 +
1.400 + CleanupStack::PopAndDestroy(step003_01);
1.401 + User::After(KTimeForDisplay);
1.402 + return TestStepResult();
1.403 + }
1.404 +