|
1 /* |
|
2 * Copyright (c) 2006-2007 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 "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: Test case. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "bctestcase.h" |
|
20 |
|
21 const TInt KInitSize = 20; |
|
22 const TInt KGranularity = 5; |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Constructor |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C CBCTestCase::CBCTestCase() |
|
31 : iType( ENormalCase ) |
|
32 { |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Destructor |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CBCTestCase::~CBCTestCase() |
|
40 { |
|
41 delete [] iTestScripts; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CBCTestCase::RunL. |
|
46 // User needs to override this function. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C void CBCTestCase::RunL( TInt ) |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CBCTestCase::AppendL |
|
55 // Append a command to iTestScripts. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CBCTestCase::AppendL(TInt aCmd) |
|
59 { |
|
60 if ( !iTestScripts ) |
|
61 { |
|
62 iScriptCount = 0; |
|
63 iMaxSize = KInitSize; |
|
64 iTestScripts = new( ELeave ) TInt[iMaxSize]; |
|
65 } |
|
66 if ( iScriptCount == iMaxSize ) |
|
67 { |
|
68 iMaxSize += KGranularity; |
|
69 TInt* tempArray = new( ELeave ) TInt[iMaxSize]; |
|
70 for ( TInt i=0; i<iScriptCount; i++ ) |
|
71 { |
|
72 tempArray[i] = iTestScripts[i]; |
|
73 } |
|
74 delete [] iTestScripts; |
|
75 iTestScripts = tempArray; |
|
76 } |
|
77 iTestScripts[iScriptCount] = aCmd; |
|
78 iScriptCount++; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CBCTestCase::AddTestL |
|
83 // Add automatic test commands. |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C void CBCTestCase::AddTestL( TInt aCmd, ... ) |
|
87 { |
|
88 TInt cmd = aCmd; |
|
89 VA_LIST list; |
|
90 VA_START(list, aCmd); |
|
91 |
|
92 while ( cmd != TEND ) |
|
93 { |
|
94 AppendL( cmd ); |
|
95 cmd=VA_ARG( list, TInt ); |
|
96 } |
|
97 VA_END(list); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CBCTestCase::TestScripts |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 TInt* CBCTestCase::TestScripts() |
|
105 { |
|
106 return iTestScripts; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CBCTestCase::ScriptCount |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 TInt CBCTestCase::ScriptCount() |
|
114 { |
|
115 return iScriptCount; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CBCTestCase::AddTestScript |
|
120 // User can write all commands in a TInt array, then add it to test case. |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C void CBCTestCase::AddTestScriptL( const TInt* aCmdArray, TInt aCmdCount ) |
|
124 { |
|
125 if ( !aCmdArray || aCmdCount < 0 ) |
|
126 { |
|
127 User::Leave( KErrArgument ); |
|
128 } |
|
129 |
|
130 TInt count = iScriptCount + aCmdCount; |
|
131 if ( iMaxSize < count ) |
|
132 { |
|
133 TInt* temp = new( ELeave ) TInt[count]; |
|
134 for ( TInt i = 0; i < iScriptCount; i++ ) |
|
135 { |
|
136 temp[i] = iTestScripts[i]; |
|
137 } |
|
138 delete [] iTestScripts; |
|
139 iTestScripts = temp; |
|
140 iMaxSize = count; |
|
141 } |
|
142 for ( TInt i = 0; i < aCmdCount; i++ ) |
|
143 { |
|
144 iTestScripts[i + iScriptCount] = aCmdArray[i]; |
|
145 } |
|
146 iScriptCount = count; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CBCTestCase::Name |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 TDesC& CBCTestCase::Name() |
|
154 { |
|
155 return iName; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CBCTestCase::Name |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CBCTestCase::SetName( const TDesC& aName ) |
|
163 { |
|
164 iName.Zero(); |
|
165 iName.Append( aName ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CBCTestCase::Type |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CBCTestCase::Type() |
|
173 { |
|
174 return iType; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CBCTestCase::SetType |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CBCTestCase::SetType( TInt aType ) |
|
182 { |
|
183 iType = aType; |
|
184 } |