|
1 // Copyright (c) 1999-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 #include "smtptestparsers.h" |
|
17 #include "smtptests.h" |
|
18 |
|
19 _LIT(KCommandSmtpClientTest, "smtp_client_test"); |
|
20 |
|
21 |
|
22 // SMTP commands |
|
23 _LIT(KCommandSmtpService, "smtp_service"); |
|
24 |
|
25 // SMTP settings strings |
|
26 _LIT(KCommandEmailSetServer, "set_server"); |
|
27 _LIT(KCommandEmailSetAlias, "set_alias"); |
|
28 _LIT(KCommandEmailSetAddress, "set_email_address"); |
|
29 _LIT(KCommandEmailSetReplyAddress, "set_reply_address"); |
|
30 _LIT(KCommandEmailSetReceiptAddress, "set_receipt_address"); |
|
31 _LIT(KCommandSmtpSetTLS, "set_tls"); // 1 parameter, sets the secure connection for SMTP service |
|
32 |
|
33 _LIT(KCommandSmtp3SetWrappedTLS, "set_wrapped_tls"); // 1 parameter, sets the secure connection for SMTP service. value should be 1 or 0 |
|
34 _LIT(KCommandSmtpSetPort, "set_port"); // 1 parameter, sets the port no for SMTP service. |
|
35 |
|
36 |
|
37 _LIT(KCommandSmtpCheckStatus, "check_smtp_error"); |
|
38 |
|
39 |
|
40 _LIT(KCommandSmtpCopyAndMonitor, "copy_and_monitor"); // 0 parameters, copies and monitors SMTP service |
|
41 |
|
42 // Smtp Operations |
|
43 _LIT(KCommandSmtpUseService, "use_service"); // 0 parameters, uses the currently selected service |
|
44 |
|
45 |
|
46 // |
|
47 // |
|
48 // CNewSmtpTestCommandParser |
|
49 // |
|
50 |
|
51 // A command parser |
|
52 // Parses the command which generates a new SMTP test harness |
|
53 // This command would usually be found in an email test section |
|
54 |
|
55 CNewSmtpTestCommandParser* CNewSmtpTestCommandParser::NewL(CTestScript& aScript, CEmailClientTest& aEmailClientTest) |
|
56 { |
|
57 CNewSmtpTestCommandParser* self = new (ELeave) CNewSmtpTestCommandParser(aScript, aEmailClientTest); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 }; |
|
63 |
|
64 void CNewSmtpTestCommandParser::ProcessL() |
|
65 { |
|
66 // Create an smtp test, give it the test utilities |
|
67 CSmtpClientTest* smtpTest = CSmtpClientTest::NewL(iEmailClientTest.EmailTestUtils(), iEmailClientTest.TestConsole()); |
|
68 CleanupStack::PushL(smtpTest); |
|
69 |
|
70 // Attach the email test to the main test |
|
71 iEmailClientTest.AddStateL(smtpTest, iDebugInfo); |
|
72 CleanupStack::Pop(smtpTest); // emailTest is now owned by the iMainTest |
|
73 |
|
74 // Check that there is one argument, the email test section name |
|
75 CheckNumberOfArgumentsL(1); |
|
76 // Create an email section parser |
|
77 CSmtpClientSectionParser* sectionParser = CSmtpClientSectionParser::NewL(*smtpTest, iScript, (*iArgumentList)[0]); |
|
78 CleanupStack::PushL(sectionParser); |
|
79 sectionParser->ParseL(); |
|
80 CleanupStack::PopAndDestroy(sectionParser); |
|
81 } |
|
82 |
|
83 void CNewSmtpTestCommandParser::ConstructL() |
|
84 { |
|
85 CBaseCommandParser::ConstructL(); |
|
86 AddCommandL(KCommandSmtpClientTest); |
|
87 } |
|
88 |
|
89 CNewSmtpTestCommandParser::CNewSmtpTestCommandParser(CTestScript& aScript, CEmailClientTest& aEmailClientTest) : iEmailClientTest(aEmailClientTest), iScript(aScript) |
|
90 { |
|
91 } |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 // |
|
97 // |
|
98 // CSmtpClientSectionParser |
|
99 // |
|
100 |
|
101 // A section parser |
|
102 // Parses an SMTP test section |
|
103 |
|
104 CSmtpClientSectionParser* CSmtpClientSectionParser::NewL(CSmtpClientTest& aSmtpClientTest, CTestScript& aScript, const TDesC& aNewSectionName) |
|
105 { |
|
106 CSmtpClientSectionParser* self = new (ELeave) CSmtpClientSectionParser(aSmtpClientTest, aScript); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(aNewSectionName); |
|
109 CleanupStack::Pop(self); |
|
110 return self; |
|
111 } |
|
112 |
|
113 void CSmtpClientSectionParser::ConstructL(const TDesC& aNewSectionName) |
|
114 { |
|
115 CEmailClientSectionParser::ConstructL(aNewSectionName); |
|
116 AddCommandParserL(CSmtpServiceCommandParser::NewL(iScript, iSmtpTest)); |
|
117 AddCommandParserL(CSmtpCheckStatusParser::NewL(iSmtpTest)); |
|
118 AddCommandParserL(CSmtpOperationParser::NewL(iSmtpTest)); |
|
119 } |
|
120 |
|
121 CSmtpClientSectionParser::CSmtpClientSectionParser(CSmtpClientTest& aSmtpTest, CTestScript& aScript) : CEmailClientSectionParser(aSmtpTest, aScript), iSmtpTest(aSmtpTest) |
|
122 { |
|
123 } |
|
124 |
|
125 |
|
126 |
|
127 // |
|
128 // |
|
129 // CSmtpServiceCommandParser |
|
130 // |
|
131 |
|
132 void CSmtpServiceCommandParser::ProcessL() |
|
133 { |
|
134 CheckNumberOfArgumentsL(1); |
|
135 // Create the settings object which we will give to the settings section parser |
|
136 CSmtpServiceSectionParser* serviceParser = CSmtpServiceSectionParser::NewL(iScript, iSmtpClientTest, (*iArgumentList)[0]); |
|
137 CleanupStack::PushL(serviceParser); |
|
138 serviceParser->ParseL(); |
|
139 CleanupStack::PopAndDestroy(serviceParser); |
|
140 } |
|
141 |
|
142 CSmtpServiceCommandParser* CSmtpServiceCommandParser::NewL(CTestScript& aScript, CSmtpClientTest& aSmtpClientTest) |
|
143 { |
|
144 CSmtpServiceCommandParser* self = new (ELeave) CSmtpServiceCommandParser(aScript, aSmtpClientTest); |
|
145 CleanupStack::PushL(self); |
|
146 self->ConstructL(); |
|
147 CleanupStack::Pop(self); |
|
148 return self; |
|
149 } |
|
150 |
|
151 void CSmtpServiceCommandParser::ConstructL() |
|
152 { |
|
153 CBaseCommandParser::ConstructL(); |
|
154 AddCommandL(KCommandSmtpService); |
|
155 } |
|
156 |
|
157 CSmtpServiceCommandParser::CSmtpServiceCommandParser(CTestScript& aScript, CSmtpClientTest& aSmtpClientTest) : iSmtpClientTest(aSmtpClientTest), iScript(aScript) |
|
158 { |
|
159 } |
|
160 |
|
161 |
|
162 // |
|
163 // |
|
164 // CSmtpServiceSectionParser |
|
165 // |
|
166 |
|
167 // A section parser |
|
168 // Parses a SMTP section to create a SMTP service |
|
169 |
|
170 CSmtpServiceSectionParser* CSmtpServiceSectionParser::NewL(CTestScript& aScript, CEmailClientTest& aTestHarness, const TDesC& aSectionName) |
|
171 { |
|
172 CSmtpServiceSectionParser* self = new (ELeave) CSmtpServiceSectionParser(aScript, aTestHarness); |
|
173 CleanupStack::PushL(self); |
|
174 self->ConstructL(aSectionName); |
|
175 CleanupStack::Pop(self); |
|
176 return self; |
|
177 } |
|
178 |
|
179 void CSmtpServiceSectionParser::ConstructL(const TDesC& aSectionName) |
|
180 { |
|
181 CBaseSectionParser::ConstructL(aSectionName); |
|
182 |
|
183 // Add the state to generate the smtp service |
|
184 CCreateSmtpService* testState = CCreateSmtpService::NewL(iTestHarness); |
|
185 TTestDebugInfo debugInfo(iScript, iSection->SectionPosition(), 0); |
|
186 iTestHarness.AddStateL(testState, debugInfo); |
|
187 |
|
188 // The parsers will fill in the entry and service details before the state that creates the entry is run. |
|
189 AddCommandParserL(CSmtpServiceCommands::NewL(*testState)); |
|
190 |
|
191 CEmailServiceSectionParser::ConstructL(aSectionName, *testState); |
|
192 } |
|
193 |
|
194 CSmtpServiceSectionParser::CSmtpServiceSectionParser(CTestScript& aScript, CEmailClientTest& aTestHarness) : CEmailServiceSectionParser(aScript, aTestHarness) |
|
195 { |
|
196 } |
|
197 |
|
198 CSmtpServiceSectionParser::~CSmtpServiceSectionParser() |
|
199 { |
|
200 } |
|
201 |
|
202 |
|
203 |
|
204 // |
|
205 // |
|
206 // CSmtpServiceCommands |
|
207 // |
|
208 |
|
209 // A command parser |
|
210 // Parses the commands that generate the SMTP service |
|
211 |
|
212 CSmtpServiceCommands* CSmtpServiceCommands::NewL(CCreateSmtpService& aTestState) |
|
213 { |
|
214 CSmtpServiceCommands* self = new (ELeave) CSmtpServiceCommands(aTestState); |
|
215 CleanupStack::PushL(self); |
|
216 self->ConstructL(); |
|
217 CleanupStack::Pop(self); |
|
218 return self; |
|
219 } |
|
220 |
|
221 void CSmtpServiceCommands::ProcessL() |
|
222 { |
|
223 // eh xxxx, check args |
|
224 if ((*iCurrentCommand) == KCommandEmailSetServer) |
|
225 { |
|
226 iTestState.Settings().SetServerAddressL((*iArgumentList)[0]); |
|
227 } |
|
228 else if ((*iCurrentCommand) == KCommandEmailSetAlias) |
|
229 { |
|
230 iTestState.Settings().SetEmailAliasL((*iArgumentList)[0]); |
|
231 iTestState.SetDetailsStringL((*iArgumentList)[0]); |
|
232 } |
|
233 else if ((*iCurrentCommand) == KCommandEmailSetAddress) |
|
234 { |
|
235 iTestState.Settings().SetEmailAddressL((*iArgumentList)[0]); |
|
236 } |
|
237 else if ((*iCurrentCommand) == KCommandEmailSetReplyAddress) |
|
238 { |
|
239 iTestState.Settings().SetReplyToAddressL((*iArgumentList)[0]); |
|
240 } |
|
241 else if ((*iCurrentCommand) == KCommandEmailSetReceiptAddress) |
|
242 { |
|
243 iTestState.Settings().SetReceiptAddressL((*iArgumentList)[0]); |
|
244 } |
|
245 else if ((*iCurrentCommand) == KCommandSmtpSetTLS) |
|
246 { |
|
247 CheckNumberOfArgumentsL(1); |
|
248 TLex lex((*iArgumentList)[0]); |
|
249 TInt setTls=0; |
|
250 User::LeaveIfError(lex.Val(setTls)); |
|
251 iTestState.Settings().SetSecureSockets(setTls); |
|
252 } |
|
253 else if ((*iCurrentCommand) == KCommandSmtp3SetWrappedTLS) |
|
254 { |
|
255 CheckNumberOfArgumentsL(1); |
|
256 TLex lex((*iArgumentList)[0]); |
|
257 TInt setWrappedTls=0; |
|
258 User::LeaveIfError(lex.Val(setWrappedTls)); |
|
259 iTestState.Settings().SetSSLWrapper(setWrappedTls); |
|
260 } |
|
261 else if ((*iCurrentCommand) == KCommandSmtpSetPort) |
|
262 { |
|
263 |
|
264 CheckNumberOfArgumentsL(1); |
|
265 TLex lex((*iArgumentList)[0]); |
|
266 TInt setPort=0; |
|
267 User::LeaveIfError(lex.Val(setPort)); |
|
268 iTestState.Settings().SetPort(setPort); |
|
269 |
|
270 } |
|
271 } |
|
272 |
|
273 CSmtpServiceCommands::CSmtpServiceCommands(CCreateSmtpService& aTestState) : iTestState(aTestState) |
|
274 { |
|
275 } |
|
276 |
|
277 void CSmtpServiceCommands::ConstructL() |
|
278 { |
|
279 CBaseCommandParser::ConstructL(); |
|
280 AddCommandL(KCommandEmailSetServer); |
|
281 AddCommandL(KCommandEmailSetAlias); |
|
282 AddCommandL(KCommandEmailSetAddress); |
|
283 AddCommandL(KCommandEmailSetReplyAddress); |
|
284 AddCommandL(KCommandEmailSetReceiptAddress); |
|
285 AddCommandL(KCommandSmtpSetTLS); |
|
286 AddCommandL(KCommandSmtp3SetWrappedTLS); |
|
287 AddCommandL(KCommandSmtpSetPort); |
|
288 } |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 // |
|
295 // |
|
296 // CSmtpCheckStatusParser |
|
297 // |
|
298 |
|
299 |
|
300 CSmtpCheckStatusParser* CSmtpCheckStatusParser::NewL(CSmtpClientTest& aSmtpTestHarness) |
|
301 { |
|
302 CSmtpCheckStatusParser* self = new (ELeave) CSmtpCheckStatusParser(aSmtpTestHarness); |
|
303 CleanupStack::PushL(self); |
|
304 self->ConstructL(); |
|
305 CleanupStack::Pop(self); |
|
306 return self; |
|
307 } |
|
308 |
|
309 void CSmtpCheckStatusParser::ProcessL() |
|
310 { |
|
311 TLex lex((*iArgumentList)[0]); |
|
312 TInt expectedStatus; |
|
313 User::LeaveIfError(lex.Val(expectedStatus)); |
|
314 iTestHarness.AddStateL(new (ELeave) CCheckSmtpOperation(expectedStatus, iTestHarness), iDebugInfo); |
|
315 } |
|
316 |
|
317 CSmtpCheckStatusParser::CSmtpCheckStatusParser(CSmtpClientTest& aSmtpTestHarness) : iTestHarness(aSmtpTestHarness) |
|
318 { |
|
319 } |
|
320 |
|
321 void CSmtpCheckStatusParser::ConstructL() |
|
322 { |
|
323 CBaseCommandParser::ConstructL(); |
|
324 AddCommandL(KCommandSmtpCheckStatus); |
|
325 } |
|
326 |
|
327 |
|
328 // |
|
329 // |
|
330 // CSmtpOperationParser |
|
331 // |
|
332 |
|
333 CSmtpOperationParser* CSmtpOperationParser::NewL(CSmtpClientTest& aSmtpClientTest) |
|
334 { |
|
335 CSmtpOperationParser* self = new (ELeave) CSmtpOperationParser(aSmtpClientTest); |
|
336 CleanupStack::PushL(self); |
|
337 self->ConstructL(); |
|
338 CleanupStack::Pop(self); |
|
339 return self; |
|
340 } |
|
341 |
|
342 void CSmtpOperationParser::ProcessL() |
|
343 { |
|
344 if ((*iCurrentCommand) == KCommandSmtpUseService) |
|
345 { |
|
346 CheckNumberOfArgumentsL(0); |
|
347 iSmtpClientTest.AddStateL(new (ELeave) CSmtpUseService(iSmtpClientTest), iDebugInfo); |
|
348 } |
|
349 else if ((*iCurrentCommand) == KCommandSmtpCopyAndMonitor) |
|
350 { |
|
351 CheckNumberOfArgumentsL(0); |
|
352 iSmtpClientTest.AddStateL(new (ELeave) CCopySelectionAndMonitor(iSmtpClientTest, EFalse), iDebugInfo); |
|
353 } |
|
354 else |
|
355 { |
|
356 User::Leave(KErrNotFound); |
|
357 } |
|
358 } |
|
359 |
|
360 void CSmtpOperationParser::ConstructL() |
|
361 { |
|
362 CBaseCommandParser::ConstructL(); |
|
363 AddCommandL(KCommandSmtpUseService); |
|
364 AddCommandL(KCommandSmtpCopyAndMonitor); |
|
365 } |
|
366 |
|
367 CSmtpOperationParser::CSmtpOperationParser(CSmtpClientTest& aSmtpClientTest) : iSmtpClientTest(aSmtpClientTest) |
|
368 { |
|
369 } |
|
370 |