2
|
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 "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: This file contains TestScripterImp implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include <StifTestInterface.h>
|
|
20 |
#include <StifParser.h>
|
|
21 |
#include "TestScripterInternal.h"
|
|
22 |
#include "TestScripter.h"
|
|
23 |
// EXTERNAL DATA STRUCTURES
|
|
24 |
//extern ?external_data;
|
|
25 |
|
|
26 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
27 |
//extern ?external_function( ?arg_type,?arg_type );
|
|
28 |
|
|
29 |
// CONSTANTS
|
|
30 |
//const ?type ?constant_var = ?constant;
|
|
31 |
|
|
32 |
// MACROS
|
|
33 |
//#define ?macro ?macro_def
|
|
34 |
|
|
35 |
// LOCAL CONSTANTS AND MACROS
|
|
36 |
//const ?type ?constant_var = ?constant;
|
|
37 |
//#define ?macro_name ?macro_def
|
|
38 |
|
|
39 |
// MODULE DATA STRUCTURES
|
|
40 |
//enum ?declaration
|
|
41 |
//typedef ?declaration
|
|
42 |
|
|
43 |
// LOCAL FUNCTION PROTOTYPES
|
|
44 |
//?type ?function_name( ?arg_type, ?arg_type );
|
|
45 |
|
|
46 |
// FORWARD DECLARATIONS
|
|
47 |
//class ?FORWARD_CLASSNAME;
|
|
48 |
|
|
49 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
50 |
|
|
51 |
// None
|
|
52 |
|
|
53 |
|
|
54 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
55 |
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
// CScriptBase::CScriptBase
|
|
58 |
// Constructor.
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
EXPORT_C CScriptBase::CScriptBase( CTestModuleIf& aTestModuleIf ):
|
|
62 |
iTestModuleIf( aTestModuleIf )
|
|
63 |
{
|
|
64 |
// Handles multible 'waittestclass' given in test configure file.
|
|
65 |
iSignalErrors.Reset();
|
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
// CScriptBase::TestModuleIf
|
|
72 |
// Get reference to TestModuleIf API.
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
EXPORT_C CTestModuleIf& CScriptBase::TestModuleIf()
|
|
76 |
{
|
|
77 |
|
|
78 |
return iTestModuleIf;
|
|
79 |
|
|
80 |
}
|
|
81 |
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
// CScriptBase::Signal
|
|
84 |
// Signal TestScripter to continue from waittestclass.
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
EXPORT_C void CScriptBase::Signal( TInt aError )
|
|
88 |
{
|
|
89 |
|
|
90 |
if( iStatus )
|
|
91 |
{
|
|
92 |
User::RequestComplete( iStatus, aError );
|
|
93 |
}
|
|
94 |
else
|
|
95 |
{
|
|
96 |
// Handles multible 'waittestclass' given in test configure file.
|
|
97 |
// There is active object in CTestRunner also and it has higher
|
|
98 |
// priority than CTestContinue(It must be higher that e.g.
|
|
99 |
// 'allownextresult' is gotten right from configure file). That why we
|
|
100 |
// have to use this array and take signal "count" to the array for
|
|
101 |
// later handling.
|
|
102 |
iSignalErrors.Append( aError );
|
|
103 |
}
|
|
104 |
|
|
105 |
}
|
|
106 |
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
// CScriptBase::CallTestClass
|
|
109 |
// Called from test class. TestScripter forwards
|
|
110 |
// operations to other test class object.
|
|
111 |
// aLine: in: <object name> <method name> <parameters>
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
EXPORT_C TInt CScriptBase::CallTestClass( const TDesC& aLine )
|
|
115 |
{
|
|
116 |
|
|
117 |
if( iFunc )
|
|
118 |
{
|
|
119 |
return iFunc( iTestScripter, EStifTSCallClass, aLine );
|
|
120 |
}
|
|
121 |
|
|
122 |
return KErrNotSupported;
|
|
123 |
|
|
124 |
};
|
|
125 |
|
|
126 |
// -----------------------------------------------------------------------------
|
|
127 |
// CScriptBase::GetTestObject
|
|
128 |
// Get test class object address.
|
|
129 |
// -----------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
EXPORT_C CScriptBase* CScriptBase::GetTestObject( const TDesC& aObjectName )
|
|
132 |
{
|
|
133 |
|
|
134 |
if( iFunc )
|
|
135 |
{
|
|
136 |
TInt ret = iFunc( iTestScripter, EStifTSGetObject, aObjectName );
|
|
137 |
if( ret > 0 )
|
|
138 |
{
|
|
139 |
return( CScriptBase* )ret;
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
return NULL;
|
|
144 |
};
|
|
145 |
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
// CScriptBase::EnableSignal
|
|
148 |
// Enable Signal().
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
EXPORT_C void CScriptBase::EnableSignal( TRequestStatus& aStatus )
|
|
152 |
{
|
|
153 |
|
|
154 |
aStatus = KRequestPending;
|
|
155 |
iStatus = &aStatus;
|
|
156 |
|
|
157 |
// Handles multible 'waittestclass' given in test configure file.
|
|
158 |
if( iSignalErrors.Count() > 0 )
|
|
159 |
{
|
|
160 |
// Complete signal and remove it from array.
|
|
161 |
TInt error = iSignalErrors[0];
|
|
162 |
iSignalErrors.Remove( 0 );
|
|
163 |
User::RequestComplete( iStatus, error );
|
|
164 |
}
|
|
165 |
|
|
166 |
}
|
|
167 |
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
// CScriptBase::CancelSignal
|
|
170 |
// Cancel Signal().
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
EXPORT_C void CScriptBase::CancelSignal()
|
|
174 |
{
|
|
175 |
if(iStatus!=NULL)
|
|
176 |
{
|
|
177 |
User::RequestComplete( iStatus, KErrCancel );
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
// -----------------------------------------------------------------------------
|
|
182 |
// CScriptBase::SetScripter
|
|
183 |
// Set scripter callback.
|
|
184 |
// -----------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
EXPORT_C void CScriptBase::SetScripter( CallBackFunc aFunc, CTestScripter* aTestScripter )
|
|
187 |
{
|
|
188 |
|
|
189 |
iTestScripter = aTestScripter;
|
|
190 |
iFunc = aFunc;
|
|
191 |
|
|
192 |
}
|
|
193 |
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
// CScriptBase::RunInternalL
|
|
196 |
// Run specified method from test class.
|
|
197 |
// -----------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
EXPORT_C TInt CScriptBase::RunInternalL (
|
|
200 |
TStifFunctionInfo const aFunctions[],
|
|
201 |
TInt aCount,
|
|
202 |
CStifItemParser& aItem )
|
|
203 |
{
|
|
204 |
|
|
205 |
TInt ret = KErrNotFound;
|
|
206 |
|
|
207 |
TPtrC command;
|
|
208 |
User::LeaveIfError ( aItem.GetNextString( command ) );
|
|
209 |
TInt i = 0;
|
|
210 |
TName funcName;
|
|
211 |
|
|
212 |
// Search function from table and call it
|
|
213 |
for ( i = 0; i < aCount; i++ )
|
|
214 |
{
|
|
215 |
funcName = aFunctions[i].iFunctionName;
|
|
216 |
if ( command == funcName )
|
|
217 |
{
|
|
218 |
if( iLog )
|
|
219 |
{
|
|
220 |
iLog->Log(_L("Calling [%S]"), &command );
|
|
221 |
}
|
|
222 |
ret = ( this->*(aFunctions[i].iMethod) )( aItem );
|
|
223 |
|
|
224 |
break;
|
|
225 |
}
|
|
226 |
|
|
227 |
}
|
|
228 |
|
|
229 |
if( i == aCount )
|
|
230 |
{
|
|
231 |
iLog->Log( _L("[%S] not found"), &command );
|
|
232 |
}
|
|
233 |
|
|
234 |
return ret;
|
|
235 |
|
|
236 |
}
|
|
237 |
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
// CScriptBase::GetConstantValue
|
|
240 |
// Internal fuction to get const value defined in
|
|
241 |
// [Define]...[Enddefine] section of script file
|
|
242 |
// -----------------------------------------------------------------------------
|
|
243 |
//
|
|
244 |
EXPORT_C TInt CScriptBase::GetConstantValue( const TDesC& aName, TDes& aValue )
|
|
245 |
{
|
|
246 |
return iTestScripter->GetConstantValue( aName, aValue );
|
|
247 |
}
|
|
248 |
|
|
249 |
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
// CScriptBase::GetConstantValue
|
|
252 |
// Internal fuction to get const value defined in
|
|
253 |
// [Define]...[Enddefine] section of script file
|
|
254 |
// -----------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
EXPORT_C TInt CScriptBase::GetConstantValue( const TDesC& aName, TInt& aValue )
|
|
257 |
{
|
|
258 |
TInt ret = KErrNone;
|
|
259 |
TBuf<32> valStr;
|
|
260 |
ret = iTestScripter->GetConstantValue( aName, valStr );
|
|
261 |
if ( ret != KErrNone )
|
|
262 |
{
|
|
263 |
return ret;
|
|
264 |
}
|
|
265 |
|
|
266 |
TLex converter( valStr );
|
|
267 |
ret = converter.Val( aValue );
|
|
268 |
|
|
269 |
return ret;
|
|
270 |
}
|
|
271 |
|
|
272 |
// -----------------------------------------------------------------------------
|
|
273 |
// CScriptBase::GetConstantValue
|
|
274 |
// Internal fuction to get const value defined in
|
|
275 |
// [Define]...[Enddefine] section of script file
|
|
276 |
// -----------------------------------------------------------------------------
|
|
277 |
//
|
|
278 |
EXPORT_C TInt CScriptBase::GetConstantValue( const TDesC& aName, TReal& aValue )
|
|
279 |
{
|
|
280 |
TInt ret = KErrNone;
|
|
281 |
TBuf<32> valStr;
|
|
282 |
ret = iTestScripter->GetConstantValue( aName, valStr );
|
|
283 |
if ( ret != KErrNone )
|
|
284 |
{
|
|
285 |
return ret;
|
|
286 |
}
|
|
287 |
|
|
288 |
TLex converter( valStr );
|
|
289 |
ret = converter.Val( aValue );
|
|
290 |
|
|
291 |
return ret;
|
|
292 |
}
|
|
293 |
|
|
294 |
// -----------------------------------------------------------------------------
|
|
295 |
// CScriptBase::SetResultDescription
|
|
296 |
// Result description can be set from within the test class method
|
|
297 |
// -----------------------------------------------------------------------------
|
|
298 |
//
|
|
299 |
EXPORT_C void CScriptBase::SetResultDescription(const TDesC& aDescription)
|
|
300 |
{
|
|
301 |
iTestScripter->SetResultDescription(aDescription);
|
|
302 |
}
|
|
303 |
|
|
304 |
// -----------------------------------------------------------------------------
|
|
305 |
// CScriptBase::SetLocalValue
|
|
306 |
// Internal fuction to set local value
|
|
307 |
// -----------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
EXPORT_C TInt CScriptBase::SetLocalValue(const TDesC& aName, const TDesC& aValue)
|
|
310 |
{
|
|
311 |
return iTestScripter->SetLocalValue(aName, aValue);
|
|
312 |
}
|
|
313 |
|
|
314 |
// -----------------------------------------------------------------------------
|
|
315 |
// CScriptBase::SetLocalValue
|
|
316 |
// Internal fuction to set local value
|
|
317 |
// -----------------------------------------------------------------------------
|
|
318 |
//
|
|
319 |
EXPORT_C TInt CScriptBase::SetLocalValue(const TDesC& aName, const TInt aValue)
|
|
320 |
{
|
|
321 |
TBuf<20> buf;
|
|
322 |
buf.Format(_L("%d"), aValue);
|
|
323 |
return iTestScripter->SetLocalValue(aName, buf);
|
|
324 |
}
|
|
325 |
|
|
326 |
// -----------------------------------------------------------------------------
|
|
327 |
// CScriptBase::SetLocalValue
|
|
328 |
// Internal fuction to set local value
|
|
329 |
// -----------------------------------------------------------------------------
|
|
330 |
//
|
|
331 |
EXPORT_C TInt CScriptBase::SetLocalValue(const TDesC& aName, const TReal aValue )
|
|
332 |
{
|
|
333 |
TBuf<50> buf;
|
|
334 |
buf.Format(_L("%g"), aValue);
|
|
335 |
return iTestScripter->SetLocalValue(aName, buf);
|
|
336 |
}
|
|
337 |
|
|
338 |
// -----------------------------------------------------------------------------
|
|
339 |
// CScriptBase::GetLocalValue
|
|
340 |
// Internal fuction to get local value
|
|
341 |
// -----------------------------------------------------------------------------
|
|
342 |
//
|
|
343 |
EXPORT_C TInt CScriptBase::GetLocalValue(const TDesC& aName, TDes& aValue)
|
|
344 |
{
|
|
345 |
return iTestScripter->GetLocalValue(aName, aValue);
|
|
346 |
}
|
|
347 |
|
|
348 |
// -----------------------------------------------------------------------------
|
|
349 |
// CScriptBase::GetLocalValue
|
|
350 |
// Internal fuction to get local value
|
|
351 |
// -----------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
EXPORT_C TInt CScriptBase::GetLocalValue(const TDesC& aName, TInt& aValue)
|
|
354 |
{
|
|
355 |
TInt ret = KErrNone;
|
|
356 |
TBuf<50> valStr;
|
|
357 |
ret = iTestScripter->GetLocalValue(aName, valStr);
|
|
358 |
if(ret != KErrNone)
|
|
359 |
{
|
|
360 |
return ret;
|
|
361 |
}
|
|
362 |
|
|
363 |
TLex converter(valStr);
|
|
364 |
ret = converter.Val(aValue);
|
|
365 |
|
|
366 |
return ret;
|
|
367 |
}
|
|
368 |
|
|
369 |
// -----------------------------------------------------------------------------
|
|
370 |
// CScriptBase::GetLocalValue
|
|
371 |
// Internal fuction to get local value
|
|
372 |
// -----------------------------------------------------------------------------
|
|
373 |
//
|
|
374 |
EXPORT_C TInt CScriptBase::GetLocalValue(const TDesC& aName, TReal& aValue )
|
|
375 |
{
|
|
376 |
TInt ret = KErrNone;
|
|
377 |
TBuf<50> valStr;
|
|
378 |
ret = iTestScripter->GetLocalValue(aName, valStr);
|
|
379 |
if(ret != KErrNone)
|
|
380 |
{
|
|
381 |
return ret;
|
|
382 |
}
|
|
383 |
|
|
384 |
TLex converter(valStr);
|
|
385 |
ret = converter.Val(aValue);
|
|
386 |
|
|
387 |
return ret;
|
|
388 |
}
|
|
389 |
|
|
390 |
// End of File
|