|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 */ |
|
19 |
|
20 #include "CMtfTestActionManager.h" |
|
21 #include "CMtfTestActionParameters.h" |
|
22 #include "CMtfTestServer.h" |
|
23 #include "CMtfTestAction.h" |
|
24 #include "CMtfTestActionWait.h" |
|
25 |
|
26 _LIT(KActionParam,"actionParam"); |
|
27 _LIT(KInvalidActionParameters,"Invalid Action Parameters"); |
|
28 |
|
29 // ISSUE: Add NewLC function. |
|
30 |
|
31 CMtfTestActionManager* CMtfTestActionManager::NewL(CMtfTestServer& aTestServer, |
|
32 const TDesC& aActionName) |
|
33 { |
|
34 CMtfTestActionManager* self=new(ELeave) CMtfTestActionManager(aTestServer); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(aActionName); |
|
37 CleanupStack::Pop(); |
|
38 return self; |
|
39 } |
|
40 |
|
41 void CMtfTestActionManager::ConstructL(const TDesC& aActionName) |
|
42 { |
|
43 iActionName = aActionName.AllocL(); |
|
44 } |
|
45 |
|
46 CMtfTestActionManager* CMtfTestActionManager::NewL(CMtfTestServer& aTestServer) |
|
47 { |
|
48 CMtfTestActionManager* self=new(ELeave) CMtfTestActionManager(aTestServer); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CMtfTestActionManager::CMtfTestActionManager(CMtfTestServer& aTestServer) |
|
53 : iTestServer(aTestServer) |
|
54 { |
|
55 } |
|
56 |
|
57 CMtfTestActionManager::~CMtfTestActionManager() |
|
58 { |
|
59 delete iActionName; |
|
60 } |
|
61 |
|
62 TVerdict CMtfTestActionManager::doTestStepPreambleL() |
|
63 { |
|
64 return TestStepResult(); |
|
65 } |
|
66 |
|
67 /** Reads the .ini file and attempts to obtain parameters for the test action that |
|
68 this instance is managing. This functionality should become superfluous once TestExecute scripts |
|
69 are changed to allow parameters directly in the script itself. */ |
|
70 TVerdict CMtfTestActionManager::doTestStepL() |
|
71 { |
|
72 if (iActionName == NULL) |
|
73 { |
|
74 // no test action to manage |
|
75 return TestStepResult(); |
|
76 } |
|
77 |
|
78 // Obtain parameters for the action and save them. |
|
79 |
|
80 TPtrC parameter; |
|
81 HBufC* actionId = NULL; |
|
82 CMtfTestActionParameters* actionParams = CMtfTestActionParameters::NewL(); |
|
83 CleanupStack::PushL(actionParams); |
|
84 |
|
85 // if this check is false then we assume no parameters |
|
86 if (GetStringFromConfig(ConfigSection(),KActionParam,parameter)) |
|
87 { |
|
88 TLex parser(parameter); |
|
89 |
|
90 parser.SkipSpace(); |
|
91 |
|
92 // if this check is false then we assume no parameters |
|
93 if (!parser.Eos()) |
|
94 { |
|
95 // there are parameters present |
|
96 // parameters are separated by white space |
|
97 // there is an optional action id parameter, in which case all other parameters |
|
98 // must be enclosed in [], e.g., [ p1 p2 ... pn] action_id |
|
99 |
|
100 TBool actionIdPresent = EFalse; // "first [ encountered" flag |
|
101 TBool paramBlockClosed = EFalse; // "second ] encountered" flag |
|
102 |
|
103 if (parser.Peek() == '[') |
|
104 { |
|
105 parser.Get(); |
|
106 actionIdPresent = ETrue; |
|
107 parser.SkipSpace(); |
|
108 |
|
109 // if we are at the end of the string then the parameters are just |
|
110 // consisting of a single [ |
|
111 |
|
112 if (parser.Eos()) |
|
113 { |
|
114 User::Leave(KErrGeneral); |
|
115 } |
|
116 } |
|
117 |
|
118 // the loop will be entered |
|
119 |
|
120 while(!parser.Eos()) |
|
121 { |
|
122 if (actionIdPresent && (parser.Peek() == ']')) |
|
123 { |
|
124 parser.Get(); |
|
125 paramBlockClosed = ETrue; |
|
126 parser.SkipSpace(); |
|
127 |
|
128 if (parser.Eos()) |
|
129 { |
|
130 // no action id, [....] |
|
131 // this is accepted |
|
132 break; |
|
133 } |
|
134 |
|
135 //actionId exists |
|
136 actionId = parser.NextToken().AllocLC(); |
|
137 |
|
138 parser.SkipSpace(); |
|
139 |
|
140 // check there is nothing after the action id |
|
141 __ASSERT_ALWAYS(parser.Eos(),User::Panic(KInvalidActionParameters,0)); |
|
142 |
|
143 // we are at the end of the parameters, since the previous line |
|
144 // was passed, the loop will be exited at the next iteration |
|
145 } |
|
146 |
|
147 actionParams->AddParameterL(parser.NextToken()); |
|
148 parser.SkipSpace(); |
|
149 } |
|
150 |
|
151 if (actionIdPresent && !paramBlockClosed) |
|
152 { |
|
153 // [....] id was not closed with ] |
|
154 User::Leave(KErrGeneral); |
|
155 } |
|
156 } |
|
157 } |
|
158 |
|
159 if (actionId) |
|
160 { |
|
161 // actionId is on the cleanup stack last |
|
162 // CreateTestActionL takes ownership of actionParams at the END of the function |
|
163 iTestServer.CreateTestActionL(*iActionName,actionParams,*actionId); |
|
164 // test server has taken ownership of actionParams, we must not leave before |
|
165 // popping them off, but first we have to pop off actionId |
|
166 CleanupStack::PopAndDestroy(actionId); |
|
167 } |
|
168 else |
|
169 { |
|
170 iTestServer.CreateTestActionL(*iActionName,actionParams); |
|
171 } |
|
172 |
|
173 CleanupStack::Pop(actionParams); |
|
174 return TestStepResult(); |
|
175 } |
|
176 |
|
177 TVerdict CMtfTestActionManager::doTestStepPostambleL() |
|
178 { |
|
179 return TestStepResult(); |
|
180 } |