1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32math.h> |
|
22 #include "demomodule.h" |
|
23 |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 // None |
|
26 |
|
27 // EXTERNAL FUNCTION PROTOTYPES |
|
28 // None |
|
29 |
|
30 // CONSTANTS |
|
31 // None |
|
32 |
|
33 // MACROS |
|
34 // None |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 // None |
|
38 |
|
39 // MODULE DATA STRUCTURES |
|
40 // None |
|
41 |
|
42 // LOCAL FUNCTION PROTOTYPES |
|
43 // None |
|
44 |
|
45 // FORWARD DECLARATIONS |
|
46 // None |
|
47 |
|
48 // ==================== LOCAL FUNCTIONS ======================================= |
|
49 |
|
50 |
|
51 /* |
|
52 ------------------------------------------------------------------------------- |
|
53 |
|
54 DESCRIPTION |
|
55 |
|
56 This module contains the implementation of CTestModuleCommon class |
|
57 member functions that does the actual tests. |
|
58 |
|
59 ------------------------------------------------------------------------------- |
|
60 */ |
|
61 |
|
62 // ================= MEMBER FUNCTIONS ========================================= |
|
63 |
|
64 /* |
|
65 ------------------------------------------------------------------------------- |
|
66 |
|
67 Class: CTestModuleCommon |
|
68 |
|
69 Method: Case |
|
70 |
|
71 Description: Returns a test case by number. |
|
72 |
|
73 This function contains an array of all available test cases |
|
74 i.e pair of case name and test function. If case specified by parameter |
|
75 aCaseNumber is found from array, then that item is returned. |
|
76 |
|
77 The reason for this rather complicated function is to specify all the |
|
78 test cases only in one place. It is not necessary to understand how |
|
79 function pointers to class member functions works when adding new test |
|
80 cases. See function body for instructions how to add new test case. |
|
81 |
|
82 Parameters: const TInt aCaseNumber :in: Test case number |
|
83 |
|
84 Return Values: const TCaseInfo Struct containing case name & function |
|
85 |
|
86 Errors/Exceptions: None |
|
87 |
|
88 Status: Proposal |
|
89 |
|
90 ------------------------------------------------------------------------------- |
|
91 */ |
|
92 const TCaseInfo CTestModuleCommon::Case ( const TInt aCaseNumber ) const |
|
93 { |
|
94 |
|
95 // NOTE!!! |
|
96 // To add new test cases, implement new test case class add construct it |
|
97 // in this classes ConstructL and append it to array. Add The number of test |
|
98 // cases to static TCaseInfoInternal KCases[ 50 ]. |
|
99 |
|
100 TInt numOfCases( KErrNone ); |
|
101 // Get amount of functions from all member testcase objects. |
|
102 for( TInt j( 0 ); j < iArray->Count(); j++ ) |
|
103 { |
|
104 numOfCases += iArray->At( j )->GetFunctionPtrArray()->Count(); |
|
105 } |
|
106 |
|
107 |
|
108 TInt currentCase( 0 ); |
|
109 // Go through the array of all member testcase objects. |
|
110 for( TInt i( 0 ); i < iArray->Count(); i++ ) |
|
111 { |
|
112 TInt amountOfFunctions( KErrNone ); |
|
113 CArrayFixFlat<MTestFunction>* functionArray = NULL; |
|
114 // Get the function pointer array of object nn from arrays place i. |
|
115 // No ownership ain't transferred. |
|
116 functionArray = iArray->At( i )->GetFunctionPtrArray(); |
|
117 amountOfFunctions = functionArray->Count(); |
|
118 // Go through all the functions of the object. |
|
119 for( TInt k( 0 ); k < amountOfFunctions; k++ ) |
|
120 { |
|
121 // Get casename for newCase from object nn at array place i for case number k. |
|
122 iTestCaseArray->At( currentCase ).iCaseName = iArray->At( i )->GetCaseNameL( k ); |
|
123 // Get method for newCase from functionArray at place k at object nn in place |
|
124 // i at array. |
|
125 iTestCaseArray->At( currentCase ).iMethod = ( functionArray->At( k ) ); |
|
126 // If the current case ain't the last case. |
|
127 if( currentCase < numOfCases ) |
|
128 { |
|
129 currentCase++; |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 // Verify that case number is valid |
|
135 if( aCaseNumber < 0 || aCaseNumber >= numOfCases ) |
|
136 { |
|
137 // Invalid case, construct empty object |
|
138 TCaseInfo null( (const TText*) L"", NULL ); |
|
139 null.iMethod = NULL; |
|
140 return null; |
|
141 } |
|
142 |
|
143 if( NULL == iTestCaseArray->At( aCaseNumber ).iCaseName ) |
|
144 { |
|
145 // Invalid case, construct empty object |
|
146 TCaseInfo null( (const TText*) L"", NULL ); |
|
147 null.iMethod = NULL; |
|
148 return null; |
|
149 } |
|
150 |
|
151 // Construct TCaseInfo object and return it |
|
152 TCaseInfo tmp ( iTestCaseArray->At( aCaseNumber ).iCaseName, |
|
153 iTestCaseArray->At( aCaseNumber ).iMethod ); |
|
154 |
|
155 return tmp; |
|
156 |
|
157 } |
|
158 |
|
159 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
160 |
|
161 // End of File |
|