|
1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataSdpAttrValue.h" |
|
19 #include "T_BTUtil.h" |
|
20 |
|
21 /*@{*/ |
|
22 //Parameters |
|
23 _LIT(KExpected, "expected"); |
|
24 _LIT(KExpectedRes, "expectedVisitorResult"); |
|
25 _LIT(KExpectedLL, "expectedLL"); |
|
26 _LIT(KExpectedLH, "expectedLH"); |
|
27 _LIT(KExpectedHL, "expectedHL"); |
|
28 _LIT(KExpectedHH, "expectedHH"); |
|
29 |
|
30 //Commands |
|
31 _LIT(KCmdAcceptVisitorL, "AcceptVisitorL"); |
|
32 _LIT(KCmdBool, "Bool"); |
|
33 _LIT(KCmdDataSize, "DataSize"); |
|
34 _LIT(KCmdDes, "Des"); |
|
35 _LIT(KCmdDoesIntFit, "DoesIntFit"); |
|
36 _LIT(KCmdInt, "Int"); |
|
37 _LIT(KCmdType, "Type"); |
|
38 _LIT(KCmdUint, "Uint"); |
|
39 _LIT(KCmdUUID, "UUID"); |
|
40 _LIT(KCmdMSAVV_ExtensionInterfaceL, "MSAVV_ExtensionInterfaceL"); |
|
41 /*@}*/ |
|
42 |
|
43 const TInt KAttrValueStringBufLen = 256; |
|
44 const TInt KVisitorResLen = 512; |
|
45 const TInt KMaxDataSize = 4; |
|
46 |
|
47 ////////////////////////////////////////////////////////////////////// |
|
48 // Construction/Destruction |
|
49 ////////////////////////////////////////////////////////////////////// |
|
50 |
|
51 CT_DataSdpAttrValue::CT_DataSdpAttrValue() |
|
52 : iVisitorResult(new TUint16[KVisitorResLen],KVisitorResLen) |
|
53 { |
|
54 } |
|
55 |
|
56 /** |
|
57 * Process a command read from the ini file |
|
58 * |
|
59 * @param aCommand The command to process |
|
60 * @param aSection The section in the ini containing data for the command |
|
61 * @param aAsyncErrorIndex Command index for async calls to return errors to |
|
62 * |
|
63 * @return ETrue if the command is processed |
|
64 * |
|
65 * @leave System wide error |
|
66 */ |
|
67 TBool CT_DataSdpAttrValue::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
68 { |
|
69 TBool ret = ETrue; |
|
70 |
|
71 if ( aCommand==KCmdAcceptVisitorL ) |
|
72 { |
|
73 DoCmdAcceptVisitor(aSection); |
|
74 } |
|
75 else if ( aCommand==KCmdBool ) |
|
76 { |
|
77 DoCmdBool(aSection); |
|
78 } |
|
79 else if ( aCommand==KCmdDataSize ) |
|
80 { |
|
81 DoCmdDataSize(aSection); |
|
82 } |
|
83 else if ( aCommand==KCmdDes ) |
|
84 { |
|
85 DoCmdDes(aSection); |
|
86 } |
|
87 else if ( aCommand==KCmdDoesIntFit ) |
|
88 { |
|
89 DoCmdDoesIntFit(aSection); |
|
90 } |
|
91 else if ( aCommand==KCmdInt ) |
|
92 { |
|
93 DoCmdInt(aSection); |
|
94 } |
|
95 else if ( aCommand==KCmdType ) |
|
96 { |
|
97 DoCmdType(aSection); |
|
98 } |
|
99 else if ( aCommand==KCmdUint ) |
|
100 { |
|
101 DoCmdUint(aSection); |
|
102 } |
|
103 else if ( aCommand==KCmdUUID ) |
|
104 { |
|
105 DoCmdUUID(aSection); |
|
106 } |
|
107 else if ( aCommand==KCmdMSAVV_ExtensionInterfaceL ) |
|
108 { |
|
109 DoCmdMSAVV_ExtensionInterfaceL(); |
|
110 } |
|
111 else |
|
112 { |
|
113 ret=EFalse; |
|
114 } |
|
115 |
|
116 return ret; |
|
117 } |
|
118 |
|
119 void CT_DataSdpAttrValue::DoCmdAcceptVisitor(const TDesC& aSection) |
|
120 { |
|
121 TRAPD(err, GetSdpAttrValue()->AcceptVisitorL(*this)); |
|
122 if ( err!=KErrNone ) |
|
123 { |
|
124 ERR_PRINTF2(_L("CSdpAttrValue::AcceptVisitorL failed with error %d"), err); |
|
125 SetError(err); |
|
126 return; |
|
127 } |
|
128 |
|
129 TPtrC expected; |
|
130 if(GetStringFromConfig(aSection, KExpectedRes(), expected)) |
|
131 { |
|
132 TPtr actual = GetVisitorResult(); |
|
133 INFO_PRINTF1(_L("Check result. Actual value:")); |
|
134 INFO_PRINTF1(actual); |
|
135 if(actual != expected) |
|
136 { |
|
137 INFO_PRINTF1(_L("CSdpAttrValue::AcceptVisitorL, Result is not as expected !")); |
|
138 SetBlockResult(EFail); |
|
139 } |
|
140 else |
|
141 { |
|
142 INFO_PRINTF1(_L("CSdpAttrValue::AcceptVisitorL, Result is correct !")); |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedRes()); |
|
148 SetBlockResult(EFail); |
|
149 } |
|
150 } |
|
151 |
|
152 void CT_DataSdpAttrValue::DoCmdBool(const TDesC& aSection) |
|
153 { |
|
154 TBool actual = GetSdpAttrValue()->Bool(); |
|
155 INFO_PRINTF2(_L("CSdpAttrValue::Bool = %d"), actual); |
|
156 |
|
157 TBool expected; |
|
158 if ( GetBoolFromConfig(aSection, KExpected(), expected) ) |
|
159 { |
|
160 if ( actual!=expected ) |
|
161 { |
|
162 ERR_PRINTF1(_L("Bool is not as expected!")); |
|
163 SetBlockResult(EFail); |
|
164 } |
|
165 } |
|
166 else |
|
167 { |
|
168 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
169 SetBlockResult(EFail); |
|
170 } |
|
171 } |
|
172 |
|
173 void CT_DataSdpAttrValue::DoCmdDataSize(const TDesC& aSection) |
|
174 { |
|
175 TUint actual = GetSdpAttrValue()->DataSize(); |
|
176 INFO_PRINTF2(_L("CSdpAttrValue::Size = %d"), actual); |
|
177 |
|
178 TInt expected; |
|
179 if (GetIntFromConfig(aSection, KExpected(), expected)) |
|
180 { |
|
181 if(actual!=expected ) |
|
182 { |
|
183 ERR_PRINTF1(_L("DataSize is not as expected!")); |
|
184 SetBlockResult(EFail); |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
190 SetBlockResult(EFail); |
|
191 } |
|
192 } |
|
193 |
|
194 void CT_DataSdpAttrValue::DoCmdDes(const TDesC& aSection) |
|
195 { |
|
196 TPtrC8 actual=GetSdpAttrValue()->Des(); |
|
197 HBufC* buffer=HBufC::NewLC(actual.Length()); |
|
198 TPtr bufferPtr=buffer->Des(); |
|
199 bufferPtr.Copy(actual); |
|
200 INFO_PRINTF1(_L("CSdpAttrValue::Des result:")); |
|
201 INFO_PRINTF1(bufferPtr); |
|
202 |
|
203 TPtrC expected; |
|
204 if ( GetStringFromConfig(aSection, KExpected(), expected) ) |
|
205 { |
|
206 if ( bufferPtr!=expected ) |
|
207 { |
|
208 ERR_PRINTF1(_L("Des is not as expected!")); |
|
209 SetBlockResult(EFail); |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
215 SetBlockResult(EFail); |
|
216 } |
|
217 CleanupStack::PopAndDestroy(buffer); |
|
218 } |
|
219 |
|
220 void CT_DataSdpAttrValue::DoCmdDoesIntFit(const TDesC& aSection) |
|
221 { |
|
222 TBool actual=GetSdpAttrValue()->DoesIntFit(); |
|
223 |
|
224 TBool expected; |
|
225 if ( GetBoolFromConfig(aSection, KExpected(), expected) ) |
|
226 { |
|
227 if ( actual!=expected ) |
|
228 { |
|
229 ERR_PRINTF1(_L("DoesIntFit is not as expected!")); |
|
230 SetBlockResult(EFail); |
|
231 } |
|
232 } |
|
233 else |
|
234 { |
|
235 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
236 SetBlockResult(EFail); |
|
237 } |
|
238 } |
|
239 |
|
240 void CT_DataSdpAttrValue::DoCmdInt(const TDesC& aSection) |
|
241 { |
|
242 TInt actual = GetSdpAttrValue()->Int(); |
|
243 INFO_PRINTF2(_L("CSdpAttrValue::Int = %d"), actual); |
|
244 |
|
245 TInt expected; |
|
246 if ( GetIntFromConfig(aSection, KExpected(), expected) ) |
|
247 { |
|
248 if ( actual!=expected ) |
|
249 { |
|
250 ERR_PRINTF1(_L("Int is not as expected!")); |
|
251 SetBlockResult(EFail); |
|
252 } |
|
253 } |
|
254 else |
|
255 { |
|
256 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
257 SetBlockResult(EFail); |
|
258 } |
|
259 } |
|
260 |
|
261 void CT_DataSdpAttrValue::DoCmdType(const TDesC& aSection) |
|
262 { |
|
263 TSdpElementType actual=GetSdpAttrValue()->Type(); |
|
264 INFO_PRINTF2(_L("CSdpAttrValue::Type = %d"), actual); |
|
265 |
|
266 TSdpElementType expected; |
|
267 if ( CT_BTUtil::ReadSdpElementType(*this, expected, aSection, KExpected()) ) |
|
268 { |
|
269 if ( actual!=expected ) |
|
270 { |
|
271 ERR_PRINTF1(_L("Type is not as expected!")); |
|
272 SetBlockResult(EFail); |
|
273 } |
|
274 } |
|
275 else |
|
276 { |
|
277 ERR_PRINTF1(_L("Missing expected value Type")); |
|
278 SetBlockResult(EFail); |
|
279 } |
|
280 } |
|
281 |
|
282 void CT_DataSdpAttrValue::DoCmdUint(const TDesC& aSection) |
|
283 { |
|
284 TInt actual = static_cast<TInt>(GetSdpAttrValue()->Uint()); |
|
285 INFO_PRINTF2(_L("CSdpAttrValue::Uint = %d"), actual); |
|
286 |
|
287 TInt expected; |
|
288 if ( GetIntFromConfig(aSection, KExpected(), expected) ) |
|
289 { |
|
290 if ( actual!=expected ) |
|
291 { |
|
292 ERR_PRINTF1(_L("Uint is not as expected!")); |
|
293 SetBlockResult(EFail); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 ERR_PRINTF2(_L("Missing expected value %S"), &KExpected()); |
|
299 SetBlockResult(EFail); |
|
300 } |
|
301 } |
|
302 |
|
303 void CT_DataSdpAttrValue::DoCmdUUID(const TDesC& aSection) |
|
304 { |
|
305 TBool ifexpectedExit = EFalse; |
|
306 TBool ifexpectedHHExit = EFalse; |
|
307 TBool ifexpectedHLExit = EFalse; |
|
308 TBool ifexpectedLHExit = EFalse; |
|
309 TBool ifexpectedLLExit = EFalse; |
|
310 TInt expected = 0; |
|
311 TInt expectedHH = 0; |
|
312 TInt expectedHL = 0; |
|
313 TInt expectedLH = 0; |
|
314 TInt expectedLL = 0; |
|
315 TUUID actualUUid = NULL; |
|
316 TInt actualIntUUid = NULL; |
|
317 |
|
318 |
|
319 |
|
320 actualUUid = GetSdpAttrValue()->UUID(); |
|
321 actualIntUUid = CT_BTUtil::ConvertUUID32toInt(actualUUid); |
|
322 |
|
323 |
|
324 if ( GetIntFromConfig(aSection, KExpected(), expected) ) |
|
325 { |
|
326 INFO_PRINTF2(_L("CSdpAttrValue::UUID call actual result: %d"), actualIntUUid); |
|
327 ifexpectedExit=ETrue; |
|
328 } |
|
329 else //to get four input values for 128-bit TUUID object |
|
330 { |
|
331 if ( GetIntFromConfig(aSection, KExpectedHH(), expectedHH)) |
|
332 { |
|
333 ifexpectedHHExit=ETrue; |
|
334 } |
|
335 else |
|
336 { |
|
337 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedHH()); |
|
338 SetBlockResult(EFail); |
|
339 } |
|
340 |
|
341 if ( GetIntFromConfig(aSection, KExpectedHL(), expectedHL)) |
|
342 { |
|
343 ifexpectedHLExit=ETrue; |
|
344 } |
|
345 else |
|
346 { |
|
347 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedHL()); |
|
348 SetBlockResult(EFail); |
|
349 } |
|
350 |
|
351 if ( GetIntFromConfig(aSection, KExpectedLH(), expectedLH)) |
|
352 { |
|
353 ifexpectedLHExit=ETrue; |
|
354 } |
|
355 else |
|
356 { |
|
357 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedLH()); |
|
358 SetBlockResult(EFail); |
|
359 } |
|
360 |
|
361 if ( GetIntFromConfig(aSection, KExpectedLL(), expectedLL)) |
|
362 { |
|
363 ifexpectedLLExit=ETrue; |
|
364 } |
|
365 else |
|
366 { |
|
367 ERR_PRINTF2(_L("Missing expected value %S"), &KExpectedLL()); |
|
368 SetBlockResult(EFail); |
|
369 } |
|
370 } |
|
371 |
|
372 |
|
373 if (ifexpectedExit) |
|
374 { |
|
375 if ( actualIntUUid!=expected ) |
|
376 { |
|
377 ERR_PRINTF1(_L("UUID is not as expected!")); |
|
378 SetBlockResult(EFail); |
|
379 } |
|
380 } |
|
381 else if(ifexpectedHHExit && ifexpectedHLExit && ifexpectedLHExit && ifexpectedLLExit)//to compare four values with input |
|
382 { |
|
383 INFO_PRINTF2(_L("expected Highest order word (HH bits 96 - 127): %d"), expectedHH); |
|
384 INFO_PRINTF2(_L("expected Second highest order word (HL bits 64 - 95): %d"), expectedHL); |
|
385 INFO_PRINTF2(_L("expected Second lowest order word (LH bits 32 - 63): %d"), expectedLH); |
|
386 INFO_PRINTF2(_L("expected Low order word (LL bits 0 - 31): %d"), expectedLL); |
|
387 |
|
388 TUUID expectedUUID(expectedHH,expectedHL,expectedLH,expectedLL); |
|
389 |
|
390 if ( actualUUid!=expectedUUID ) |
|
391 { |
|
392 ERR_PRINTF1(_L("128 bits of UUID is not as expected!")); |
|
393 SetBlockResult(EFail); |
|
394 } |
|
395 } |
|
396 } |
|
397 |
|
398 void CT_DataSdpAttrValue::VisitAttributeValueL(CSdpAttrValue& aValue, TSdpElementType aType) |
|
399 { |
|
400 INFO_PRINTF1(_L("MSdpAttributeValueVisitor VisitAttributeValueL Call")); |
|
401 HBufC16* string16 = HBufC16::NewLC(KAttrValueStringBufLen); |
|
402 |
|
403 switch (aType) |
|
404 { |
|
405 case ETypeNil: |
|
406 INFO_PRINTF1(_L("TSdpElementType is ETypeNil")); |
|
407 iVisitorResult.Append(_L("&type=Nil")); |
|
408 break; |
|
409 case ETypeUint: |
|
410 if( aValue.DataSize() <= (static_cast<TUint>(KMaxDataSize)) ) |
|
411 { |
|
412 INFO_PRINTF2(_L("TSdpElementType is ETypeUint. Value = %d"), aValue.Uint()); |
|
413 iVisitorResult.Append(_L("&type=Uint&value=")); |
|
414 iVisitorResult.AppendNum(aValue.Uint()); |
|
415 } |
|
416 else |
|
417 { |
|
418 string16->Des().Copy(aValue.Des()); |
|
419 TPtrC16 tprStringUint = string16->Des(); |
|
420 INFO_PRINTF1(_L("TSdpElementType is ETypeUint. Value = ")); |
|
421 INFO_PRINTF1(tprStringUint); |
|
422 iVisitorResult.Append(_L("&type=Uint&value=")); |
|
423 iVisitorResult.Append(tprStringUint); |
|
424 } |
|
425 break; |
|
426 case ETypeInt: |
|
427 INFO_PRINTF2(_L("TSdpElementType is ETypeInt. Value = %d"), aValue.Int()); |
|
428 iVisitorResult.Append(_L("&type=Int&value=")); |
|
429 iVisitorResult.AppendNum(aValue.Int()); |
|
430 break; |
|
431 case ETypeUUID: |
|
432 { |
|
433 TUUID uUid = aValue.UUID(); |
|
434 TUint intUUid= CT_BTUtil::ConvertUUID32toInt(uUid); |
|
435 INFO_PRINTF2(_L("TSdpElementType is ETypeUUID: Value is %d"),intUUid); |
|
436 iVisitorResult.Append(_L("&type=UUID&value=")); |
|
437 iVisitorResult.AppendNum(intUUid); |
|
438 } |
|
439 break; |
|
440 case ETypeString: |
|
441 { |
|
442 string16->Des().Copy(aValue.Des()); |
|
443 TPtrC16 tprString = string16->Des(); |
|
444 INFO_PRINTF1(_L("TSdpElementType is ETypeString. Value = ")); |
|
445 INFO_PRINTF1(tprString); |
|
446 iVisitorResult.Append(_L("&type=String&value=")); |
|
447 iVisitorResult.Append(tprString); |
|
448 } |
|
449 break; |
|
450 case ETypeBoolean: |
|
451 INFO_PRINTF2(_L("TSdpElementType is ETypeBoolean. Value = %d"), aValue.Bool()); |
|
452 iVisitorResult.Append(_L("&type=Boolean&value=")); |
|
453 iVisitorResult.AppendNum(aValue.Bool()); |
|
454 break; |
|
455 case ETypeDES: |
|
456 INFO_PRINTF1(_L("TSdpElementType is ETypeDES")); |
|
457 iVisitorResult.Append(_L("&type=DES")); |
|
458 break; |
|
459 case ETypeDEA: |
|
460 INFO_PRINTF1(_L("TSdpElementType is ETypeDEA")); |
|
461 iVisitorResult.Append(_L("&type=DEA")); |
|
462 break; |
|
463 case ETypeURL: |
|
464 { |
|
465 string16->Des().Copy(aValue.Des()); |
|
466 TPtrC16 tprStringURL = string16->Des(); |
|
467 INFO_PRINTF1(_L("TSdpElementType is ETypeURL. Value = ")); |
|
468 INFO_PRINTF1(tprStringURL); |
|
469 iVisitorResult.Append(_L("&type=URL&value=")); |
|
470 iVisitorResult.Append(tprStringURL); |
|
471 } |
|
472 break; |
|
473 case ETypeEncoded: |
|
474 INFO_PRINTF1(_L("TSdpElementType is ETypeEncoded")); |
|
475 iVisitorResult.Append(_L("&type=Encoded")); |
|
476 break; |
|
477 default: |
|
478 INFO_PRINTF2(_L("TSdpElementType is Unknown %d"), aType); |
|
479 iVisitorResult.Append(_L("&type=Unknown")); |
|
480 break; |
|
481 } |
|
482 CleanupStack::PopAndDestroy(string16); |
|
483 } |
|
484 |
|
485 TPtr CT_DataSdpAttrValue::GetVisitorResult() |
|
486 { |
|
487 return iVisitorResult; |
|
488 } |
|
489 |
|
490 void CT_DataSdpAttrValue::ResetVisitorResult() |
|
491 { |
|
492 iVisitorResult.Zero(); |
|
493 } |
|
494 |
|
495 void CT_DataSdpAttrValue::StartListL(CSdpAttrValueList& /*aList*/) |
|
496 { |
|
497 } |
|
498 |
|
499 void CT_DataSdpAttrValue::EndListL() |
|
500 { |
|
501 } |
|
502 |
|
503 void CT_DataSdpAttrValue::DoCmdMSAVV_ExtensionInterfaceL() |
|
504 { |
|
505 INFO_PRINTF1(_L("MSdpAttributeValueVisitor MSAVV_ExtensionInterfaceL call")); |
|
506 void* tmpVoid; |
|
507 TRAPD(err, this->MSAVV_ExtensionInterfaceL(KNullUid, tmpVoid)); |
|
508 if(err != KErrNone) |
|
509 { |
|
510 ERR_PRINTF2(_L("MSdpAttributeValueVisitor MSAVV_ExtensionInterfaceL failed with error %d"), err); |
|
511 SetError(err); |
|
512 } |
|
513 } |