os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_003_xx.cpp
Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This contains Flogger Unit Test Case 003.xx
20 // Test system includes
21 #include "teststepcomsdbg.h"
22 #include "step_003_xx.h"
24 #include <comms-infras/commsdebugutility.h>
28 * Function Name : CFloggerTest003_01
29 * Input parameters : None
30 * Output parameters : None
31 * Description : This is the constructor
35 CFloggerTest003_01::CFloggerTest003_01()
37 // Store the name of this test case
38 SetTestStepName(_L("step_003_01"));
43 * Function Name :~ CFloggerTest003_01
44 * Input parameters : None
45 * Output parameters : None
46 * Description : This is the Destructor
50 CFloggerTest003_01::~CFloggerTest003_01()
56 * Function Name : doTestStepL
57 * Input parameters : None
58 * Output parameters : TVerdict
59 * Description : This function returns weather the test case 003_01 has
65 TVerdict CFloggerTest003_01::doTestStepL( )
67 User::After(KTimeForDisplay1);
68 INFO_PRINTF1(_L("Step 003.01 called "));
70 if ( executeStepL(EFalse) == KErrNone )
71 SetTestStepResult(EPass);
73 SetTestStepResult(EFail);
75 return TestStepResult();
80 * Function Name : executeStepL
81 * Input parameters : None
82 * Output parameters : TInt
83 * Description : This function sets the subsystem and component name
84 * checks weather they are set in the log file correctly
89 TInt CFloggerTest003_01::executeStepL(TBool heapTest)
91 return DoTestWrite(heapTest);
95 * Function Name : executeStepL
96 * Input parameters : None
97 * Output parameters : TInt
98 * Description : This function sets the subsystem and component name
99 * checks weather they are set in the log file correctly
104 TInt CFloggerTest003_01::executeStepL()
110 * Function Name : DoTestWriteL
111 * Input parameters : None
112 * Output parameters : TInt
113 * Description : This function checks the weather test data was written
114 in to the log file by DoTestWriteL() or not.
119 TInt CFloggerTest003_01::DoTestWrite(TBool heapTest)
121 _LIT8(KTestMessage ,"TC 3.01 :This is test msg");
124 ptrSubSystem.Set(_L8("SubSystem"));
125 ptrComponent.Set(_L8("Component"));
128 RFileLogger theFlogger;
130 ret = theFlogger.Connect();
134 ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent);
137 ret = theFlogger.ClearLog();
140 theFlogger.Write(KTestMessage);
141 ForceLogFlush(theFlogger);
142 User::After(KTimeToLogLargeData);
144 TRAPD(r, ret = DoTestCheckWriteL());
145 if ((heapTest) && ((ret == KErrNotFound) || (r != KErrNone)))
149 else if (r != KErrNone)
162 * Function Name : DoTestCheckWriteL
163 * Input parameters : None
164 * Output parameters : TInt
165 * Description : This function checks the weather test data was written
166 * in to the log file by DoTestWriteL() or not.
171 TInt CFloggerTest003_01::DoTestCheckWriteL()
175 ptrSubSystem.Set(_L8("SubSystem"));
176 ptrComponent.Set(_L8("Component"));
180 TInt listfilesize,returnCode;
181 RFs iFileSystem; //For file operation create a file system
182 TBuf8<256> testData; //To hold the test descriptor
183 _LIT(KLogFile,"c:\\logs\\log.txt");
185 _LIT(KTestSystem, "SubSystem"); //Test sytem name
186 _LIT(KTestComponent, "Component"); //Test component name
187 _LIT8(KTestMessage ,"TC 3.01 :This is test msg"); // Test descriptor
188 _LIT8(KOOMError, "#Logs may be lost out of memory!!"); // Error message which has to be tested in log
190 User::LeaveIfError(iFileSystem.Connect());
192 //Open the file in the read mode
193 User::LeaveIfError(theFile.Open(iFileSystem, KLogFile, EFileWrite|EFileShareAny));
194 CleanupClosePushL(theFile);
196 User::LeaveIfError(theFile.Size(listfilesize)); //Size of the file
198 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
199 CleanupStack::PushL(hBuffer);
200 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
202 // Read from position 0: start of file
203 returnCode = theFile.Read(ptrString);
205 testData.Copy(KTestMessage); //Copy the test message name
206 returnCode = ptrString.Find(KTestMessage); //find the test system name in the
207 //buffer read from the file
208 if (returnCode == KErrNotFound)
210 User::Leave(KErrNotFound);
213 returnCode = ptrString.Find(KOOMError);
216 User::Leave(KErrNoMemory);
219 testData.Copy(KTestSystem); //Copy the test subsystem name
220 returnCode = ptrString.Find(testData); //Find the test subsystem name in the
221 //buffer read from the file
223 if (returnCode > 0) // Test subsystem name present
225 testData.Copy(KTestComponent); //Copy the test component name
226 returnCode = ptrString.Find(testData); //Find the test component name in the
227 //buffer read from the file
230 CleanupStack::PopAndDestroy(hBuffer);
231 CleanupStack::PopAndDestroy(); //theFile
233 if (returnCode > 0) // Test component name present
244 * Function Name : CFloggerTest003_02
245 * Input parameters : None
246 * Output parameters : None
247 * Description : This is the constructor
251 CFloggerTest003_02::CFloggerTest003_02()
253 // store the name of this test case
254 SetTestStepName(_L("step_003_02"));
259 * Function Name :~ CFloggerTest003_02
260 * Input parameters : None
261 * Output parameters : None
262 * Description : This is the Destructor
266 CFloggerTest003_02::~CFloggerTest003_02()
272 * Function Name : doTestStepL
273 * Input parameters : None
274 * Output parameters : TVerdict
275 * Description : This function returns weather the test case 003_02 has
281 TVerdict CFloggerTest003_02::doTestStepL( )
283 // INFO_PRINTF1(_L("Step 003.02 called ")); // This line was panicing in release mode testing
285 if ( executeStepL() == KErrNone )
286 SetTestStepResult(EFail);
288 SetTestStepResult(EPass);
291 return TestStepResult();
296 * Function Name : executeStepL
297 * Input parameters : None
298 * Output parameters : TInt
299 * Description : This function writes the test data in to the log file
300 * This function check the test message is present in the
306 TInt CFloggerTest003_02::executeStepL()
308 return DoTestWrite() ;
312 * Function Name : executeStepL
313 * Input parameters : None
314 * Output parameters : TInt
315 * Description : This function writes the test data in to the log file
316 * This function check the test message is present in the
322 TInt CFloggerTest003_02::executeStepL(TBool)
327 * Function Name : DoTestWriteL
328 * Input parameters : None
329 * Output parameters : TInt
330 * Description : This function writees the data to the file logger
335 TInt CFloggerTest003_02::DoTestWrite()
337 _LIT(KTestMessage,"This is test message ");
339 //Call Write() before SetLogTags(), this will cause a PANIC
342 iFlogger.Write(KTestMessage);
345 //This test will cause a PANIC, so we will never get here
351 * Function Name : CFloggerTest003_03
352 * Input parameters : None
353 * Output parameters : None
354 * Description : This is the constructor
358 CFloggerTest003_03::CFloggerTest003_03()
360 // store the name of this test case
361 SetTestStepName(_L("step_003_03"));
366 * Function Name :~ CFloggerTest003_03
367 * Input parameters : None
368 * Output parameters : None
369 * Description : This is the Destructor
373 CFloggerTest003_03::~CFloggerTest003_03()
379 * Function Name : doTestStepL
380 * Input parameters : None
381 * Output parameters : TVerdict
382 * Description : This function is responsible for doing the heap test analysis
386 TVerdict CFloggerTest003_03::doTestStepL( )
388 INFO_PRINTF1(_L("Step 003.03 called "));
390 CFloggerTest003_01* step003_01 = new CFloggerTest003_01;
391 CleanupStack::PushL(step003_01);
392 if (doTestStepWithHeapFailureL( *step003_01, 450, 465, KErrNone, ETrue) != KErrNone)
394 SetTestStepResult(EFail);
397 CleanupStack::PopAndDestroy(step003_01);
398 User::After(KTimeForDisplay);
399 return TestStepResult();