os/ossrv/stdcpp/tsrc/BC/apps/widecharclassapiBCTest/src/widecharclassapiBCTest.cpp
First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 // [INCLUDE FILES] - do not remove
20 #include <Stiftestinterface.h>
21 #include "widecharclassapiBCTest.h"
22 #include <SettingServerClient.h>
24 // EXTERNAL DATA STRUCTURES
25 //extern ?external_data;
27 // EXTERNAL FUNCTION PROTOTYPES
28 //extern ?external_function( ?arg_type,?arg_type );
31 //const ?type ?constant_var = ?constant;
34 //#define ?macro ?macro_def
36 // LOCAL CONSTANTS AND MACROS
37 //const ?type ?constant_var = ?constant;
38 //#define ?macro_name ?macro_def
40 // MODULE DATA STRUCTURES
42 //typedef ?declaration
44 // LOCAL FUNCTION PROTOTYPES
45 //?type ?function_name( ?arg_type, ?arg_type );
47 // FORWARD DECLARATIONS
48 //class ?FORWARD_CLASSNAME;
50 // ============================= LOCAL FUNCTIONS ===============================
52 // -----------------------------------------------------------------------------
53 // ?function_name ?description.
55 // Returns: ?value_1: ?description
56 // ?value_n: ?description_line1
58 // -----------------------------------------------------------------------------
62 ?arg_type arg, // ?description
63 ?arg_type arg) // ?description
73 // ============================ MEMBER FUNCTIONS ===============================
75 // -----------------------------------------------------------------------------
76 // CwidecharclassapiBCTest::CwidecharclassapiBCTest
77 // C++ default constructor can NOT contain any code, that
79 // -----------------------------------------------------------------------------
81 CwidecharclassapiBCTest::CwidecharclassapiBCTest()
86 // -----------------------------------------------------------------------------
87 // CwidecharclassapiBCTest::ConstructL
88 // Symbian 2nd phase constructor can leave.
90 // Note: If OOM test case uses STIF Logger, then STIF Logger must be created
91 // with static buffer size parameter (aStaticBufferSize). Otherwise Logger
92 // allocates memory from heap and therefore causes error situations with OOM
93 // testing. For more information about STIF Logger construction, see STIF Users
95 // -----------------------------------------------------------------------------
97 void CwidecharclassapiBCTest::ConstructL()
99 //Read logger settings to check whether test case name is to be
100 //appended to log file name.
101 RSettingServer settingServer;
102 TInt ret = settingServer.Connect();
107 // Struct to StifLogger settigs.
108 TLoggerSettings loggerSettings;
109 // Parse StifLogger defaults from STIF initialization file.
110 ret = settingServer.GetLoggerSettings(loggerSettings);
115 // Close Setting server session
116 settingServer.Close();
117 iAddTestCaseTitleToLogName = loggerSettings.iAddTestCaseTitle;
119 iStdLog = CStifLogger::NewL( KwidecharclassapiBCTestLogPath,
120 KwidecharclassapiBCTestLogFile);
123 // Sample how to use logging
124 _LIT( KLogStart, "widecharclassapiBCTest logging starts!" );
125 iLog->Log( KLogStart );
127 iVersionLogged = EFalse;
130 // -----------------------------------------------------------------------------
131 // CwidecharclassapiBCTest::NewL
132 // Two-phased constructor.
133 // -----------------------------------------------------------------------------
135 CwidecharclassapiBCTest* CwidecharclassapiBCTest::NewL()
137 CwidecharclassapiBCTest* self = new (ELeave) CwidecharclassapiBCTest;
139 CleanupStack::PushL( self );
148 CwidecharclassapiBCTest::~CwidecharclassapiBCTest()
157 // -----------------------------------------------------------------------------
158 // CwidecharclassapiBCTest::InitL
159 // InitL is used to initialize the Test Module.
160 // -----------------------------------------------------------------------------
162 TInt CwidecharclassapiBCTest::InitL(
163 TFileName& /*aIniFile*/,
164 TBool /*aFirstTime*/ )
170 // -----------------------------------------------------------------------------
171 // CwidecharclassapiBCTest::GetTestCasesL
172 // GetTestCases is used to inquire test cases from the Test Module. Test
173 // cases are stored to array of test cases. The Test Framework will be
174 // the owner of the data in the RPointerArray after GetTestCases return
175 // and it does the memory deallocation.
176 // -----------------------------------------------------------------------------
178 TInt CwidecharclassapiBCTest::GetTestCasesL(
179 const TFileName& /*aConfig*/,
180 RPointerArray<TTestCaseInfo>& aTestCases )
183 // Loop through all test cases and create new
184 // TTestCaseInfo items and append items to aTestCase array
185 for( TInt i = 0; Case(i).iMethod != NULL; i++ )
188 // Allocate new TTestCaseInfo from heap for a testcase definition.
189 TTestCaseInfo* newCase = new( ELeave ) TTestCaseInfo();
191 // PushL TTestCaseInfo to CleanupStack.
192 CleanupStack::PushL( newCase );
194 // Set number for the testcase.
195 // When the testcase is run, this comes as a parameter to RunTestCaseL.
196 newCase->iCaseNumber = i;
198 // Set title for the test case. This is shown in UI to user.
199 newCase->iTitle.Copy( Case(i).iCaseName );
201 // Append TTestCaseInfo to the testcase array. After appended
202 // successfully the TTestCaseInfo object is owned (and freed)
203 // by the TestServer.
204 User::LeaveIfError(aTestCases.Append ( newCase ) );
206 // Pop TTestCaseInfo from the CleanupStack.
207 CleanupStack::Pop( newCase );
215 // -----------------------------------------------------------------------------
216 // CwidecharclassapiBCTest::RunTestCaseL
217 // RunTestCaseL is used to run an individual test case specified
218 // by aTestCase. Test cases that can be run may be requested from
219 // Test Module by GetTestCases method before calling RunTestCase.
220 // -----------------------------------------------------------------------------
222 TInt CwidecharclassapiBCTest::RunTestCaseL(
223 const TInt aCaseNumber,
224 const TFileName& /*aConfig*/,
225 TTestResult& aResult )
229 SendTestModuleVersion();
230 iVersionLogged = ETrue;
234 TInt execStatus = KErrNone;
236 // Get the pointer to test case function
237 TCaseInfo tmp = Case ( aCaseNumber );
239 _LIT( KLogStartTC, "Starting testcase [%S]" );
240 iLog->Log( KLogStartTC, &tmp.iCaseName);
242 // Check that case number was valid
243 if ( tmp.iMethod != NULL )
245 //Open new log file with test case title in file name
246 if(iAddTestCaseTitleToLogName)
248 //Delete test case logger if exists
255 TFileName logFileName;
257 TestModuleIf().GetTestCaseTitleL(title);
259 logFileName.Format(KwidecharclassapiBCTestLogFileWithTitle, &title);
261 iTCLog = CStifLogger::NewL(KwidecharclassapiBCTestLogPath,
266 // Valid case was found, call it via function pointer
267 iMethod = tmp.iMethod;
268 //execStatus = ( this->*iMethod )( aResult );
269 TRAPD(err, execStatus = ( this->*iMethod )( aResult ));
270 if(iAddTestCaseTitleToLogName)
272 //Restore standard log and destroy test case logger
274 delete iTCLog; //Close test case log
277 User::LeaveIfError(err);
281 // Valid case was not found, return error.
282 execStatus = KErrNotFound;
285 // Return case execution status (not the result of the case execution)
290 // -----------------------------------------------------------------------------
291 // CwidecharclassapiBCTest::OOMTestQueryL
292 // Used to check if a particular test case should be run in OOM conditions and
293 // which memory allocations should fail.
294 // -----------------------------------------------------------------------------
296 TBool CwidecharclassapiBCTest::OOMTestQueryL(
297 const TFileName& /* aTestCaseFile */,
298 const TInt aCaseNumber,
299 TOOMFailureType& /* aFailureType */,
300 TInt& aFirstMemFailure,
301 TInt& aLastMemFailure )
303 _LIT( KLogOOMTestQueryL, "CwidecharclassapiBCTest::OOMTestQueryL" );
304 iLog->Log( KLogOOMTestQueryL );
306 aFirstMemFailure = Case( aCaseNumber ).iFirstMemoryAllocation;
307 aLastMemFailure = Case( aCaseNumber ).iLastMemoryAllocation;
309 return Case( aCaseNumber ).iIsOOMTest;
313 // -----------------------------------------------------------------------------
314 // CwidecharclassapiBCTest::OOMTestInitializeL
315 // Used to perform the test environment setup for a particular OOM test case.
316 // Test Modules may use the initialization file to read parameters for Test
317 // Module initialization but they can also have their own configure file or
318 // some other routine to initialize themselves.
320 // NOTE: User may add implementation for OOM test environment initialization.
321 // Usually no implementation is required.
322 // -----------------------------------------------------------------------------
324 void CwidecharclassapiBCTest::OOMTestInitializeL(
325 const TFileName& /* aTestCaseFile */,
326 const TInt /* aCaseNumber */ )
330 // -----------------------------------------------------------------------------
331 // CwidecharclassapiBCTest::OOMHandleWarningL
332 // In some cases the heap memory allocation should be skipped, either due to
333 // problems in the OS code or components used by the code being tested, or even
334 // inside the tested components which are implemented this way on purpose (by
335 // design), so it is important to give the tester a way to bypass allocation
338 // NOTE: User may add implementation for OOM test warning handling. Usually no
339 // implementation is required.
340 // -----------------------------------------------------------------------------
342 void CwidecharclassapiBCTest::OOMHandleWarningL(
343 const TFileName& /* aTestCaseFile */,
344 const TInt /* aCaseNumber */,
345 TInt& /* aFailNextValue */ )
349 // -----------------------------------------------------------------------------
350 // CwidecharclassapiBCTest::OOMTestFinalizeL
351 // Used to perform the test environment cleanup for a particular OOM test case.
353 // NOTE: User may add implementation for OOM test environment finalization.
354 // Usually no implementation is required.
355 // -----------------------------------------------------------------------------
357 void CwidecharclassapiBCTest::OOMTestFinalizeL(
358 const TFileName& /* aTestCaseFile */,
359 const TInt /* aCaseNumber */ )
363 //-----------------------------------------------------------------------------
364 // CwidecharclassapiBCTest::SendTestModuleVersion
365 // Method used to send version of test module
366 //-----------------------------------------------------------------------------
368 void CwidecharclassapiBCTest::SendTestModuleVersion()
370 TVersion moduleVersion;
371 moduleVersion.iMajor = TEST_MODULE_VERSION_MAJOR;
372 moduleVersion.iMinor = TEST_MODULE_VERSION_MINOR;
373 moduleVersion.iBuild = TEST_MODULE_VERSION_BUILD;
375 TFileName moduleName;
376 moduleName = _L("widecharclassapiBCTest.dll");
378 TestModuleIf().SendTestModuleVersion(moduleVersion, moduleName);
381 // ========================== OTHER EXPORTED FUNCTIONS =========================
383 // -----------------------------------------------------------------------------
384 // LibEntryL is a polymorphic Dll entry point
385 // Returns: CTestModuleBase*: Pointer to Test Module object
386 // -----------------------------------------------------------------------------
388 EXPORT_C CTestModuleBase* LibEntryL()
390 return CwidecharclassapiBCTest::NewL();
394 // -----------------------------------------------------------------------------
395 // SetRequirements handles test module parameters(implements evolution
396 // version 1 for test module's heap and stack sizes configuring).
397 // Returns: TInt: Symbian error code.
398 // -----------------------------------------------------------------------------
400 EXPORT_C TInt SetRequirements( CTestModuleParam*& /*aTestModuleParam*/,
401 TUint32& /*aParameterValid*/ )
404 /* --------------------------------- NOTE ---------------------------------
405 USER PANICS occurs in test thread creation when:
406 1) "The panic occurs when the value of the stack size is negative."
407 2) "The panic occurs if the minimum heap size specified is less
409 KMinHeapSize: "Functions that require a new heap to be allocated will
410 either panic, or will reset the required heap size to this value if
411 a smaller heap size is specified".
412 3) "The panic occurs if the minimum heap size specified is greater than
413 the maximum size to which the heap can grow".
415 1) Make sure that your hardware or Symbian OS is supporting given sizes.
416 e.g. Hardware might support only sizes that are divisible by four.
417 ------------------------------- NOTE end ------------------------------- */
419 // Normally STIF uses default heap and stack sizes for test thread, see:
420 // KTestThreadMinHeap, KTestThreadMinHeap and KStackSize.
421 // If needed heap and stack sizes can be configured here by user. Remove
422 // comments and define sizes.
425 aParameterValid = KStifTestModuleParameterChanged;
427 CTestModuleParamVer01* param = CTestModuleParamVer01::NewL();
429 param->iTestThreadStackSize= 16384; // 16K stack
431 param->iTestThreadMinHeap = 4096; // 4K heap min
432 param->iTestThreadMaxHeap = 1048576;// 1M heap max
434 aTestModuleParam = param;