|
1 /* |
|
2 * Copyright (c) 2004 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ctfatesttimer.h> |
|
21 #include <ctfatestlog.h> |
|
22 #include <tftypes.h> |
|
23 #include "siftrace.h" |
|
24 #include "ctfdoscontrol.h" |
|
25 #include "ctfdoscontroltestcase.h" |
|
26 #include "ctfdoscontroltestcaseparam.h" |
|
27 |
|
28 CTFDosControlTestCaseParam::CTFDosControlTestCaseParam( void ) |
|
29 { |
|
30 } |
|
31 |
|
32 |
|
33 void CTFDosControlTestCaseParam::ConstructL( const TTFDosServerControlTestCaseState* aStates, TInt aStateCount ) |
|
34 { |
|
35 TRACE_ASSERT( aStates != NULL ); |
|
36 TRACE_ASSERT( aStateCount > 0 ); |
|
37 iStates = REINTERPRET_CAST( TTFDosServerControlTestCaseState*, User::Alloc( sizeof ( TTFDosServerControlTestCaseState ) * aStateCount ) ); |
|
38 User::LeaveIfNull( iStates ); |
|
39 Mem::Copy( iStates, aStates, sizeof ( TTFDosServerControlTestCaseState ) * aStateCount ); |
|
40 iStateCount = aStateCount; |
|
41 } |
|
42 |
|
43 |
|
44 CTFDosControlTestCaseParam::~CTFDosControlTestCaseParam( void ) |
|
45 { |
|
46 User::Free( iStates ); |
|
47 iStates = NULL; |
|
48 } |
|
49 |
|
50 |
|
51 const TTFDosServerControlTestCaseState* CTFDosControlTestCaseParam::States( void ) const |
|
52 { |
|
53 return iStates; |
|
54 } |
|
55 |
|
56 |
|
57 TInt CTFDosControlTestCaseParam::StateCount( void ) const |
|
58 { |
|
59 return iStateCount; |
|
60 } |
|
61 |
|
62 |
|
63 CTFDosControlTestCase::CTFDosControlTestCase( CTFDosControlTestCaseParam* aParameters ) |
|
64 : CTFStubTestCase( KTFStubTypeDosServerControl ) |
|
65 , iParameters( aParameters ) |
|
66 { |
|
67 TRACE_ASSERT( aParameters != NULL ); |
|
68 if ( aParameters != NULL ) |
|
69 { |
|
70 TRACE_ASSERT( aParameters->States() != NULL ); |
|
71 TRACE_ASSERT( aParameters->StateCount() > 0 ); |
|
72 } |
|
73 } |
|
74 |
|
75 |
|
76 void CTFDosControlTestCase::ConstructL( void ) |
|
77 { |
|
78 iTimer = CTFATestTimer::NewL( *this ); |
|
79 } |
|
80 |
|
81 |
|
82 CTFDosControlTestCase::~CTFDosControlTestCase( void ) |
|
83 { |
|
84 delete iParameters; |
|
85 delete iTimer; |
|
86 } |
|
87 |
|
88 |
|
89 void CTFDosControlTestCase::Log( TInt aDepth ) |
|
90 { |
|
91 _LIT( KStart, "DosServer control component, %d states" ); |
|
92 _LIT( KState, "Flags: %d %d %d %d %d" ); |
|
93 Logger().WriteList( aDepth, KStart, iParameters->StateCount() ); |
|
94 for ( TInt i = 0; i < iParameters->StateCount(); i++ ) |
|
95 { |
|
96 Logger().WriteList( aDepth + 1, KState, |
|
97 iParameters->States()[i].iDosFunction, |
|
98 iParameters->States()[i].iArg1, |
|
99 iParameters->States()[i].iArg2, |
|
100 iParameters->States()[i].iExpectedResult, |
|
101 iParameters->States()[i].iCompletionEvent ); |
|
102 } |
|
103 } |
|
104 |
|
105 |
|
106 void CTFDosControlTestCase::InitL( void ) |
|
107 { |
|
108 iCleanupWait = EFalse; |
|
109 iCurrentStateIndex = 0; |
|
110 iCurrentState = iParameters->States()[iCurrentStateIndex]; |
|
111 } |
|
112 |
|
113 |
|
114 void CTFDosControlTestCase::ActiveTestRunL( void ) |
|
115 { |
|
116 if ( iCleanupWait ) |
|
117 { |
|
118 CActiveScheduler::Stop(); |
|
119 } |
|
120 else |
|
121 { |
|
122 RunL(); |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 void CTFDosControlTestCase::RunL( void ) |
|
128 { |
|
129 TInt result = KErrNone; |
|
130 if ( iCurrentState.iDosFunction != 0 ) |
|
131 { |
|
132 if ( iCurrentState.iDosFunction == ETFDosEvent_Synchronized ) |
|
133 { |
|
134 // Wait event to start next state! |
|
135 } |
|
136 else |
|
137 { |
|
138 TRAP( result, CallCurrentDosFunctionL() ); |
|
139 StartNextState( result ); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 void CTFDosControlTestCase::Teardown( void ) |
|
146 { |
|
147 // If the test is terminated by a failing stub test case, |
|
148 // the timer may be left active and thus must be cancelled. |
|
149 iTimer->Cancel(); |
|
150 iTimer->After( 100000 ); // 100-ms timeout to wait for pending events. |
|
151 iCleanupWait = ETrue; |
|
152 CActiveScheduler::Start(); |
|
153 } |
|
154 |
|
155 |
|
156 void CTFDosControlTestCase::NotifyDosEvent( TInt aEvent, TInt aParameter ) |
|
157 { |
|
158 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::NotifyDosEvent(%d, %d)"), aEvent, aParameter ) ); |
|
159 |
|
160 iCurrentState = iParameters->States()[iCurrentStateIndex]; |
|
161 |
|
162 if ( !IsComplete() ) |
|
163 { |
|
164 if ( aEvent == iCurrentState.iCompletionEvent && iCurrentState.iArg1 == aParameter ) |
|
165 { |
|
166 StartNextState( KErrNone ); |
|
167 } |
|
168 else |
|
169 { |
|
170 DoCompleteTest( KTFErrDosUnexpectedEvent ); |
|
171 } |
|
172 } |
|
173 else |
|
174 { |
|
175 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::NotifyDosEvent() - Test already finished" ) ) ); |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 void CTFDosControlTestCase::DoCompleteTest( TInt aResult ) |
|
181 { |
|
182 iTimer->Cancel(); |
|
183 CompleteTest( aResult ); |
|
184 } |
|
185 |
|
186 |
|
187 void CTFDosControlTestCase::CallCurrentDosFunctionL( void ) |
|
188 { |
|
189 TRACE_ASSERT( iStub != NULL ); |
|
190 if ( iStub != NULL ) |
|
191 { |
|
192 STATIC_CAST( CTFDosControl*, iStub )->CallDosFunctionL( iCurrentState ); |
|
193 } |
|
194 else |
|
195 { |
|
196 User::Leave( KTFErrNoStub ); |
|
197 } |
|
198 } |
|
199 |
|
200 |
|
201 CTFDosControlTestCaseParam& CTFDosControlTestCase::Parameters( void ) |
|
202 { |
|
203 return *iParameters; |
|
204 } |
|
205 |
|
206 |
|
207 TTFDosFunction CTFDosControlTestCase::CurrentDosFunction( void ) const |
|
208 { |
|
209 return iCurrentState.iDosFunction; |
|
210 } |
|
211 |
|
212 |
|
213 TInt CTFDosControlTestCase::CurrentArg1( void ) const |
|
214 { |
|
215 return iCurrentState.iArg1; |
|
216 } |
|
217 |
|
218 |
|
219 TInt CTFDosControlTestCase::CurrentStateIndex( void ) const |
|
220 { |
|
221 return iCurrentStateIndex; |
|
222 } |
|
223 |
|
224 |
|
225 CTFATestTimer* CTFDosControlTestCase::Timer( void ) |
|
226 { |
|
227 return iTimer; |
|
228 } |
|
229 |
|
230 |
|
231 void CTFDosControlTestCase::StartNextState( TInt aResult ) |
|
232 { |
|
233 if ( aResult != KErrNone ) |
|
234 { |
|
235 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::StartNextState() - Test case failed: %d" ), aResult ) ); |
|
236 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::StartNextState() - Failed state: %d" ), iCurrentStateIndex ) ); |
|
237 DoCompleteTest( aResult ); |
|
238 |
|
239 } |
|
240 else if ( iCurrentStateIndex == iParameters->StateCount() - 1 ) |
|
241 { |
|
242 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::StartNextState() - Test case complete" ) ) ); |
|
243 DoCompleteTest( KErrNone ); |
|
244 } |
|
245 else |
|
246 { |
|
247 TEST_CASE_TRACE( ( _L( "CTFDosServerControlTestCase::StartNextState() - Starting state %d" ), iCurrentStateIndex + 1 ) ); |
|
248 iCurrentStateIndex++; |
|
249 iCurrentState = iParameters->States()[iCurrentStateIndex]; |
|
250 if ( !iTimer->IsActive() ) |
|
251 { |
|
252 iTimer->After( 100000 ); // Timer calls RunL |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 TInt CTFDosControlTestCase::CheckResult( TInt aResult ) |
|
258 { |
|
259 |
|
260 TInt result(KErrNone); |
|
261 |
|
262 if ( aResult == iParameters->States()[iCurrentStateIndex].iExpectedResult ) |
|
263 { |
|
264 result = KErrNone; |
|
265 } |
|
266 else |
|
267 { |
|
268 result = aResult; |
|
269 } |
|
270 |
|
271 return result; |
|
272 } |
|
273 |
|
274 |