os/persistentdata/traceservices/commsdebugutility/TE_commsdebugutility/src/step_023_01.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 023.01
19 // Test system includes
20 #include "teststepcomsdbg.h"
21 #include "step_023_01.h"
24 #include <comms-infras/commsdebugutility.h>
28 * Function Name : CFloggerTest023_01
29 * Input parameters : None
30 * Output parameters : None
31 * Description : This is the constructor
34 CFloggerTest023_01::CFloggerTest023_01()
36 // store the name of this test case
37 SetTestStepName(_L("step_023_01"));
42 * Function Name :~ CFloggerTest023_01
43 * Input parameters : None
44 * Output parameters : None
45 * Description : This is the Destructor
49 CFloggerTest023_01::~CFloggerTest023_01()
56 * Function Name : doTestStepL
57 * Input parameters : None
58 * Output parameters : TVerdict
59 * Description : This function returns weather the test case 023_01 has
65 TVerdict CFloggerTest023_01::doTestStepL( )
67 if ( executeStepL() == KErrNone )
68 SetTestStepResult(EPass);
71 SetTestStepResult(EFail);
74 return TestStepResult();
77 TInt CFloggerTest023_01::executeStepL(TBool)
82 TInt CFloggerTest023_01::executeStepL( )
84 TInt ret = KErrGeneral;
88 TRAPD(r, ret = DoTestCheckWriteL());
97 * Function Name : DoTestWrite
98 * Input parameters : None
99 * Output parameters : TInt
100 * Description : This function writes the test data in to the log file
105 TInt CFloggerTest023_01::DoTestWrite()
107 INFO_PRINTF1(_L("Step 023.01 called "));
109 RFileLogger theFlogger;
112 ptrSubSystem.Set(_L8("SubSystem")); //Test system name
113 ptrComponent.Set(_L8("Component")); //Test component name
114 _LIT8(KTestMessage,"This is the test message"); //Test decriptor
116 TInt ret = KErrGeneral;
117 ret = theFlogger.Connect();
119 if (ret == KErrNone) // To Write the test descriptor the following lines are used.
121 ret = theFlogger.SetLogTags(ptrSubSystem, ptrComponent); //To set the tags
124 theFlogger.Write(KTestMessage);
125 theFlogger.__DbgShutDownServer();
130 User::After(100*1000); //Need this or connect will return KErrServerTerminated
132 if (ret == KErrNone) // To actually test the ClearLog() functionality
133 ret = theFlogger.Connect();
135 ret = theFlogger.SetLogTags(ptrSubSystem,ptrComponent);
138 theFlogger.ClearLog(); //ClearLog called to clear the log message
139 theFlogger.__DbgShutDownServer();
140 User::After(100*1000); //need this to give server time to clear the log
150 * Function Name : DoTestCheckWriteL
151 * Input parameters : None
152 * Output parameters : TInt
153 * Description : This function writes the data to the file logger
158 TInt CFloggerTest023_01::DoTestCheckWriteL()
164 RFs fileSystem; //For file operation create a file system
165 TBuf8<256> testData; //To hold the test descriptor
166 _LIT(KLogFile, "c:\\logs\\log.txt"); // log file name and path
168 _LIT8(KTestMessage,"This is the test message"); //Test decriptor
169 _LIT8(KSystemName,"SubSystem"); //Test subsystem name
170 _LIT8(KComponentName,"Component");// Test component name
172 User::LeaveIfError(fileSystem.Connect()); //Connect to the file server
174 //Open the file in the read mode
175 User::LeaveIfError(theFile.Open(fileSystem,KLogFile,EFileRead));
176 CleanupClosePushL(theFile);
178 User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file
179 hBuffer = HBufC8::New(listfilesize); //Allocate the buffer
180 CleanupStack::PushL(hBuffer);
181 TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer
183 // Read from position 0: start of file
184 returnCode = theFile.Read(ptrString);
186 testData.Copy(KTestMessage); //Copy the test descriptor
187 returnCode = ptrString.Find(testData); //find the test descriptor in the buffer read
190 if (returnCode < 0) //Note test message should not be present
192 testData.Copy(KSystemName); //Note test system name should not be present
193 returnCode = ptrString.Find(testData); //find the test system in the buffer read
197 if (returnCode < 0) //Note test component name should not be present
199 testData.Copy(KComponentName); //Note test message should not be present
200 returnCode = ptrString.Find(testData); //find the test component in the buffer read
204 CleanupStack::PopAndDestroy(hBuffer);
205 CleanupStack::PopAndDestroy(); //theFile
216 * Function Name : CFloggerTest023_02
217 * Input parameters : None
218 * Output parameters : None
219 * Description : This is the Constructor
223 CFloggerTest023_02::CFloggerTest023_02()
225 // store the name of this test case
226 SetTestStepName(_L("step_023_02"));
232 * Function Name :~ CFloggerTest023_02
233 * Input parameters : None
234 * Output parameters : None
235 * Description : This is the Destructor
239 CFloggerTest023_02::~CFloggerTest023_02()
246 * Function Name : doTestStepL
247 * Input parameters : None
248 * Output parameters : TVerdict
249 * Description : This function returns weather the test case 023_02 has
255 TVerdict CFloggerTest023_02::doTestStepL( )
257 // INFO_PRINTF1(_L("Step 023.01 called ")); // This line was panicing in release mode testing
259 if ( executeStepL() == KErrNone )
260 SetTestStepResult(EPass);
263 SetTestStepResult(EFail);
266 return TestStepResult();
269 TInt CFloggerTest023_02::executeStepL(TBool)
274 TInt CFloggerTest023_02::executeStepL( )
276 TPtrC8 ptrSubSystemTmp;
277 TPtrC8 ptrComponentTmp;
278 ptrSubSystemTmp.Set(_L8("SubSystem"));
279 ptrComponentTmp.Set(_L8("Component"));
281 RFileLogger theLogger;
283 theLogger.ClearLog(); // This line of code panics since it is called prior to SetLogTags()!!!!
284 theLogger.SetLogTags(ptrSubSystemTmp,ptrComponentTmp);