|
1 // Copyright (c) 2006-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 ESockDebug.TestSteps.cpp |
|
18 */ |
|
19 |
|
20 #include <comms-infras/esockdebugmessages.h> |
|
21 |
|
22 #include "SocketServer.TestSteps.h" |
|
23 #include "ESockDebug.TestSteps.h" |
|
24 |
|
25 #include <xml/parser.h> |
|
26 #include <xml/xmlparsererrors.h> |
|
27 #include "XmlParsing.h" |
|
28 #include <elements/sd_mintercept.h> |
|
29 |
|
30 #include <utf.h> |
|
31 |
|
32 |
|
33 #ifdef _DEBUG |
|
34 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
35 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
36 _LIT(KSpecAssert_ESockTestESckDbg, "ESockTestESckDbg"); |
|
37 #endif |
|
38 |
|
39 using namespace Xml; |
|
40 |
|
41 // ESOCK Message Intercept Register |
|
42 //================================= |
|
43 |
|
44 // Build message intercept pattern |
|
45 //-------------------------------- |
|
46 CAppendMessageInterceptPattern::CAppendMessageInterceptPattern(CCEsockTestBase*& aEsockTest) |
|
47 : CTe_EsockStepBase(aEsockTest) |
|
48 { |
|
49 SetTestStepName(KAppendMessageInterceptPattern); |
|
50 } |
|
51 |
|
52 TInt CAppendMessageInterceptPattern::ConfigureFromIni() |
|
53 { |
|
54 // Read in name of socket server used for controlling esock debug |
|
55 if((GetStringFromConfig(iSection, KTe_SocketServName, iSocketSvrName) != 1) |
|
56 || (iSocketSvrName.Length() == 0)) |
|
57 { |
|
58 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
59 return KErrNotFound; |
|
60 } |
|
61 |
|
62 // We need to have at least one expression |
|
63 TInt success; |
|
64 TBool done(EFalse); |
|
65 |
|
66 // The expressions are indexed from 1 in our config files |
|
67 TInt expressionCount = 1; |
|
68 |
|
69 // Fetch the action first |
|
70 TAction action; |
|
71 TRAPD(error, ReadActionL(action)); |
|
72 if(error != KErrNone) |
|
73 { |
|
74 INFO_PRINTF1(_L("Couldn't find action field in config file")); |
|
75 return KErrNotFound; |
|
76 } |
|
77 else |
|
78 { |
|
79 RExpressionList expressionList; |
|
80 CleanupClosePushL(expressionList); |
|
81 |
|
82 // We have an action so start looking for expressions to go with it |
|
83 // One at a time read in whole expressions till no more to be found |
|
84 while(!done) |
|
85 { |
|
86 TEventExpression eventExpression; |
|
87 |
|
88 // Read in the expression |
|
89 TRAPD(error, ReadEventExpressionL(expressionCount, eventExpression)); |
|
90 |
|
91 if(error == KErrNone) |
|
92 { |
|
93 // Found an expression so lets add it to an expression list for this pattern |
|
94 expressionList.Append(eventExpression); |
|
95 } |
|
96 else if(error == KErrNotFound) |
|
97 { |
|
98 // Must be the end of list of expressions |
|
99 done = ETrue; |
|
100 } |
|
101 else |
|
102 { |
|
103 // Some kind of xml parsing issue lets get out of here |
|
104 CleanupStack::PopAndDestroy(&expressionList); |
|
105 return error; |
|
106 } |
|
107 |
|
108 expressionCount++; |
|
109 } |
|
110 |
|
111 if(expressionList.Count() > 0) |
|
112 { |
|
113 iPattern = CPattern::NewL(expressionList, action); |
|
114 CleanupStack::Pop(&expressionList); |
|
115 success = KErrNone; |
|
116 } |
|
117 else |
|
118 { |
|
119 CleanupStack::PopAndDestroy(&expressionList); |
|
120 success = KErrArgument; |
|
121 } |
|
122 |
|
123 } |
|
124 |
|
125 return success; |
|
126 } |
|
127 |
|
128 const TInt KConfigSubSectionNameMaxLength = 64; |
|
129 const TInt KIniDataMaxLength = 256; |
|
130 |
|
131 void CAppendMessageInterceptPattern::ReadEventExpressionL(TInt aIndex, TEventExpression& aExpression) |
|
132 { |
|
133 // Fetch the whole ini data subsection that we will parse |
|
134 _LIT(KEventSubSectionFormat, "Event%d"); |
|
135 TBuf<KConfigSubSectionNameMaxLength> subSectionName; |
|
136 subSectionName.Format(KEventSubSectionFormat, aIndex); |
|
137 |
|
138 TPtrC iniData; |
|
139 if(!GetStringFromConfig(iSection, subSectionName, iniData)) |
|
140 { |
|
141 // We must have already found the last event expression |
|
142 User::Leave(KErrNotFound); |
|
143 } |
|
144 |
|
145 // Damn we need to convert the whole ini section back to UTF8 |
|
146 TBuf8<KIniDataMaxLength> iniData8; |
|
147 CnvUtfConverter::ConvertFromUnicodeToUtf8(iniData8, iniData); |
|
148 |
|
149 // Add some tags around the outside. XML parser needs them and leaving them out of the ini keeps things simple |
|
150 _LIT8(KSurroundingEventTagsFormat, "<Event>%S</Event>"); |
|
151 TBuf8<KIniDataMaxLength> iniData8tagged; |
|
152 iniData8tagged.Format(KSurroundingEventTagsFormat, &iniData8); |
|
153 |
|
154 // Its some xml so lets just parse the lot |
|
155 CEventExpressionXmlHandler handler(aExpression); |
|
156 CParser* parser = CParser::NewLC(KXmlMimeType, handler); |
|
157 TRAPD(error, Xml::ParseL(*parser, iniData8tagged)); |
|
158 if(error != KErrNone) |
|
159 { |
|
160 INFO_PRINTF2(_L("Error during XML parsing of (%S)."), &subSectionName); |
|
161 User::Leave(KErrArgument); |
|
162 } |
|
163 |
|
164 // Cleanup |
|
165 CleanupStack::PopAndDestroy(parser); |
|
166 } |
|
167 |
|
168 void CAppendMessageInterceptPattern::ReadActionL(TAction& aAction) |
|
169 { |
|
170 // Fetch the whole ini data subsection that we will parse |
|
171 TPtrC iniData; |
|
172 _LIT(KAction, "Action"); |
|
173 if(!GetStringFromConfig(iSection, KAction, iniData)) |
|
174 { |
|
175 User::Leave(KErrNotFound); |
|
176 } |
|
177 |
|
178 // Damn we need to convert the whole ini section back to UTF8 |
|
179 TBuf8<KIniDataMaxLength> iniData8; |
|
180 CnvUtfConverter::ConvertFromUnicodeToUtf8(iniData8, iniData); |
|
181 |
|
182 // Its some xml so lets just parse the lot |
|
183 CActionXmlHandler handler(aAction); |
|
184 CParser* parser = CParser::NewLC(KXmlMimeType, handler); |
|
185 TRAPD(error, Xml::ParseL(*parser, iniData8)); |
|
186 if(error != KErrNone) |
|
187 { |
|
188 INFO_PRINTF2(_L("Error during XML parsing of (%S)."), KAction); |
|
189 User::Leave(KErrNotFound); |
|
190 } |
|
191 |
|
192 // Cleanup |
|
193 CleanupStack::PopAndDestroy(parser); |
|
194 } |
|
195 |
|
196 TVerdict CAppendMessageInterceptPattern::doSingleTestStep() |
|
197 { |
|
198 SetTestStepResult(EFail); |
|
199 |
|
200 // Look up the socket server being used for esock debug control |
|
201 RSocketServ* debugSocketServer = iEsockTest->iSockServs.Find(iSocketSvrName); |
|
202 |
|
203 if(debugSocketServer) |
|
204 { |
|
205 // Make the call to reset the ESock debug register with the socket server given |
|
206 TRAPD(error, AppendPatternToRegisterL(*debugSocketServer)); |
|
207 if(error == KErrNone) |
|
208 { |
|
209 SetTestStepResult(EPass); |
|
210 } |
|
211 else |
|
212 { |
|
213 // If it errored then this step failed |
|
214 INFO_PRINTF2(_L("Could not enable the ESock message intercept register. Error (%S)."), error); |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 INFO_PRINTF1(_L("Could not find socket server for debug control of esock. Error (%S).")); |
|
220 } |
|
221 |
|
222 return TestStepResult(); |
|
223 } |
|
224 |
|
225 CAppendMessageInterceptPattern::~CAppendMessageInterceptPattern() |
|
226 { |
|
227 delete iPattern; |
|
228 } |
|
229 |
|
230 void CAppendMessageInterceptPattern::AppendPatternToRegisterL(RSocketServ& /*aSocketSvr*/) const |
|
231 { |
|
232 __ASSERT_DEBUG(iPattern, User::Panic(KSpecAssert_ESockTestESckDbg, 1)); |
|
233 TUint numExpressions = iPattern->Expressions().Count(); |
|
234 __ASSERT_DEBUG(numExpressions > 0, User::Panic(KSpecAssert_ESockTestESckDbg, 2)); |
|
235 |
|
236 //TODO MessageIntercept not operational |
|
237 #if 0 |
|
238 // Pull apart the pattern built and send it across to the message intercept register |
|
239 TUint index; |
|
240 TInt error; |
|
241 for(index = 0; index < numExpressions; index++) |
|
242 { |
|
243 TEventExpression expression = iPattern->Expressions()[index]; |
|
244 |
|
245 // Build the debug control message for current expression and send it to esock |
|
246 TAppendExpressionMsg msg1(expression); |
|
247 error = aSocketSvr.__DbgControl(msg1); |
|
248 if(error != KErrNone) |
|
249 { |
|
250 User::Leave(KErrGeneral); |
|
251 } |
|
252 } |
|
253 |
|
254 // And finally terminate the pattern with the action |
|
255 TAppendActionMsg msg2(iPattern->Action()); |
|
256 error = aSocketSvr.__DbgControl(msg2); |
|
257 if(error != KErrNone) |
|
258 { |
|
259 User::Leave(KErrGeneral); |
|
260 } |
|
261 #endif |
|
262 User::Leave(KErrGeneral); |
|
263 } |
|
264 |
|
265 |
|
266 |
|
267 // Enable message intercept register |
|
268 //---------------------------------- |
|
269 CEnableMessageInterceptRegister::CEnableMessageInterceptRegister(CCEsockTestBase*& aEsockTest) |
|
270 : CTe_EsockStepBase(aEsockTest), iSocketSvrName(KNullDesC) |
|
271 { |
|
272 SetTestStepName(KEnableMessageInterceptRegister); |
|
273 } |
|
274 |
|
275 TInt CEnableMessageInterceptRegister::ConfigureFromIni() |
|
276 { |
|
277 // Read in appropriate fields |
|
278 if((GetStringFromConfig(iSection, KTe_SocketServName, iSocketSvrName) != 1) |
|
279 || (iSocketSvrName.Length() == 0)) |
|
280 { |
|
281 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
282 return KErrNotFound; |
|
283 } |
|
284 |
|
285 // All ok if we got this far |
|
286 return KErrNone; |
|
287 } |
|
288 |
|
289 TVerdict CEnableMessageInterceptRegister::doSingleTestStep() |
|
290 { |
|
291 SetTestStepResult(EFail); |
|
292 |
|
293 // Look up the socket server being used for esock debug control |
|
294 RSocketServ* debugSocketServer = iEsockTest->iSockServs.Find(iSocketSvrName); |
|
295 |
|
296 //TODO MessageIntercept not operational |
|
297 #if 0 |
|
298 if(debugSocketServer) |
|
299 { |
|
300 // Build a debug control message and send it to esock |
|
301 MessageIntercept::TEnableMsg msg; |
|
302 TInt error = debugSocketServer->__DbgControl(msg); |
|
303 |
|
304 if (error != KErrNone) |
|
305 { |
|
306 // If it errored then this step failed |
|
307 INFO_PRINTF2(_L("Could not enable the ESock message intercept register. Error (%S)."), error); |
|
308 } |
|
309 else |
|
310 { |
|
311 SetTestStepResult(EPass); |
|
312 } |
|
313 } |
|
314 else |
|
315 { |
|
316 INFO_PRINTF1(_L("Could not find socket server for debug control of esock. Error (%S).")); |
|
317 } |
|
318 #endif |
|
319 return TestStepResult(); |
|
320 } |
|
321 |
|
322 |
|
323 // Disable message intercept |
|
324 //-------------------------- |
|
325 CDisableMessageInterceptRegister::CDisableMessageInterceptRegister(CCEsockTestBase*& aEsockTest) |
|
326 : CTe_EsockStepBase(aEsockTest), iSocketSvrName(KNullDesC) |
|
327 { |
|
328 SetTestStepName(KDisableMessageInterceptRegister); |
|
329 } |
|
330 |
|
331 TInt CDisableMessageInterceptRegister::ConfigureFromIni() |
|
332 { |
|
333 // Read in appropriate fields |
|
334 if((GetStringFromConfig(iSection, KTe_SocketServName, iSocketSvrName) != 1) |
|
335 || (iSocketSvrName.Length() == 0)) |
|
336 { |
|
337 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
338 return KErrNotFound; |
|
339 } |
|
340 |
|
341 // All ok if we got this far |
|
342 return KErrNone; |
|
343 } |
|
344 |
|
345 TVerdict CDisableMessageInterceptRegister::doSingleTestStep() |
|
346 { |
|
347 SetTestStepResult(EFail); |
|
348 |
|
349 // Look up the socket server being used for esock debug control |
|
350 RSocketServ* debugSocketServer = iEsockTest->iSockServs.Find(iSocketSvrName); |
|
351 |
|
352 if(debugSocketServer) |
|
353 { |
|
354 // Build a debug control message and send it to esock |
|
355 //TODO MessageIntercept not operational |
|
356 #if 0 |
|
357 MessageIntercept::TDisableMsg msg; |
|
358 TInt error = debugSocketServer->__DbgControl(msg); |
|
359 |
|
360 if (error != KErrNone) |
|
361 { |
|
362 // If it errored then this step failed |
|
363 INFO_PRINTF2(_L("Could not disable the ESock message intercept register. Error (%S)."), error); |
|
364 } |
|
365 else |
|
366 { |
|
367 SetTestStepResult(EPass); |
|
368 } |
|
369 #endif |
|
370 } |
|
371 else |
|
372 { |
|
373 INFO_PRINTF1(_L("Could not find socket server for debug control of esock. Error (%S).")); |
|
374 } |
|
375 |
|
376 // All ok if we got this far |
|
377 return TestStepResult(); |
|
378 } |
|
379 |
|
380 |
|
381 // Reset message intercept register |
|
382 //--------------------------------- |
|
383 |
|
384 CResetMessageInterceptRegister::CResetMessageInterceptRegister(CCEsockTestBase*& aEsockTest) |
|
385 : CTe_EsockStepBase(aEsockTest), iSocketSvrName(KNullDesC) |
|
386 { |
|
387 SetTestStepName(KResetMessageInterceptRegister); |
|
388 } |
|
389 |
|
390 TInt CResetMessageInterceptRegister::ConfigureFromIni() |
|
391 { |
|
392 // Read in appropriate fields |
|
393 if((GetStringFromConfig(iSection, KTe_SocketServName, iSocketSvrName) != 1) |
|
394 || (iSocketSvrName.Length() == 0)) |
|
395 { |
|
396 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
397 return KErrNotFound; |
|
398 } |
|
399 |
|
400 // All ok if we got this far |
|
401 return KErrNone; |
|
402 } |
|
403 |
|
404 TVerdict CResetMessageInterceptRegister::doSingleTestStep() |
|
405 { |
|
406 // Default to failing |
|
407 SetTestStepResult(EFail); |
|
408 //TODO MessageIntercept not operational |
|
409 #if 0 |
|
410 // Look up the socket server being used for esock debug control |
|
411 RSocketServ* debugSocketServer = iEsockTest->iSockServs.Find(iSocketSvrName); |
|
412 |
|
413 if(debugSocketServer) |
|
414 { |
|
415 // Build a debug control message and send it to esock |
|
416 MessageIntercept::TSoftResetMsg msg; |
|
417 TInt error = debugSocketServer->__DbgControl(msg); |
|
418 |
|
419 if (error != KErrNone) |
|
420 { |
|
421 // If it errored then this step failed |
|
422 INFO_PRINTF2(_L("Could not reset the ESock message intercept register. Error (%S)."), error); |
|
423 SetTestStepError(error); |
|
424 } |
|
425 else |
|
426 // Everything ok so we passed |
|
427 { |
|
428 SetTestStepResult(EPass); |
|
429 } |
|
430 } |
|
431 else |
|
432 { |
|
433 INFO_PRINTF1(_L("Could not find socket server for debug control of esock. Error (%S).")); |
|
434 } |
|
435 #endif |
|
436 return TestStepResult(); |
|
437 } |
|
438 |
|
439 |
|
440 // Query completion of message interception |
|
441 //----------------------------------------- |
|
442 |
|
443 CQueryMsgInterceptComplete::CQueryMsgInterceptComplete(CCEsockTestBase*& aEsockTest) |
|
444 : CTe_EsockStepBase(aEsockTest), iSocketSvrName(KNullDesC) |
|
445 { |
|
446 SetTestStepName(KQueryMsgInterceptComplete); |
|
447 } |
|
448 |
|
449 TInt CQueryMsgInterceptComplete::ConfigureFromIni() |
|
450 { |
|
451 // Read in appropriate fields |
|
452 if((GetStringFromConfig(iSection, KTe_SocketServName, iSocketSvrName) != 1) |
|
453 || (iSocketSvrName.Length() == 0)) |
|
454 { |
|
455 INFO_PRINTF1(_L("Couldn't find appropriate field in config file")); |
|
456 return KErrNotFound; |
|
457 } |
|
458 |
|
459 // All ok if we got this far |
|
460 return KErrNone; |
|
461 } |
|
462 |
|
463 TVerdict CQueryMsgInterceptComplete::doSingleTestStep() |
|
464 { |
|
465 // Default to failing |
|
466 SetTestStepResult(EFail); |
|
467 |
|
468 // Look up the socket server being used for esock debug control |
|
469 RSocketServ* debugSocketServer = iEsockTest->iSockServs.Find(iSocketSvrName); |
|
470 |
|
471 //TODO MessageIntercept not operational |
|
472 #if 0 |
|
473 if(debugSocketServer) |
|
474 { |
|
475 // Build a debug control message and send it to esock |
|
476 MessageIntercept::TQueryCompleteMsg msg; |
|
477 TInt result = debugSocketServer->__DbgControl(msg); |
|
478 |
|
479 if (result < 0) |
|
480 { |
|
481 // If it errored then this step failed |
|
482 INFO_PRINTF2(_L("Could not reset the ESock message intercept register. Error (%S)."), result); |
|
483 SetTestStepError(result); |
|
484 } |
|
485 else if (result == MessageIntercept::EPassedState) |
|
486 // Everything ok so we passed |
|
487 { |
|
488 SetTestStepResult(EPass); |
|
489 } |
|
490 } |
|
491 else |
|
492 { |
|
493 INFO_PRINTF1(_L("Could not find socket server for debug control of esock. Error (%S).")); |
|
494 } |
|
495 #endif |
|
496 return TestStepResult(); |
|
497 } |
|
498 |