|
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_DataSdpUtil.h" |
|
19 #include <es_sock.h> |
|
20 |
|
21 /*@{*/ |
|
22 |
|
23 //Commands |
|
24 _LIT(KCmdPutUint, "PutUint"); |
|
25 _LIT(KCmdGetUint, "GetUint"); |
|
26 _LIT(KCmdPutUint64, "PutUint64"); |
|
27 _LIT(KCmdGetUint64, "GetUint64"); |
|
28 _LIT(KCmdPutUint128, "PutUint128"); |
|
29 _LIT(KCmdGetUint128, "GetUint128"); |
|
30 |
|
31 //Parameters |
|
32 _LIT(KInt, "integer"); |
|
33 _LIT(KNumberOfBytes, "numberOfBytes"); |
|
34 _LIT(KObject, "object"); |
|
35 _LIT(KNumber, "number"); |
|
36 _LIT(KLower, "low"); |
|
37 _LIT(KHigher, "high"); |
|
38 |
|
39 /*@}*/ |
|
40 |
|
41 ////////////////////////////////////////////////////////////////////// |
|
42 // Construction/Destruction |
|
43 ////////////////////////////////////////////////////////////////////// |
|
44 |
|
45 CT_DataSdpUtil* CT_DataSdpUtil::NewL() |
|
46 { |
|
47 CT_DataSdpUtil* ret=new (ELeave) CT_DataSdpUtil(); |
|
48 CleanupStack::PushL(ret); |
|
49 ret->ConstructL(); |
|
50 CleanupStack::Pop(ret); |
|
51 return ret; |
|
52 } |
|
53 |
|
54 CT_DataSdpUtil::CT_DataSdpUtil() |
|
55 { |
|
56 } |
|
57 |
|
58 void CT_DataSdpUtil::ConstructL() |
|
59 { |
|
60 } |
|
61 |
|
62 CT_DataSdpUtil::~CT_DataSdpUtil() |
|
63 { |
|
64 DestroyData(); |
|
65 } |
|
66 |
|
67 void CT_DataSdpUtil::SetObjectL(TAny* /*aAny*/) |
|
68 { |
|
69 } |
|
70 |
|
71 void CT_DataSdpUtil::DestroyData() |
|
72 { |
|
73 } |
|
74 |
|
75 /** |
|
76 * Process a command read from the ini file |
|
77 * |
|
78 * @param aCommand The command to process |
|
79 * @param aSection The section in the ini containing data for the command |
|
80 * @param aAsyncErrorIndex Command index for async calls to return errors to |
|
81 * |
|
82 * @return ETrue if the command is processed |
|
83 * |
|
84 * @leave System wide error |
|
85 */ |
|
86 TBool CT_DataSdpUtil::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
87 { |
|
88 TBool ret=ETrue; |
|
89 |
|
90 if ( aCommand==KCmdPutUint ) |
|
91 { |
|
92 DoCmdPutUint(aSection); |
|
93 } |
|
94 else if ( aCommand==KCmdGetUint ) |
|
95 { |
|
96 DoCmdGetUint(aSection); |
|
97 } |
|
98 else if ( aCommand==KCmdPutUint64 ) |
|
99 { |
|
100 DoCmdPutUint64(aSection); |
|
101 } |
|
102 else if ( aCommand==KCmdGetUint64 ) |
|
103 { |
|
104 DoCmdGetUint64(aSection); |
|
105 } |
|
106 else if ( aCommand==KCmdPutUint128 ) |
|
107 { |
|
108 DoCmdPutUint128(aSection); |
|
109 } |
|
110 else if ( aCommand==KCmdGetUint128 ) |
|
111 { |
|
112 DoCmdGetUint128(aSection); |
|
113 } |
|
114 else |
|
115 { |
|
116 ret=EFalse; |
|
117 } |
|
118 |
|
119 return ret; |
|
120 } |
|
121 |
|
122 |
|
123 /** |
|
124 Test PutUint() |
|
125 */ |
|
126 void CT_DataSdpUtil::DoCmdPutUint(const TDesC& aSection) |
|
127 { |
|
128 INFO_PRINTF1(_L("SdpUtil PutUint call")); |
|
129 TPckgBuf<TUint64> valuePackaged; |
|
130 TUint8* dataPtr=&valuePackaged[0]; |
|
131 |
|
132 TInt theValue = 0; |
|
133 if( GetIntFromConfig(aSection, KInt(), theValue) ) |
|
134 { |
|
135 TInt64 theInt = theValue; |
|
136 |
|
137 if( GetIntFromConfig(aSection, KNumberOfBytes(), theValue) ) |
|
138 { |
|
139 TInt numberOfBytes = theValue; |
|
140 SdpUtil::PutUint(dataPtr, theInt, numberOfBytes); |
|
141 |
|
142 TInt64 temp = 0; |
|
143 TInt64 expectedValue = 0; |
|
144 for(TInt i=numberOfBytes-1; i >=0; --i) |
|
145 { |
|
146 temp = dataPtr[i]<<(8*(numberOfBytes-i-1)); |
|
147 expectedValue = expectedValue + temp; |
|
148 } |
|
149 INFO_PRINTF2(_L("SdpUtil PutUint Call: actual = %d"), theInt); |
|
150 INFO_PRINTF2(_L("SdpUtil PutUint Call: expected = %d"), expectedValue); |
|
151 |
|
152 if( expectedValue != theInt ) |
|
153 { |
|
154 ERR_PRINTF1(_L("PutUint is not as expected!")); |
|
155 SetBlockResult(EFail); |
|
156 } |
|
157 } |
|
158 else |
|
159 { |
|
160 ERR_PRINTF2(_L("Missing parameter %S"), &KNumberOfBytes()); |
|
161 SetBlockResult(EFail); |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 ERR_PRINTF2(_L("Missing parameter %S"), &KNumberOfBytes()); |
|
167 SetBlockResult(EFail); |
|
168 } |
|
169 } |
|
170 |
|
171 /** |
|
172 Test GetUint() |
|
173 */ |
|
174 void CT_DataSdpUtil::DoCmdGetUint(const TDesC& aSection) |
|
175 { |
|
176 INFO_PRINTF1(_L("SdpUtil GetUint Call")); |
|
177 |
|
178 TPtrC theString; |
|
179 if ( GetStringFromConfig(aSection, KObject(), theString) ) |
|
180 { |
|
181 HBufC8* buffer8=HBufC8::NewLC(theString.Length()); |
|
182 buffer8->Des().Copy(theString); |
|
183 TPtr8 theString8=buffer8->Des(); |
|
184 |
|
185 TUint theTUint = SdpUtil::GetUint(theString8); |
|
186 INFO_PRINTF2(_L("SdpUtil GetUint Call: actual = %d"), theTUint); |
|
187 |
|
188 TUint expectedValue = 0; |
|
189 switch(theString.Length()) |
|
190 { |
|
191 case 0: |
|
192 expectedValue = 0; |
|
193 break; |
|
194 case 1: |
|
195 expectedValue = theString8[0]; |
|
196 break; |
|
197 case 2: |
|
198 expectedValue = BigEndian::Get16(theString8.Ptr()); |
|
199 break; |
|
200 case 4: |
|
201 expectedValue = BigEndian::Get32(theString8.Ptr()); |
|
202 break; |
|
203 default: |
|
204 expectedValue = 0; |
|
205 break; |
|
206 } |
|
207 INFO_PRINTF2(_L("SdpUtil GetUint Call: expected = %d"), expectedValue); |
|
208 |
|
209 if( theTUint!=expectedValue ) |
|
210 { |
|
211 ERR_PRINTF1(_L("GetUint is not as expected!")); |
|
212 SetBlockResult(EFail); |
|
213 } |
|
214 CleanupStack::PopAndDestroy(buffer8); |
|
215 } |
|
216 else |
|
217 { |
|
218 ERR_PRINTF2(_L("Missing parameter %S"), &KObject()); |
|
219 SetBlockResult(EFail); |
|
220 } |
|
221 } |
|
222 |
|
223 /** |
|
224 Test PutUint64() |
|
225 */ |
|
226 void CT_DataSdpUtil::DoCmdPutUint64(const TDesC& aSection) |
|
227 { |
|
228 INFO_PRINTF1(_L("SdpUtil PutUint64 call")); |
|
229 |
|
230 TInt theValue = 0; |
|
231 TPckgBuf<TUint64> valuePackaged; |
|
232 TUint8* dataPtr=&valuePackaged[0]; |
|
233 |
|
234 if( GetIntFromConfig(aSection, KNumber(), theValue) ) |
|
235 { |
|
236 TUint64 theNumber = theValue; |
|
237 SdpUtil::PutUint64(dataPtr, theNumber); |
|
238 |
|
239 TUint64 temp = 0; |
|
240 TUint64 expectedValue = 0; |
|
241 for(TInt i=sizeof(TUint64)-1; i>=0; i--) |
|
242 { |
|
243 temp = dataPtr[i]<<(8*(sizeof(TUint64)-i-1)); |
|
244 expectedValue = expectedValue + temp; |
|
245 } |
|
246 INFO_PRINTF2(_L("SdpUtil PutUint64 Call: actual = %lu"), theNumber); |
|
247 INFO_PRINTF2(_L("SdpUtil PutUint64 Call: expected = %lu"), expectedValue); |
|
248 |
|
249 if( expectedValue != theNumber ) |
|
250 { |
|
251 ERR_PRINTF1(_L("PutUint64 is not as expected!")); |
|
252 SetBlockResult(EFail); |
|
253 } |
|
254 } |
|
255 else |
|
256 { |
|
257 ERR_PRINTF2(_L("Missing parameter %S"), &KNumber()); |
|
258 SetBlockResult(EFail); |
|
259 } |
|
260 } |
|
261 |
|
262 /** |
|
263 Test GetUint64() |
|
264 */ |
|
265 void CT_DataSdpUtil::DoCmdGetUint64(const TDesC& aSection) |
|
266 { |
|
267 INFO_PRINTF1(_L("SdpUtil GetUint64 Call")); |
|
268 |
|
269 TPtrC theString; |
|
270 if( GetStringFromConfig(aSection, KObject(), theString) ) |
|
271 { |
|
272 HBufC8* buffer8=HBufC8::NewLC(theString.Length()); |
|
273 buffer8->Des().Copy(theString); |
|
274 TPtr8 theString8=buffer8->Des(); |
|
275 |
|
276 TUint64 theNumber = 0; |
|
277 SdpUtil::GetUint64(theString8, theNumber); |
|
278 INFO_PRINTF2(_L("SdpUtil GetUint64 Call: actual = %lu"), theNumber); |
|
279 |
|
280 const TUint8* dataPtr = theString8.Ptr(); |
|
281 TUint64 expectedValue = (static_cast<TUint64>(dataPtr[0])<<56) | (static_cast<TUint64>(dataPtr[1])<<48) | (static_cast<TUint64>(dataPtr[2])<<40) | (static_cast<TUint64>(dataPtr[3])<<32) | (dataPtr[4]<<24) | (dataPtr[5]<<16) | (dataPtr[6]<<8) | dataPtr[7]; |
|
282 INFO_PRINTF2(_L("SdpUtil GetUint64 Call: expected = %lu"), expectedValue); |
|
283 |
|
284 if( theNumber!=expectedValue ) |
|
285 { |
|
286 ERR_PRINTF1(_L("GetUint64 is not as expected!")); |
|
287 SetBlockResult(EFail); |
|
288 } |
|
289 CleanupStack::PopAndDestroy(buffer8); |
|
290 } |
|
291 else |
|
292 { |
|
293 ERR_PRINTF2(_L("Missing parameter %S"), &KObject()); |
|
294 SetBlockResult(EFail); |
|
295 } |
|
296 } |
|
297 |
|
298 /** |
|
299 Test PutUint128() |
|
300 */ |
|
301 void CT_DataSdpUtil::DoCmdPutUint128(const TDesC& aSection) |
|
302 { |
|
303 INFO_PRINTF1(_L("SdpUtil PutUint128 call")); |
|
304 |
|
305 TInt theValue = 0; |
|
306 TPckgBuf<TUint64> valuePackaged; |
|
307 TUint8* dataPtr=&valuePackaged[0]; |
|
308 |
|
309 if( GetIntFromConfig(aSection, KLower(), theValue) ) |
|
310 { |
|
311 TUint64 lower = theValue; |
|
312 if( GetIntFromConfig(aSection, KHigher(), theValue) ) |
|
313 { |
|
314 TUint64 higher = theValue; |
|
315 SdpUtil::PutUint128(dataPtr, lower, higher); |
|
316 INFO_PRINTF2(_L("SdpUtil PutUint128 Call: actual(Lower) = %lu"), lower); |
|
317 INFO_PRINTF2(_L("SdpUtil PutUint128 Call: actual(Higher) = %lu"), higher); |
|
318 |
|
319 TUint64 tempLow = 0; |
|
320 TUint64 tempHigh = 0; |
|
321 TInt offset = sizeof(TUint64); |
|
322 TUint64 lowExpectedValue = 0; |
|
323 TUint64 highExpectedValue = 0; |
|
324 for(TInt i=offset-1; i>=0; i--) |
|
325 { |
|
326 tempLow = dataPtr[i+offset]<<(8*(sizeof(TUint64)-i-1)); |
|
327 lowExpectedValue = lowExpectedValue + tempLow; |
|
328 |
|
329 tempHigh = dataPtr[i]<<(8*(sizeof(TUint64)-i-1)); |
|
330 highExpectedValue = highExpectedValue + tempHigh; |
|
331 } |
|
332 INFO_PRINTF2(_L("SdpUtil PutUint128 Call: expected(Lower) = %lu"), lowExpectedValue); |
|
333 INFO_PRINTF2(_L("SdpUtil PutUint128 Call: expected(Higher) = %lu"), highExpectedValue); |
|
334 if( (lowExpectedValue != lower) || (highExpectedValue != higher) ) |
|
335 { |
|
336 ERR_PRINTF1(_L("PutUint128 is not as expected!")); |
|
337 SetBlockResult(EFail); |
|
338 } |
|
339 } |
|
340 else |
|
341 { |
|
342 ERR_PRINTF2(_L("Missing parameter %S"), &KHigher()); |
|
343 SetBlockResult(EFail); |
|
344 } |
|
345 } |
|
346 else |
|
347 { |
|
348 ERR_PRINTF2(_L("Missing parameter %S"), &KHigher()); |
|
349 SetBlockResult(EFail); |
|
350 } |
|
351 } |
|
352 |
|
353 /** |
|
354 Test GetUint128() |
|
355 */ |
|
356 void CT_DataSdpUtil::DoCmdGetUint128(const TDesC& aSection) |
|
357 { |
|
358 INFO_PRINTF1(_L("SdpUtil GetUint128 Call")); |
|
359 |
|
360 TPtrC theString; |
|
361 if( GetStringFromConfig(aSection, KObject(), theString) ) |
|
362 { |
|
363 HBufC8* buffer8=HBufC8::NewLC(theString.Length()); |
|
364 buffer8->Des().Copy(theString); |
|
365 TPtr8 theString8=buffer8->Des(); |
|
366 |
|
367 TUint64 lower = 0; |
|
368 TUint64 higher = 0; |
|
369 SdpUtil::GetUint128(theString8, lower, higher); |
|
370 INFO_PRINTF3(_L("SdpUtil GetUint128 Call: actual(Lower/Higher) = %lu/%lu"), lower, higher); |
|
371 |
|
372 const TUint8* dataPtr = theString8.Ptr(); |
|
373 TUint64 highExpectedValue = (static_cast<TUint64>(dataPtr[0])<<56) | (static_cast<TUint64>(dataPtr[1])<<48) | (static_cast<TUint64>(dataPtr[2])<<40) | (static_cast<TUint64>(dataPtr[3])<<32) | (dataPtr[4]<<24) | (dataPtr[5]<<16) | (dataPtr[6]<<8) | dataPtr[7]; |
|
374 TUint64 lowExpectedValue = (static_cast<TUint64>(dataPtr[8])<<56) | (static_cast<TUint64>(dataPtr[9])<<48) | (static_cast<TUint64>(dataPtr[10])<<40) | (static_cast<TUint64>(dataPtr[11])<<32) | (dataPtr[12]<<24) | (dataPtr[13]<<16) | (dataPtr[14]<<8) | dataPtr[15]; |
|
375 INFO_PRINTF3(_L("SdpUtil GetUint128 Call: expected(Lower/Higher) = %lu/%lu"), lowExpectedValue, highExpectedValue); |
|
376 |
|
377 if( (lowExpectedValue != lower) || (highExpectedValue != higher) ) |
|
378 { |
|
379 ERR_PRINTF1(_L("GetUint128 is not as expected!")); |
|
380 SetBlockResult(EFail); |
|
381 } |
|
382 CleanupStack::PopAndDestroy(buffer8); |
|
383 } |
|
384 else |
|
385 { |
|
386 ERR_PRINTF2(_L("Missing parameter %S"), &KObject()); |
|
387 SetBlockResult(EFail); |
|
388 } |
|
389 } |