|
1 // Copyright (c) 2005-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 // SDP Database library test code |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <f32file.h> |
|
21 #include <e32math.h> |
|
22 #include <btsdp.h> |
|
23 #include <e32def.h> |
|
24 #include <e32const.h> |
|
25 #include <e32std.h> |
|
26 #include "listener.h" |
|
27 #include "reqhandler.h" |
|
28 #include "SDPDatabase.h" |
|
29 #include "protocolmanl.h" |
|
30 #include "MAttributeVisitor.h" |
|
31 #include "ServiceSearchVisitor.h" |
|
32 #include "DataEncoder.h" |
|
33 #include "ExtractorVisitor.h" |
|
34 #include "EncoderVisitor.h" |
|
35 #include "responsesizevisitor.h" |
|
36 #include "debug.h" |
|
37 //#ifdef __EPOC32__ |
|
38 #include <c32comm.h> |
|
39 //#endif |
|
40 |
|
41 GLDEF_D RTest test(_L("SDP database DLL tests")); |
|
42 |
|
43 #if defined (__WINS__) |
|
44 #define PDD_NAME _L("ECDRV") |
|
45 #define LDD_NAME _L("ECOMM") |
|
46 #else // __GCC32__ |
|
47 #define PDD_NAME _L("EUART1") |
|
48 #define LDD_NAME _L("ECOMM") |
|
49 // #define ETNA_PDD_NAME _L("EUART2") // for debugging over com2 |
|
50 #endif |
|
51 |
|
52 CSdpDatabase *BuildDbL(); |
|
53 CSdpDatabase *BuildUpf4DbL(); |
|
54 CSdpDatabase* BuildContinuationDbL(); |
|
55 CSdpDatabase* BuildNestedListDbL(); |
|
56 CSdpDatabase* BuildPrequalDbL(); |
|
57 // in Builddb.cpp |
|
58 |
|
59 void LoadLDD_PDD() |
|
60 { |
|
61 TInt r; |
|
62 //#ifdef __EPOC32__ |
|
63 r=StartC32(); |
|
64 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
65 { |
|
66 test.Printf(_L("Failed %d!\n\r"),r); |
|
67 test(r==KErrNone); |
|
68 } |
|
69 else |
|
70 test.Printf(_L("Started C32\n")); |
|
71 //#endif |
|
72 test.Printf(_L("Loading PDD\n")); |
|
73 r=User::LoadPhysicalDevice(PDD_NAME); |
|
74 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
75 { |
|
76 test.Printf(_L("Failed %d!\n\r"),r); |
|
77 test(r==KErrNone); |
|
78 } |
|
79 else |
|
80 test.Printf(_L("Loaded PDD\n")); |
|
81 test.Printf(_L("Loading LDD\n")); |
|
82 r=User::LoadLogicalDevice(LDD_NAME); |
|
83 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
84 { |
|
85 test.Printf(_L("Failed %d!\n\r"),r); |
|
86 test(r==KErrNone); |
|
87 } |
|
88 else |
|
89 test.Printf(_L("Loaded LDD\n")); |
|
90 } |
|
91 |
|
92 // plagiarised from tsdp.cpp |
|
93 // actually Mel can't cast from Shortest form (TPtrC8) to a TDesC8 without this call |
|
94 void HexDes(const TDesC8& aDes) |
|
95 { |
|
96 for (TInt i = 0; i < aDes.Length(); ++i) |
|
97 test.Printf(_L("%02x"), aDes[i]); |
|
98 } |
|
99 |
|
100 class CAttrPrintVisitor : public CBase, public MAttributeVisitor |
|
101 { |
|
102 public: |
|
103 CAttrPrintVisitor(CConsoleBase& aConsole) : iConsole(aConsole) {iIndent=0;} |
|
104 ~CAttrPrintVisitor() {/*iConsole.Getch();*/} |
|
105 void VisitAttributeL(CSdpAttr &aAttribute) |
|
106 { |
|
107 Indent(); |
|
108 test.Printf(_L("\nID:0x%x:"), aAttribute.AttributeID()); |
|
109 } |
|
110 void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType) |
|
111 { |
|
112 // FIXME need a new object like the match list that will just store the object in |
|
113 // FIXME an array, or perhaps just print it ? Is it a visitor ? |
|
114 // CSdpSearchPattern* encAttrList = new (ELeave) CSdpSearchPattern; |
|
115 // CleanupStack::PushL(encAttrList); |
|
116 |
|
117 // CElementParser* parser = CElementParser::NewL(encAttrList); |
|
118 // CleanupStack::PushL(parser); |
|
119 |
|
120 // TInt rem; |
|
121 |
|
122 TBuf16<64> iString; |
|
123 // TInt iFound; |
|
124 switch (aType) |
|
125 { |
|
126 case ETypeString: |
|
127 iString.Copy(aValue.Des()); |
|
128 test.Printf(_L("\"%S\""),&iString); |
|
129 break; |
|
130 case ETypeDES: |
|
131 test.Printf(_L(" DES")); |
|
132 break; |
|
133 case ETypeUint: |
|
134 test.Printf(_L(" UInt:0x%x"), aValue.Uint()); |
|
135 break; |
|
136 case ETypeUUID: |
|
137 test.Printf(_L(" UUID:0x")); |
|
138 HexDes(aValue.UUID().ShortestForm()); |
|
139 break; |
|
140 case ETypeEncoded: |
|
141 HexDes(aValue.Des()); // simplest |
|
142 //parse out the elements in this encoded attribute |
|
143 // rem = parser->ParseElementsL(aValue.Des()); |
|
144 // CleanupStack::PopAndDestroy(/*parser*/); |
|
145 // for (iFound=0 ; iFound++ ; (iFound < (encAttrList->Length()))) |
|
146 // { |
|
147 // VisitAttributeValueL(encAttrList->At(iFound).Value, encAttrList->At(iFound).Type); |
|
148 // } |
|
149 // CleanupStack::PopAndDestroy(/*encAttrList*/); |
|
150 break; |
|
151 default: |
|
152 test.Printf(_L("type %d\n"), aType); |
|
153 } |
|
154 } |
|
155 void StartListL(CSdpAttrValueList &/*aList*/) |
|
156 { |
|
157 ++iIndent; |
|
158 test.Printf(_L("{")); |
|
159 } |
|
160 void EndListL() |
|
161 { |
|
162 if(iIndent<=0) |
|
163 { |
|
164 test.Printf(_L("\nERROR! Unmatched EndList!\n")); |
|
165 __DEBUGGER(); |
|
166 } |
|
167 test.Printf(_L("}")); |
|
168 --iIndent; |
|
169 } |
|
170 private: |
|
171 void Indent() {/*test.SetPos(iIndent)*/;} |
|
172 CConsoleBase &iConsole; |
|
173 TInt iIndent; |
|
174 }; |
|
175 |
|
176 void PrintDb(CSdpDatabase& aDb, CConsoleBase& aConsole) |
|
177 { |
|
178 aConsole.Printf(_L("Printing Database...\n")); |
|
179 |
|
180 for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++) |
|
181 {// Iterate thru records in Db |
|
182 aConsole.Printf(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle()); |
|
183 for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
184 {// Iterate thru attributes in record |
|
185 CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(aConsole); |
|
186 (*attrIter).AcceptVisitorL(*theVisitor); |
|
187 delete theVisitor; |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 class CAttrFlogVisitor : public CBase, public MAttributeVisitor |
|
193 { |
|
194 public: |
|
195 CAttrFlogVisitor(){} |
|
196 void VisitAttributeL(CSdpAttr &aAttribute) |
|
197 { |
|
198 Indent(); |
|
199 |
|
200 //3 lines for one here, but prevents warning. |
|
201 TUint id; |
|
202 id= aAttribute.AttributeID(); |
|
203 FTRACE(FPrint(_L("Attribute ID: 0x%x\n"), id)); |
|
204 |
|
205 (void)(id != 0); // keep compiler happy by referencing id as an r-value in urel |
|
206 } |
|
207 void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType) |
|
208 { |
|
209 TBuf16<64> iString; |
|
210 switch (aType) |
|
211 { |
|
212 case ETypeString: |
|
213 iString.Copy(aValue.Des()); |
|
214 FTRACE(FPrint(_L("\"%S\""),&iString)); |
|
215 break; |
|
216 case ETypeDES: |
|
217 FTRACE(FPrint(_L(" DES"))); |
|
218 break; |
|
219 case ETypeUint: |
|
220 FTRACE(FPrint(_L(" UInt:0x%x"), aValue.Uint())); |
|
221 break; |
|
222 case ETypeUUID: |
|
223 FTRACE(FPrint(_L(" UUID:0x"))); |
|
224 HexDes(aValue.UUID().ShortestForm()); |
|
225 break; |
|
226 case ETypeEncoded: |
|
227 HexDes(aValue.Des()); // simplest |
|
228 break; |
|
229 default: |
|
230 FTRACE(FPrint(_L("type %d\n"), aType)); |
|
231 } |
|
232 } |
|
233 //void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType) |
|
234 // { |
|
235 // Indent(); |
|
236 // FTRACE(FPrint(_L("(Val: type %d)\n"), aType)); |
|
237 // if(aType==ETypeUUID) |
|
238 // { |
|
239 // TUUID u = aValue.UUID(); |
|
240 // FTRACE(FPrint(_L("(Val: uuid 0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x)\n"), |
|
241 // u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15])); |
|
242 // } |
|
243 // |
|
244 // } |
|
245 void StartListL(CSdpAttrValueList &/*aList*/) |
|
246 { |
|
247 ++iIndent; |
|
248 Indent(); |
|
249 FTRACE(FPrint(_L("{\n"))); |
|
250 } |
|
251 void EndListL() |
|
252 { |
|
253 if(iIndent<=0) |
|
254 { |
|
255 FTRACE(FPrint(_L("\nERROR! Unmatched EndList!\n"))); |
|
256 __DEBUGGER(); |
|
257 } |
|
258 Indent(); |
|
259 FTRACE(FPrint(_L("}\n"))); |
|
260 --iIndent; |
|
261 } |
|
262 private: |
|
263 void HexDes(const TDesC8& aDes) |
|
264 { |
|
265 for (TInt i = 0; i < aDes.Length(); ++i) |
|
266 { |
|
267 FTRACE(FPrint(_L("%02x"), aDes[i])); |
|
268 } |
|
269 } |
|
270 |
|
271 void Indent() |
|
272 { |
|
273 for(TInt i=0; i<iIndent;++i) |
|
274 { |
|
275 FTRACE(FPrint(_L(" "))); |
|
276 } |
|
277 |
|
278 } |
|
279 TInt iIndent; |
|
280 }; |
|
281 |
|
282 |
|
283 void FlogDb(CSdpDatabase& aDb) |
|
284 { |
|
285 FTRACE(FPrint(_L("\n\nPrinting Database...\n\n"))); |
|
286 |
|
287 for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++) |
|
288 {// Iterate thru records in Db |
|
289 FTRACE(FPrint(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle())); |
|
290 for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
291 {// Iterate thru attributes in record |
|
292 CAttrFlogVisitor* theVisitor = new CAttrFlogVisitor(); |
|
293 (*attrIter).AcceptVisitorL(*theVisitor); |
|
294 delete theVisitor; |
|
295 } |
|
296 } |
|
297 FTRACE(FPrint(_L("\n\nEnd Printing Database...\n\n\n\n"))); |
|
298 } |
|
299 |
|
300 |
|
301 |
|
302 class CSearchObserver : public CBase, public MServiceSearchHandler |
|
303 { |
|
304 public: |
|
305 void RecordFoundL(CSdpServRecord& aMatchingRec) |
|
306 { |
|
307 ++iMatchesFound; |
|
308 test.Printf(_L("Match %d found in record 0x%x\n"), iMatchesFound, aMatchingRec.Handle()); |
|
309 }; |
|
310 TInt iMatchesFound; |
|
311 }; |
|
312 |
|
313 void SearchDbL(CSdpDatabase &aDb, const CSdpSearchPattern &aPattern, TInt aExpectedMatches) |
|
314 { |
|
315 CSearchObserver *ob = new(ELeave) CSearchObserver; |
|
316 CleanupStack::PushL(ob); |
|
317 CServiceSearchVisitor::SearchDbL(aDb, aPattern, *ob); |
|
318 test(aExpectedMatches==ob->iMatchesFound); |
|
319 CleanupStack::PopAndDestroy(); |
|
320 } |
|
321 |
|
322 void RegisterDatabaseInServerL (RSdpDatabase& aDb, CSdpDatabase& aDbStruct) |
|
323 { |
|
324 for(TServRecordIter recIter(aDbStruct.RecordIter()); recIter; recIter++) |
|
325 {// Iterate thru records in Db |
|
326 TServAttrIter attrIter((*recIter).AttributeIter()); |
|
327 if(!attrIter) |
|
328 continue; |
|
329 if((*attrIter).AttributeID() == 0) |
|
330 attrIter++; //Skip rec handle |
|
331 if(!attrIter) |
|
332 continue; |
|
333 if((*attrIter).AttributeID() != 1 || (*attrIter).Value().Type() != ETypeDES) |
|
334 continue; |
|
335 // Get service class list |
|
336 TSdpServRecordHandle handle; |
|
337 aDb.CreateServiceRecordL((CSdpAttrValueDES&)(*attrIter).Value(), handle); |
|
338 attrIter++; |
|
339 for(; attrIter; attrIter++) |
|
340 {// Iterate thru attributes in record |
|
341 aDb.UpdateAttributeL(handle, (*attrIter).AttributeID(), (*attrIter).Value()); |
|
342 } |
|
343 } |
|
344 } |
|
345 |
|
346 TSdpServRecordHandle BuildPagonisL(RSdpDatabase& aDb, TUUID aUUID, TUint8 aCN) |
|
347 /** |
|
348 Record Pagonis should be used when building a record with a protocol ID |
|
349 list consisting of L2CAP and RFCOMM. This record is for a service of class |
|
350 "serial port" - UUID16 0x1101 |
|
351 note that attributes 2, 5 and 0x201 should be updated. |
|
352 also note only English, pas de Francais, keine Deutsch, non Espanol |
|
353 **/ |
|
354 { |
|
355 TBuf8<4> value1; |
|
356 TBuf8<4> value2; |
|
357 TSdpServRecordHandle recHandle; |
|
358 CSdpAttrValue* attrVal = 0; |
|
359 CSdpAttrValueDES* attrValDES = 0; |
|
360 |
|
361 |
|
362 value1.FillZ(4); |
|
363 value2.FillZ(4); |
|
364 |
|
365 // Set Attr 1 (service class list) to list with UUID = 0x1101 (serial port) |
|
366 // or 0x1102 (LANP) |
|
367 aDb.CreateServiceRecordL(aUUID, recHandle); |
|
368 test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
369 |
|
370 // Set Attr 2 (service record state) to 0 |
|
371 value1.FillZ(4); |
|
372 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
373 CleanupStack::PushL(attrVal); |
|
374 aDb.UpdateAttributeL(recHandle, 0x02, *attrVal); |
|
375 CleanupStack::PopAndDestroy(); |
|
376 attrVal = 0; |
|
377 |
|
378 // Set attr 4 (protocol list) to L2CAP, and RFCOMM |
|
379 value1.FillZ(4); |
|
380 value1[3] = 3; |
|
381 value2.FillZ(4); |
|
382 value2[3] = aCN; |
|
383 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
384 CleanupStack::PushL(attrValDES); |
|
385 attrValDES |
|
386 ->StartListL() |
|
387 ->BuildDESL() |
|
388 ->StartListL() |
|
389 ->BuildUUIDL(TUUID(TUint16(0x0100))) // L2CAP |
|
390 ->BuildUintL(value1) |
|
391 ->EndListL() |
|
392 ->BuildDESL() |
|
393 ->StartListL() |
|
394 ->BuildUUIDL(TUUID(TUint16(0x0003))) // RFCOMM |
|
395 ->BuildUintL(value2) |
|
396 ->EndListL() |
|
397 ->EndListL(); |
|
398 aDb.UpdateAttributeL(recHandle, 0x04, *attrValDES); |
|
399 CleanupStack::PopAndDestroy(); |
|
400 attrValDES = 0; |
|
401 |
|
402 // Set Attr 5 (browse group list) to list with one UUID |
|
403 // 0x1101 (serial port class) |
|
404 // this should be updated with other service classes when other services are added. |
|
405 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
406 CleanupStack::PushL(attrValDES); |
|
407 attrValDES |
|
408 ->StartListL() |
|
409 ->BuildUUIDL(TUUID(TUint32(0x1002))) |
|
410 ->EndListL(); |
|
411 aDb.UpdateAttributeL(recHandle, 0x05, *attrValDES); |
|
412 CleanupStack::PopAndDestroy(); |
|
413 attrValDES = 0; |
|
414 |
|
415 |
|
416 // Set Attr 0x006 (language base) |
|
417 value1.FillZ(4); |
|
418 value1[2] = 0x65; |
|
419 value1[3] = 0x6e; |
|
420 TBuf8<4> val2; |
|
421 TBuf8<4> val3; |
|
422 val2.FillZ(4); |
|
423 val3.FillZ(4); |
|
424 val2[3] = 0x6a; |
|
425 val3[2] = 0x01; |
|
426 |
|
427 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
428 CleanupStack::PushL(attrValDES); |
|
429 attrValDES |
|
430 ->StartListL() |
|
431 ->BuildUintL(value1) // english |
|
432 ->BuildUintL(val2) // UTF-8 |
|
433 ->BuildUintL(val3) // language base |
|
434 ->EndListL(); |
|
435 aDb.UpdateAttributeL(recHandle, 0x06, *attrValDES); |
|
436 CleanupStack::PopAndDestroy(); |
|
437 attrValDES = 0; |
|
438 |
|
439 // Set Attr 0x007 (time to live) to 1200 (0x4B0) seconds (20 minutes) |
|
440 value1.FillZ(4); |
|
441 value1[2]=4; |
|
442 value1[3]=0xb0; |
|
443 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
444 CleanupStack::PushL(attrVal); |
|
445 aDb.UpdateAttributeL(recHandle, 0x07, *attrVal); |
|
446 CleanupStack::PopAndDestroy(); |
|
447 attrVal = 0; |
|
448 |
|
449 // Set Attr 0x008 (availability) to 0xff - fully available - not in use |
|
450 value1.FillZ(4); |
|
451 value1[3]=0xff; |
|
452 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
453 CleanupStack::PushL(attrVal); |
|
454 aDb.UpdateAttributeL(recHandle, 0x08, *attrVal); |
|
455 CleanupStack::PopAndDestroy(); |
|
456 attrVal = 0; |
|
457 |
|
458 |
|
459 // Set Attr 0x100 (default Name) to string |
|
460 attrVal = CSdpAttrValueString::NewStringL(_L8("Pagonis Service")); |
|
461 CleanupStack::PushL(attrVal); |
|
462 aDb.UpdateAttributeL(recHandle, 0x0100, *attrVal); |
|
463 CleanupStack::PopAndDestroy(); |
|
464 attrVal = 0; |
|
465 |
|
466 // Set Attr 0x101 (def. description) to string |
|
467 attrVal = CSdpAttrValueString::NewStringL(_L8("It's all Greek to me!")); |
|
468 CleanupStack::PushL(attrVal); |
|
469 aDb.UpdateAttributeL(recHandle, 0x0101, *attrVal); |
|
470 CleanupStack::PopAndDestroy(); |
|
471 attrVal = 0; |
|
472 |
|
473 // Set Attr 0x102 (def. provider) to Symbian |
|
474 attrVal = CSdpAttrValueString::NewStringL(_L8("Symbian Ltd.")); |
|
475 CleanupStack::PushL(attrVal); |
|
476 aDb.UpdateAttributeL(recHandle, 0x0102, *attrVal); |
|
477 CleanupStack::PopAndDestroy(); |
|
478 attrVal = 0; |
|
479 |
|
480 // Set Attr 0x201 (service database state) to 0 |
|
481 value1.FillZ(4); |
|
482 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
483 CleanupStack::PushL(attrVal); |
|
484 aDb.UpdateAttributeL(recHandle, 0x0201, *attrVal); |
|
485 CleanupStack::PopAndDestroy(); |
|
486 attrVal = 0; |
|
487 |
|
488 return recHandle; |
|
489 } |
|
490 |
|
491 |
|
492 TSdpServRecordHandle BuildWAPL(RSdpDatabase& aDb, TUint8 aCN) |
|
493 /** |
|
494 Record Wap should be used when building a record with a protocol ID |
|
495 list consisting of L2CAP and RFCOMM, similar to Pagonis but containing |
|
496 a profile descriptor list with LAN access using PPP. |
|
497 This record is for a service of class "WAP bearer" - UUID16 0x1113 |
|
498 **/ |
|
499 { |
|
500 TBuf8<4> value1; |
|
501 TBuf8<4> value2; |
|
502 TSdpServRecordHandle recHandle; |
|
503 CSdpAttrValue* attrVal = 0; |
|
504 CSdpAttrValueDES* attrValDES = 0; |
|
505 |
|
506 |
|
507 value1.FillZ(4); |
|
508 value2.FillZ(4); |
|
509 |
|
510 // Set Attr 1 (service class list) to list with UUID = 0x1113 (WAP access device) |
|
511 aDb.CreateServiceRecordL(TUUID(TUint16(0x1113)), recHandle); |
|
512 test.Printf(_L("WAP Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
513 |
|
514 // Set Attr 2 (service record state) to 0 |
|
515 value1.FillZ(4); |
|
516 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
517 CleanupStack::PushL(attrVal); |
|
518 aDb.UpdateAttributeL(recHandle, 0x02, *attrVal); |
|
519 CleanupStack::PopAndDestroy(); |
|
520 attrVal = 0; |
|
521 |
|
522 // Set attr 4 (protocol list) to L2CAP, and RFCOMM |
|
523 value1.FillZ(4); |
|
524 value1[3] = 3; |
|
525 value2.FillZ(4); |
|
526 value2[3] = aCN; |
|
527 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
528 CleanupStack::PushL(attrValDES); |
|
529 attrValDES |
|
530 ->StartListL() |
|
531 ->BuildDESL() |
|
532 ->StartListL() |
|
533 ->BuildUUIDL(TUUID(TUint16(0x0100))) // L2CAP |
|
534 ->BuildUintL(value1) |
|
535 ->EndListL() |
|
536 ->BuildDESL() |
|
537 ->StartListL() |
|
538 ->BuildUUIDL(TUUID(TUint16(0x0003))) // RFCOMM |
|
539 ->BuildUintL(value2) |
|
540 ->EndListL() |
|
541 ->EndListL(); |
|
542 aDb.UpdateAttributeL(recHandle, 0x04, *attrValDES); |
|
543 CleanupStack::PopAndDestroy(); |
|
544 attrValDES = 0; |
|
545 |
|
546 // Set Attr 5 (browse group list) to list with one UUID |
|
547 // 0x1101 (serial port class) |
|
548 // this should be updated with other service classes when other services are added. |
|
549 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
550 CleanupStack::PushL(attrValDES); |
|
551 attrValDES |
|
552 ->StartListL() |
|
553 ->BuildUUIDL(TUUID(TUint32(0x1002))) |
|
554 ->EndListL(); |
|
555 aDb.UpdateAttributeL(recHandle, 0x05, *attrValDES); |
|
556 CleanupStack::PopAndDestroy(); |
|
557 attrValDES = 0; |
|
558 |
|
559 |
|
560 // Set Attr 0x006 (language base) |
|
561 value1.FillZ(4); |
|
562 value1[2] = 0x65; |
|
563 value1[3] = 0x6e; |
|
564 TBuf8<4> val2; |
|
565 TBuf8<4> val3; |
|
566 val2.FillZ(4); |
|
567 val3.FillZ(4); |
|
568 val2[3] = 0x6a; |
|
569 val3[2] = 0x01; |
|
570 |
|
571 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
572 CleanupStack::PushL(attrValDES); |
|
573 attrValDES |
|
574 ->StartListL() |
|
575 ->BuildUintL(value1) // english |
|
576 ->BuildUintL(val2) // UTF-8 |
|
577 ->BuildUintL(val3) // language base |
|
578 ->EndListL(); |
|
579 aDb.UpdateAttributeL(recHandle, 0x06, *attrValDES); |
|
580 CleanupStack::PopAndDestroy(); |
|
581 attrValDES = 0; |
|
582 |
|
583 // Set Attr 0x007 (time to live) to 1200 (0x4B0) seconds (20 minutes) |
|
584 value1.FillZ(4); |
|
585 value1[2]=4; |
|
586 value1[3]=0xb0; |
|
587 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
588 CleanupStack::PushL(attrVal); |
|
589 aDb.UpdateAttributeL(recHandle, 0x07, *attrVal); |
|
590 CleanupStack::PopAndDestroy(); |
|
591 attrVal = 0; |
|
592 |
|
593 // Set Attr 0x008 (availability) to 0xff - fully available - not in use |
|
594 value1.FillZ(4); |
|
595 value1[3]=0xff; |
|
596 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
597 CleanupStack::PushL(attrVal); |
|
598 aDb.UpdateAttributeL(recHandle, 0x08, *attrVal); |
|
599 CleanupStack::PopAndDestroy(); |
|
600 attrVal = 0; |
|
601 |
|
602 // Set Attr 0x009 (profile descriptor) to confuse the BTCOMM client when looking for LANP |
|
603 value1.FillZ(4); |
|
604 value1[3] = 1; |
|
605 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
606 CleanupStack::PushL(attrValDES); |
|
607 attrValDES |
|
608 ->StartListL() |
|
609 ->BuildDESL() |
|
610 ->StartListL() |
|
611 ->BuildUUIDL(TUUID(TUint16(0x1102))) // LAN access using PPP |
|
612 ->BuildUintL(value1) |
|
613 ->EndListL() |
|
614 ->EndListL(); |
|
615 aDb.UpdateAttributeL(recHandle, 0x09, *attrValDES); |
|
616 CleanupStack::PopAndDestroy(); |
|
617 attrValDES = 0; |
|
618 |
|
619 |
|
620 // Set Attr 0x100 (default Name) to string |
|
621 attrVal = CSdpAttrValueString::NewStringL(_L8("Pagonis Service")); |
|
622 CleanupStack::PushL(attrVal); |
|
623 aDb.UpdateAttributeL(recHandle, 0x0100, *attrVal); |
|
624 CleanupStack::PopAndDestroy(); |
|
625 attrVal = 0; |
|
626 |
|
627 // Set Attr 0x101 (def. description) to string |
|
628 attrVal = CSdpAttrValueString::NewStringL(_L8("It's all Greek to me!")); |
|
629 CleanupStack::PushL(attrVal); |
|
630 aDb.UpdateAttributeL(recHandle, 0x0101, *attrVal); |
|
631 CleanupStack::PopAndDestroy(); |
|
632 attrVal = 0; |
|
633 |
|
634 // Set Attr 0x102 (def. provider) to Symbian |
|
635 attrVal = CSdpAttrValueString::NewStringL(_L8("Symbian Ltd.")); |
|
636 CleanupStack::PushL(attrVal); |
|
637 aDb.UpdateAttributeL(recHandle, 0x0102, *attrVal); |
|
638 CleanupStack::PopAndDestroy(); |
|
639 attrVal = 0; |
|
640 |
|
641 // Set Attr 0x201 (service database state) to 0 |
|
642 value1.FillZ(4); |
|
643 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
644 CleanupStack::PushL(attrVal); |
|
645 aDb.UpdateAttributeL(recHandle, 0x0201, *attrVal); |
|
646 CleanupStack::PopAndDestroy(); |
|
647 attrVal = 0; |
|
648 |
|
649 return recHandle; |
|
650 } |
|
651 |
|
652 |
|
653 |
|
654 void Test0() |
|
655 /** |
|
656 Client/server test. |
|
657 **/ |
|
658 { |
|
659 FLOG(_L("Running test 0")); |
|
660 //FIXME: TRAPD? |
|
661 test.Start(_L("Test 0 -- Client/Server")); |
|
662 TInt ret; |
|
663 LoadLDD_PDD(); |
|
664 |
|
665 RSdp sdp; |
|
666 ret = sdp.Connect(); |
|
667 if(ret!=KErrNone) |
|
668 { |
|
669 test.End(); |
|
670 return; |
|
671 } |
|
672 RSdpDatabase db; |
|
673 ret = db.Open(sdp); |
|
674 if(ret!=KErrNone) |
|
675 { |
|
676 test.End(); |
|
677 return; |
|
678 } |
|
679 TSdpServRecordHandle recHandle = 0; |
|
680 TUUID uuid = TUUID(0x20000); //prevents warning |
|
681 db.CreateServiceRecordL(uuid, recHandle); |
|
682 test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
683 CSdpAttrValueDES* list = CSdpAttrValueDES::NewDESL(NULL); |
|
684 MSdpElementBuilder* bldr= list; |
|
685 CleanupStack::PushL(list); |
|
686 |
|
687 bldr |
|
688 ->StartListL() |
|
689 ->BuildUUIDL(TUUID(TUint32(0x20002000))) |
|
690 ->BuildUUIDL(TUUID(TUint32(0x11112222), TUint32(0x33334444), |
|
691 TUint32(0x55556666), TUint32(0x77778888))) |
|
692 ->BuildUUIDL(TUUID(TUint32(0x40000))) |
|
693 ->EndListL(); |
|
694 //db.CreateServiceRecordL(*list, recHandle); |
|
695 CleanupStack::PopAndDestroy(); //list |
|
696 //test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
697 //User::WaitForRequest(status); |
|
698 //if(status==KErrNone) |
|
699 // test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandlePckgBuf()); |
|
700 //else |
|
701 // test.Printf(_L("Service Record Creation ERROR %d!\n\n"), status.Int()); |
|
702 |
|
703 TBuf8<8> buf8(_L8("Mel!")); |
|
704 buf8[1] = 'E'; |
|
705 buf8[2] = 'L'; |
|
706 TDesC16 buf16(_L("Nicky!")); |
|
707 db.UpdateAttributeL(recHandle, 0x3454, buf8); |
|
708 db.UpdateAttributeL(recHandle, 0x3455, _L("Nicky!")); |
|
709 db.UpdateAttributeL(recHandle, 0x3455, _L("Micky!")); |
|
710 db.UpdateAttributeL(recHandle, 0x3456, 0x9999); |
|
711 db.DeleteAttributeL(recHandle, 0x3456); |
|
712 db.UpdateAttributeL(recHandle, 0x3456, 0x7777); |
|
713 db.DeleteAttributeL(recHandle, 0x5555); //does not exist! |
|
714 //db.DeleteRecordL(recHandleSpecial); |
|
715 db.Close(); |
|
716 sdp.Close(); |
|
717 test.End(); |
|
718 } |
|
719 |
|
720 |
|
721 void Test1() |
|
722 /** |
|
723 Client/server test for use with John Pagonis. |
|
724 Suitable database built on client side, and placed in server. |
|
725 Server left alive till user chooses to kill it. |
|
726 **/ |
|
727 { |
|
728 FLOG(_L("Running test 1")); |
|
729 //FIXME: TRAPD? |
|
730 test.Start(_L("Test 1 -- Client/Server for BTCOMM testing...\n")); |
|
731 test.Printf(_L("This builds a database with three service records\n")); |
|
732 test.Printf(_L("The First one (UUID 1101) containing protocol attribute value: L2CAP, 3; RFCOMM, 1\n")); |
|
733 test.Printf(_L("the second (UUID 1102 LANP) containing protocol attribute value: L2CAP, 3; RFCOMM, 2.\n")); |
|
734 test.Printf(_L("the third (UUID 1103) containing protocol attribute value: L2CAP, 3; RFCOMM, 3.\n")); |
|
735 test.Printf(_L("the third is a WAP server record and should never be selected\n")); |
|
736 test.Printf(_L("The server then remains in listening mode\n")); |
|
737 test.Printf(_L("until the user of Test 1 types 'x'.\n\n\n\n")); |
|
738 |
|
739 TChar c; |
|
740 RSdp sdp; |
|
741 RSdpDatabase db; |
|
742 // User::After(5000000); |
|
743 TInt ret; |
|
744 LoadLDD_PDD(); |
|
745 |
|
746 ret = sdp.Connect(); |
|
747 if(ret!=KErrNone) |
|
748 { |
|
749 test.End(); |
|
750 return; |
|
751 } |
|
752 ret = db.Open(sdp); |
|
753 if(ret!=KErrNone) |
|
754 { |
|
755 test.End(); |
|
756 return; |
|
757 } |
|
758 |
|
759 TSdpServRecordHandle recHandle1; |
|
760 TSdpServRecordHandle recHandle2; |
|
761 TSdpServRecordHandle recHandle3; |
|
762 |
|
763 test.Printf(_L("SDP server with record 0, type 'x' to continue.\n")); |
|
764 c = test.Getch(); |
|
765 while (c!='x' && c!='X') |
|
766 c = test.Getch(); |
|
767 |
|
768 recHandle1 = BuildPagonisL(db,TUUID(TUint32(0x1101)), 1); |
|
769 test.Printf(_L("Pagonis record (0x1101), type 'x' to continue.\n")); |
|
770 c = test.Getch(); |
|
771 while (c!='x' && c!='X') |
|
772 c = test.Getch(); |
|
773 |
|
774 |
|
775 recHandle2 = BuildPagonisL(db,TUUID(TUint32(0x1102)), 2); |
|
776 test.Printf(_L("Pagonis record (0x1102), type 'x' to continue.\n")); |
|
777 c = test.Getch(); |
|
778 while (c!='x' && c!='X') |
|
779 c = test.Getch(); |
|
780 |
|
781 recHandle3 = BuildWAPL(db, 3); |
|
782 test.Printf(_L("one WAP record, type 'x' to continue.\n\n")); |
|
783 c = test.Getch(); |
|
784 while (c!='x' && c!='X') |
|
785 c = test.Getch(); |
|
786 |
|
787 test.Printf(_L("The database is now ready to test, type 'x' to exit.\n\n")); |
|
788 c = test.Getch(); |
|
789 while (c!='x' && c!='X') |
|
790 c = test.Getch(); |
|
791 /**/ |
|
792 db.DeleteRecordL(recHandle2); |
|
793 |
|
794 test.Printf(_L("The database has now had the second Pagonis record removed.\ |
|
795 \nWhen you have finished using this database please type 'x'.\n\n")); |
|
796 c = test.Getch(); |
|
797 while (c!='x' && c!='X') |
|
798 c = test.Getch(); |
|
799 db.UpdateAttributeL(recHandle1, 0x3455, _L("Nicky!")); |
|
800 test.Printf(_L("\nTo check on updating record STATE attribute we have now\ |
|
801 \nupdated one random attribute in the first Pagonis record.\ |
|
802 \nPlease type 'x' AGAIN.\n\n")); |
|
803 c = test.Getch(); |
|
804 while (c!='x' && c!='X') |
|
805 c = test.Getch(); |
|
806 db.UpdateAttributeL(recHandle1, 0x3455, _L("Nicky!")); |
|
807 test.Printf(_L("\nTo check on updating record STATE attribute we have now\ |
|
808 \nupdated ONCE AGAIN a random attribute in the first Pagonis\ |
|
809 \nrecord.\ |
|
810 \nPlease type 'x' ONCE AGAIN.\n\n")); |
|
811 c = test.Getch(); |
|
812 db.DeleteAttributeL(recHandle1, 0x3455); |
|
813 while (c!='x' && c!='X') |
|
814 c = test.Getch(); |
|
815 test.Printf(_L("\nTo check on updating record STATE attribute we have now\ |
|
816 \ndeleted an attribute in the first Pagonis\ |
|
817 \nrecord.\ |
|
818 \nPlease type 'x' YET AGAIN - THIS TIME TO KILL THE DATABASE.\n\n")); |
|
819 c = test.Getch(); |
|
820 while (c!='x' && c!='X') |
|
821 c = test.Getch(); |
|
822 db.DeleteAttributeL(recHandle1, 0x3455); |
|
823 /**/ |
|
824 db.DeleteRecordL(recHandle3); |
|
825 // Record with recHandle2 has already been deleted |
|
826 db.DeleteRecordL(recHandle1); |
|
827 db.Close(); |
|
828 sdp.Close(); |
|
829 |
|
830 |
|
831 test.End(); |
|
832 } |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 void TestD() |
|
838 /** |
|
839 Client/server test for use with John Pagonis. |
|
840 Suitable database built on client side, and placed in server. |
|
841 Server left alive till user chooses to kill it. |
|
842 **/ |
|
843 { |
|
844 FLOG(_L("Running test D")); |
|
845 //FIXME: TRAPD? |
|
846 test.Start(_L("Test D -- Client/Server for BTCOMM testing...\n")); |
|
847 test.Printf(_L("This builds a database with four service records\n")); |
|
848 test.Printf(_L("The first one (UUID 1103 WAP) containing protocol attribute value: L2CAP, 3; RFCOMM, 3\n")); |
|
849 test.Printf(_L("the second (UUID 1101) containing protocol attribute value: L2CAP, 3; RFCOMM, 1.\n")); |
|
850 test.Printf(_L("the third (UUID 1103 WAP) containing protocol attribute value: L2CAP, 3; RFCOMM, 4.\n")); |
|
851 test.Printf(_L("the forth (UUID 1102 LANP) containing protocol attribute value: L2CAP, 3; RFCOMM, 2.\n")); |
|
852 test.Printf(_L("The server then remains in listening mode\n")); |
|
853 test.Printf(_L("until the user of Test D types 'x'.\n\n\n\n")); |
|
854 |
|
855 TChar c; |
|
856 RSdp sdp; |
|
857 RSdpDatabase db; |
|
858 // User::After(5000000); |
|
859 TInt ret; |
|
860 LoadLDD_PDD(); |
|
861 |
|
862 ret = sdp.Connect(); |
|
863 if(ret!=KErrNone) |
|
864 { |
|
865 test.End(); |
|
866 return; |
|
867 } |
|
868 ret = db.Open(sdp); |
|
869 if(ret!=KErrNone) |
|
870 { |
|
871 test.End(); |
|
872 return; |
|
873 } |
|
874 |
|
875 TSdpServRecordHandle recHandle1; |
|
876 TSdpServRecordHandle recHandle2; |
|
877 TSdpServRecordHandle recHandle3; |
|
878 TSdpServRecordHandle recHandle4; |
|
879 |
|
880 test.Printf(_L("SDP server with record 0, type 'x' to continue.\n")); |
|
881 c = test.Getch(); |
|
882 while (c!='x' && c!='X') |
|
883 c = test.Getch(); |
|
884 |
|
885 recHandle3 = BuildWAPL(db, 3); |
|
886 test.Printf(_L("one WAP record, type 'x' to continue.\n\n")); |
|
887 c = test.Getch(); |
|
888 while (c!='x' && c!='X') |
|
889 c = test.Getch(); |
|
890 |
|
891 recHandle1 = BuildPagonisL(db,TUUID(TUint32(0x1101)), 1); |
|
892 test.Printf(_L("Pagonis record (0x1101), type 'x' to continue.\n")); |
|
893 c = test.Getch(); |
|
894 while (c!='x' && c!='X') |
|
895 c = test.Getch(); |
|
896 |
|
897 recHandle4 = BuildWAPL(db, 4); |
|
898 test.Printf(_L("one WAP record, type 'x' to continue.\n\n")); |
|
899 c = test.Getch(); |
|
900 while (c!='x' && c!='X') |
|
901 c = test.Getch(); |
|
902 |
|
903 recHandle2 = BuildPagonisL(db,TUUID(TUint32(0x1102)), 2); |
|
904 test.Printf(_L("Pagonis record (0x1102), type 'x' to continue.\n")); |
|
905 c = test.Getch(); |
|
906 while (c!='x' && c!='X') |
|
907 c = test.Getch(); |
|
908 |
|
909 |
|
910 test.Printf(_L("The database is now ready to test, type 'x' to exit.\n\n")); |
|
911 c = test.Getch(); |
|
912 while (c!='x' && c!='X') |
|
913 c = test.Getch(); |
|
914 db.DeleteRecordL(recHandle4); |
|
915 db.DeleteRecordL(recHandle3); |
|
916 db.DeleteRecordL(recHandle2); |
|
917 db.DeleteRecordL(recHandle1); |
|
918 db.Close(); |
|
919 sdp.Close(); |
|
920 |
|
921 |
|
922 test.End(); |
|
923 } |
|
924 |
|
925 |
|
926 void TestE() |
|
927 /** |
|
928 Client/server test for use with John Pagonis. |
|
929 Suitable database built on client side, and placed in server. |
|
930 Server left alive till user chooses to kill it. |
|
931 **/ |
|
932 { |
|
933 FLOG(_L("Running test D")); |
|
934 //FIXME: TRAPD? |
|
935 test.Start(_L("Test E -- Client/Server for BTCOMM testing...\n")); |
|
936 test.Printf(_L("This builds a database with four service records\n")); |
|
937 test.Printf(_L("The first one (UUID 1103 WAP) containing protocol attribute value: L2CAP, 3; RFCOMM, 3\n")); |
|
938 test.Printf(_L("the second (UUID 1101) containing protocol attribute value: L2CAP, 3; RFCOMM, 1.\n")); |
|
939 test.Printf(_L("the third (UUID 1102 LANP) containing protocol attribute value: L2CAP, 3; RFCOMM, 2.\n")); |
|
940 test.Printf(_L("the forth (UUID 1103 WAP) containing protocol attribute value: L2CAP, 3; RFCOMM, 4.\n")); |
|
941 test.Printf(_L("The server then remains in listening mode\n")); |
|
942 test.Printf(_L("until the user of Test E types 'x'.\n\n\n\n")); |
|
943 |
|
944 TChar c; |
|
945 RSdp sdp; |
|
946 RSdpDatabase db; |
|
947 // User::After(5000000); |
|
948 TInt ret; |
|
949 LoadLDD_PDD(); |
|
950 |
|
951 ret = sdp.Connect(); |
|
952 if(ret!=KErrNone) |
|
953 { |
|
954 test.End(); |
|
955 return; |
|
956 } |
|
957 ret = db.Open(sdp); |
|
958 if(ret!=KErrNone) |
|
959 { |
|
960 test.End(); |
|
961 return; |
|
962 } |
|
963 |
|
964 TSdpServRecordHandle recHandle1; |
|
965 TSdpServRecordHandle recHandle2; |
|
966 TSdpServRecordHandle recHandle3; |
|
967 TSdpServRecordHandle recHandle4; |
|
968 |
|
969 test.Printf(_L("SDP server with record 0, type 'x' to continue.\n")); |
|
970 c = test.Getch(); |
|
971 while (c!='x' && c!='X') |
|
972 c = test.Getch(); |
|
973 |
|
974 recHandle3 = BuildWAPL(db, 3); |
|
975 test.Printf(_L("one WAP record, type 'x' to continue.\n\n")); |
|
976 c = test.Getch(); |
|
977 while (c!='x' && c!='X') |
|
978 c = test.Getch(); |
|
979 |
|
980 recHandle1 = BuildPagonisL(db,TUUID(TUint32(0x1101)), 1); |
|
981 test.Printf(_L("Pagonis record (0x1101), type 'x' to continue.\n")); |
|
982 c = test.Getch(); |
|
983 while (c!='x' && c!='X') |
|
984 c = test.Getch(); |
|
985 |
|
986 recHandle2 = BuildPagonisL(db,TUUID(TUint32(0x1102)), 2); |
|
987 test.Printf(_L("Pagonis record (0x1102), type 'x' to continue.\n")); |
|
988 c = test.Getch(); |
|
989 while (c!='x' && c!='X') |
|
990 c = test.Getch(); |
|
991 |
|
992 recHandle4 = BuildWAPL(db, 4); |
|
993 test.Printf(_L("one WAP record, type 'x' to continue.\n\n")); |
|
994 c = test.Getch(); |
|
995 while (c!='x' && c!='X') |
|
996 c = test.Getch(); |
|
997 |
|
998 |
|
999 test.Printf(_L("The database is now ready to test, type 'x' to exit.\n\n")); |
|
1000 c = test.Getch(); |
|
1001 while (c!='x' && c!='X') |
|
1002 c = test.Getch(); |
|
1003 db.DeleteRecordL(recHandle4); |
|
1004 db.DeleteRecordL(recHandle3); |
|
1005 db.DeleteRecordL(recHandle2); |
|
1006 db.DeleteRecordL(recHandle1); |
|
1007 db.Close(); |
|
1008 sdp.Close(); |
|
1009 |
|
1010 |
|
1011 test.End(); |
|
1012 } |
|
1013 |
|
1014 void WhichTest() |
|
1015 { |
|
1016 TChar c; |
|
1017 test.Printf(_L("\nwhich test? ")); |
|
1018 test.Printf(_L("\npress 0 for UUID 1101, 1102, 1103 ")); |
|
1019 test.Printf(_L("\npress 1 for UUID 1103, 1101, 1103, 1102 ")); |
|
1020 test.Printf(_L("\npress 2 for UUID 1103, 1101, 1102, 1103 ")); |
|
1021 c = test.Getch(); |
|
1022 switch (c) |
|
1023 { |
|
1024 case '0': |
|
1025 Test1(); |
|
1026 break; |
|
1027 case '1': |
|
1028 TestD(); |
|
1029 break; |
|
1030 case '2': |
|
1031 TestE(); |
|
1032 break; |
|
1033 default: |
|
1034 break; |
|
1035 } |
|
1036 } |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 void Test2() |
|
1044 /** |
|
1045 Builds up a static DB, and prints it, |
|
1046 using the record and attribute iteraotrs, and a |
|
1047 simple console-printing attribute value visitor. |
|
1048 **/ |
|
1049 { |
|
1050 //FIXME: TRAPD? |
|
1051 test.Start(_L("Test 2 -- Build and print Db")); |
|
1052 // CSdpDatabase *theDb = BuildDbL(); |
|
1053 CSdpDatabase *theDb = BuildUpf4DbL(); |
|
1054 test(theDb!=NULL); |
|
1055 PrintDb(*theDb, *test.Console()); |
|
1056 delete theDb; |
|
1057 |
|
1058 test.End(); |
|
1059 } |
|
1060 |
|
1061 void Test3() |
|
1062 /** |
|
1063 Builds up a static DB, and copies it into the RSdpDatabase |
|
1064 **/ |
|
1065 { |
|
1066 //FIXME: TRAPD? |
|
1067 test.Start(_L("Test 3 -- Build and print Db")); |
|
1068 // CSdpDatabase *theDb = BuildDbL(); |
|
1069 CSdpDatabase *theDb = BuildUpf4DbL(); |
|
1070 test(theDb!=NULL); |
|
1071 CleanupStack::PushL(theDb); |
|
1072 |
|
1073 RSdp sdp; |
|
1074 RSdpDatabase db; |
|
1075 TInt ret; |
|
1076 LoadLDD_PDD(); |
|
1077 |
|
1078 test.Next(_L("Opening SDP Database")); |
|
1079 ret = sdp.Connect(); |
|
1080 test(ret==KErrNone); |
|
1081 CleanupClosePushL(sdp); |
|
1082 ret = db.Open(sdp); |
|
1083 test(ret==KErrNone); |
|
1084 CleanupClosePushL(db); |
|
1085 |
|
1086 test.Next(_L("Storing database")); |
|
1087 RegisterDatabaseInServerL(db, *theDb); |
|
1088 |
|
1089 test.Next(_L("Database stored. Now run your tests! Press any key to close SDDB")); |
|
1090 test.Getch(); |
|
1091 |
|
1092 CleanupStack::PopAndDestroy(3); // db, sdp, theDb |
|
1093 |
|
1094 test.End(); |
|
1095 } |
|
1096 |
|
1097 |
|
1098 void Test4() |
|
1099 /** |
|
1100 Builds a static DB and searches it for a |
|
1101 UUID search pattern (as per SDP service search |
|
1102 requests) |
|
1103 **/ |
|
1104 { |
|
1105 test.Start(_L("Test 2 -- Service search over Db")); |
|
1106 CSdpDatabase *theDb = BuildDbL(); |
|
1107 |
|
1108 CSdpSearchPattern* thePattern = CSdpSearchPattern::NewL(); |
|
1109 //Service pattern with one UUID in it... |
|
1110 test.Next(_L("Doing un-encoded tests")); |
|
1111 test.Next(_L("Searching for SDP server service UUID (0x1000)")); |
|
1112 thePattern->AddL(TUUID(TUint16(0x1000))); |
|
1113 SearchDbL(*theDb, *thePattern, 2); // Expect 2 matches |
|
1114 |
|
1115 test.Next(_L("Searching for SDP server service and bogoid UUID")); |
|
1116 thePattern->AddL(TUUID(TUint32(0x55667788))); |
|
1117 SearchDbL(*theDb, *thePattern, 1); // Expect 1 matches |
|
1118 |
|
1119 test.Next(_L("Searching for SDP server service and two bogoid UUID")); |
|
1120 thePattern->AddL(TUUID(TUint32(0x11112222))); |
|
1121 SearchDbL(*theDb, *thePattern, 0); // Expect 0 matches |
|
1122 |
|
1123 test.Next(_L("Searching for RFCOMM uuid")); |
|
1124 thePattern->Reset(); |
|
1125 thePattern->AddL(TUUID(TUint16(0x0003))); |
|
1126 SearchDbL(*theDb, *thePattern, 1); // Expect 1 matches |
|
1127 |
|
1128 |
|
1129 thePattern->Reset(); |
|
1130 |
|
1131 theDb->EncodeDbL(); |
|
1132 |
|
1133 test.Next(_L("Doing encoded tests")); |
|
1134 test.Next(_L("Searching for SDP server service UUID (0x1000)")); |
|
1135 thePattern->AddL(TUUID(TUint16(0x1000))); |
|
1136 SearchDbL(*theDb, *thePattern, 2); // Expect 2 matches |
|
1137 |
|
1138 test.Next(_L("Searching for SDP server service and bogoid UUID")); |
|
1139 thePattern->AddL(TUUID(TUint32(0x55667788))); |
|
1140 SearchDbL(*theDb, *thePattern, 1); // Expect 1 matches |
|
1141 |
|
1142 test.Next(_L("Searching for SDP server service and two bogoid UUID")); |
|
1143 thePattern->AddL(TUUID(TUint32(0x11112222))); |
|
1144 SearchDbL(*theDb, *thePattern, 0); // Expect 0 matches |
|
1145 |
|
1146 test.Next(_L("Searching for RFCOMM uuid")); |
|
1147 thePattern->Reset(); |
|
1148 thePattern->AddL(TUUID(TUint16(0x0003))); |
|
1149 SearchDbL(*theDb, *thePattern, 1); // Expect 1 matches |
|
1150 |
|
1151 |
|
1152 |
|
1153 delete thePattern; |
|
1154 delete theDb; |
|
1155 test.End(); |
|
1156 } |
|
1157 |
|
1158 void TestEncoder(TInt aType, CSdpDatabase *aDb) |
|
1159 { |
|
1160 TInt64 seed = aType * 49; |
|
1161 |
|
1162 test.Start(_L("Test 3 -- Encoder & Parser")); |
|
1163 CSdpDatabase *builtDb = CSdpDatabase::NewL(); |
|
1164 |
|
1165 HBufC8* outbuf = HBufC8::New(1024); |
|
1166 TPtr8 writePtr (outbuf->Des()); |
|
1167 TElementEncoder theEncoder(writePtr); |
|
1168 CElementParser* theParser = CElementParser::NewL(0); |
|
1169 CSdpAttrIdMatchList *theAttrList = CSdpAttrIdMatchList::NewL(); |
|
1170 |
|
1171 theAttrList->AddL(KAttrRangeAll); |
|
1172 |
|
1173 test.Next(_L("Encode and parse ref DB")); |
|
1174 { |
|
1175 for(TServRecordIter recIter(aDb->RecordIter()); recIter; recIter++) |
|
1176 {// Iterate thru records in Db |
|
1177 TInt startPos = writePtr.Length(); |
|
1178 CAttrExtractVisitor::EncodeAttributesL(theEncoder, *recIter, *theAttrList); |
|
1179 // grows writePtr |
|
1180 |
|
1181 CSdpServRecord* builtRec = CSdpServRecord::NewL(); |
|
1182 theParser->Reset(builtRec); |
|
1183 TInt incr = 1; |
|
1184 TBool moreExpected = ETrue; |
|
1185 for (TInt i = startPos; i < writePtr.Length(); i += incr) |
|
1186 {// parse it back, in inreasing chunks |
|
1187 switch(aType) |
|
1188 { |
|
1189 case 0: |
|
1190 incr += 1; |
|
1191 break; |
|
1192 case 1: |
|
1193 incr <<= 1; |
|
1194 break; |
|
1195 case 2: |
|
1196 default: |
|
1197 incr = Math::Rand(seed) % (i+2); |
|
1198 } |
|
1199 incr=Min(incr, writePtr.Length() - i); |
|
1200 moreExpected = theParser->BufferedParseL(writePtr.Mid(i, incr)); |
|
1201 } |
|
1202 test(!moreExpected); |
|
1203 builtDb->AddRecord(builtRec); |
|
1204 } |
|
1205 } |
|
1206 |
|
1207 HBufC8* outbuf2 = HBufC8::New(outbuf->Size()); |
|
1208 writePtr.Set (outbuf2->Des()); |
|
1209 |
|
1210 test.Next(_L("Re-Encode the DB built from parser")); |
|
1211 { |
|
1212 for(TServRecordIter recIter(builtDb->RecordIter()); recIter; recIter++) |
|
1213 {// Iterate thru records in Db |
|
1214 CAttrExtractVisitor::EncodeAttributesL(theEncoder, *recIter, *theAttrList); |
|
1215 } |
|
1216 } |
|
1217 |
|
1218 // test(*outbuf == *outbuf2); |
|
1219 |
|
1220 // The bit below is equivalent to the above line, only easier to debug |
|
1221 test(outbuf->Length() == outbuf2->Length()); |
|
1222 for (TInt i = 0; i < outbuf->Length(); ++i) |
|
1223 { |
|
1224 test((*outbuf)[i] == (*outbuf2)[i]); |
|
1225 } |
|
1226 |
|
1227 delete outbuf; |
|
1228 delete outbuf2; |
|
1229 delete theParser; |
|
1230 delete theAttrList; |
|
1231 delete builtDb; |
|
1232 test.End(); |
|
1233 } |
|
1234 |
|
1235 |
|
1236 void Test5() |
|
1237 { |
|
1238 for (TInt i = 0; i < 8; ++i) |
|
1239 { |
|
1240 test.Next(_L("Doing tests with ref Db")); |
|
1241 CSdpDatabase *theDb = BuildDbL(); |
|
1242 TestEncoder(i, theDb); |
|
1243 delete theDb; |
|
1244 |
|
1245 test.Next(_L("Doing tests with UPF4 Db")); |
|
1246 theDb = BuildUpf4DbL(); |
|
1247 TestEncoder(i, theDb); |
|
1248 delete theDb; |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 void Test6() |
|
1253 { |
|
1254 test.Start(_L("Test 6 -- Database size and encoding stuff")); |
|
1255 CSdpDatabase *theDb = BuildDbL(); |
|
1256 |
|
1257 const TUint KExpectedSizes[] = |
|
1258 { |
|
1259 5, 5, 12, 28, |
|
1260 14, 5, 5, 22, |
|
1261 23, 35, 5, 10, |
|
1262 3, 15, 19, |
|
1263 }; |
|
1264 test.Next(_L("Testing the size functions")); |
|
1265 TInt ind = 0; |
|
1266 for(TServRecordIter recIter(theDb->RecordIter()); recIter; recIter++) |
|
1267 {// Iterate thru records in Db |
|
1268 for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
1269 {// Iterate thru attributes in record |
|
1270 TUint size = TElementEncoder::EncodedSize((*attrIter).Value().Type(), (*attrIter).Value().DataSize()); |
|
1271 test.Printf(_L("Attribute value Encoded size is %d\n"), size); |
|
1272 test(size == KExpectedSizes[ind]); |
|
1273 ++ind; |
|
1274 } |
|
1275 } |
|
1276 |
|
1277 delete theDb; |
|
1278 |
|
1279 test.Next(_L("Testing attribute match list stuff")); |
|
1280 CSdpAttrIdMatchList *theAttrList = CSdpAttrIdMatchList::NewL(); |
|
1281 |
|
1282 theAttrList->AddL(TAttrRange(10, 15)); // insert at beginning -> 10-15 |
|
1283 theAttrList->AddL(TAttrRange(30, 40)); // insert at end -> 10-15,30-40 |
|
1284 theAttrList->AddL(TAttrRange(18, 19)); // insert between 2 -> 10-15, 18-19, 30-40 |
|
1285 theAttrList->AddL(TAttrRange(27, 29)); // append to start of another range -> 10-15, 18-19, 27-40 |
|
1286 theAttrList->AddL(TAttrRange(41, 45)); // append to end of another range -> 10-15, 18-19, 27-45 |
|
1287 theAttrList->AddL(TAttrRange(16, 17)); // join 2 ranges together -> 10-19, 27-45 |
|
1288 theAttrList->AddL(TAttrRange(21, 24)); // insert between 2 -> 10-19, 21-24, 27-45 |
|
1289 test(theAttrList->Count() == 3); |
|
1290 |
|
1291 TInt posn; |
|
1292 test(theAttrList->InMatchListRange(10, posn)); |
|
1293 test(theAttrList->InMatchListRange(11, posn)); |
|
1294 test(theAttrList->InMatchListRange(15, posn)); |
|
1295 |
|
1296 test(theAttrList->InMatchListRange(21, posn)); |
|
1297 test(theAttrList->InMatchListRange(22, posn)); |
|
1298 test(theAttrList->InMatchListRange(23, posn)); |
|
1299 test(theAttrList->InMatchListRange(24, posn)); |
|
1300 |
|
1301 test(theAttrList->InMatchListRange(45, posn)); |
|
1302 |
|
1303 theAttrList->RemoveL(TAttrRange(12, 14)); // mid-range -> 10-11, 15-19, 21-24, 27-45 |
|
1304 test(theAttrList->Count() == 4); |
|
1305 |
|
1306 theAttrList->RemoveL(TAttrRange(12, 14)); // no change -> 10-11, 15-19, 21-24, 27-45 |
|
1307 theAttrList->RemoveL(TAttrRange(14, 16)); // overlap start -> 10-11, 17-19, 21-24, 27-45 |
|
1308 test(theAttrList->Count() == 4); |
|
1309 theAttrList->RemoveL(TAttrRange(17, 20)); // remove one item -> 10-11, 21-24, 27-45 |
|
1310 theAttrList->RemoveL(TAttrRange(40, 45)); // end of range -> 10-11, 21-24, 27-39 |
|
1311 theAttrList->RemoveL(TAttrRange(28, 28)); // range of one -> 10-11, 21-24, 27, 29-39 |
|
1312 test(theAttrList->Count() == 4); |
|
1313 test(theAttrList->InMatchList(27)); |
|
1314 theAttrList->RemoveL(TAttrRange(26, 28)); // remove range of one -> 10-11, 21-24, 29-39 |
|
1315 test(theAttrList->Count() == 3); |
|
1316 |
|
1317 theAttrList->AddL(TAttrRange(15, 15)); // insert between 2 -> 10-11, 15, 21-24, 29-39 |
|
1318 theAttrList->AddL(TAttrRange(17, 18)); // insert between 2 -> 10-11, 15, 17-18, 21-24, 29-39 |
|
1319 test(theAttrList->Count() == 5); |
|
1320 theAttrList->AddL(TAttrRange(13, 26)); // obliterate 3 with one big insertion -> 10-11, 13-26, 29-39 |
|
1321 test(theAttrList->Count() == 3); |
|
1322 theAttrList->RemoveL(TAttrRange(15, 17)); //-> 10-11, 13-14, 18-26, 29-39 |
|
1323 theAttrList->RemoveL(TAttrRange(19, 21)); //-> 10-11, 13-14, 18, 22-26, 29-39 |
|
1324 theAttrList->RemoveL(TAttrRange(23, 24)); //-> 10-11, 13-14, 18, 22, 25-26, 29-39 |
|
1325 test(theAttrList->Count() == 6); |
|
1326 theAttrList->AddL(TAttrRange(16, 28)); // obliterate 3 with one big deletion -> 10-11, 13-14, 29-39 |
|
1327 test(theAttrList->Count() == 3); |
|
1328 |
|
1329 theAttrList->RemoveL(TAttrRange(31, 31)); //-> 10-11, 13-14, 29-30 32-39 |
|
1330 test(theAttrList->Count() == 4); |
|
1331 theAttrList->AddL(TAttrRange(28, 31)); // new range contiguous with 2 current ranges -> 10-11, 13-14, 28-39 |
|
1332 test(theAttrList->Count() == 3); |
|
1333 |
|
1334 theAttrList->RemoveL(TAttrRange(0, 45)); // remove all entries |
|
1335 |
|
1336 theAttrList->AddL(TAttrRange(50, 300)); // 50-300 |
|
1337 |
|
1338 test(theAttrList->InMatchList(50)); |
|
1339 test(theAttrList->InMatchList(256)); |
|
1340 test(theAttrList->InMatchList(300)); |
|
1341 |
|
1342 test(theAttrList->InMatchList(301) == EFalse); |
|
1343 test(theAttrList->InMatchList(49) == EFalse); |
|
1344 |
|
1345 theAttrList->AddL(TAttrRange(302, 304)); // 50-300, 302-304 |
|
1346 test(theAttrList->Count() == 2); |
|
1347 |
|
1348 theAttrList->AddL(TAttrRange(50, 50)); |
|
1349 test(theAttrList->Count() == 2); |
|
1350 |
|
1351 theAttrList->AddL(TAttrRange(45, 310)); // 45-310 |
|
1352 test(theAttrList->Count() == 1); |
|
1353 test(theAttrList->InMatchList(45)); |
|
1354 test(theAttrList->InMatchList(310)); |
|
1355 test(theAttrList->InMatchList(311) == EFalse); |
|
1356 test(theAttrList->InMatchList(44) == EFalse); |
|
1357 |
|
1358 theAttrList->AddL(TAttrRange(45, 200)); // 45-310 |
|
1359 test(theAttrList->Count() == 1); |
|
1360 |
|
1361 theAttrList->RemoveL(TAttrRange(50, 60)); // 45-49 61-310 |
|
1362 test(theAttrList->Count() == 2); |
|
1363 test(theAttrList->InMatchList(49)); |
|
1364 test(theAttrList->InMatchList(50) == EFalse); |
|
1365 test(theAttrList->InMatchList(60) == EFalse); |
|
1366 test(theAttrList->InMatchList(61)); |
|
1367 test(theAttrList->InMatchList(45)); |
|
1368 test(theAttrList->InMatchList(310)); |
|
1369 test(theAttrList->InMatchList(311) == EFalse); |
|
1370 |
|
1371 theAttrList->RemoveL(TAttrRange(55, 65)); // 45-49 66-310 |
|
1372 test(theAttrList->Count() == 2); |
|
1373 test(theAttrList->InMatchList(66)); |
|
1374 test(theAttrList->InMatchList(65) == EFalse); |
|
1375 |
|
1376 theAttrList->RemoveL(TAttrRange(55, 55)); |
|
1377 test(theAttrList->Count() == 2); |
|
1378 theAttrList->RemoveL(TAttrRange(1, 2)); |
|
1379 theAttrList->RemoveL(TAttrRange(400, 500)); |
|
1380 test(theAttrList->Count() == 2); |
|
1381 |
|
1382 theAttrList->RemoveL(TAttrRange(40, 70)); // 71-310 |
|
1383 test(theAttrList->Count() == 1); |
|
1384 |
|
1385 theAttrList->AddL(TAttrRange(5, 39)); // 5-39, 71-310 |
|
1386 test(theAttrList->Count() == 2); |
|
1387 |
|
1388 theAttrList->RemoveL(TAttrRange(38, 38)); // 5-37, 39, 71-310 |
|
1389 test(theAttrList->Count() == 3); |
|
1390 theAttrList->RemoveL(TAttrRange(36, 36)); // 5-35, 37, 39, 71-310 |
|
1391 test(theAttrList->Count() == 4); |
|
1392 |
|
1393 theAttrList->RemoveL(TAttrRange(30, 70)); // 5-29, 71-310 |
|
1394 test(theAttrList->Count() == 2); |
|
1395 |
|
1396 theAttrList->RemoveL(TAttrRange(1, 309)); // 310 |
|
1397 test(theAttrList->Count() == 1); |
|
1398 test(theAttrList->InMatchList(310)); |
|
1399 test(theAttrList->InMatchList(309) == EFalse); |
|
1400 test(theAttrList->InMatchList(311) == EFalse); |
|
1401 |
|
1402 theAttrList->RemoveL(TAttrRange(1, 310)); // none |
|
1403 test(theAttrList->Count() == 0); |
|
1404 |
|
1405 |
|
1406 theAttrList->AddL(TAttrRange(45, 310)); // 45-310 |
|
1407 test(theAttrList->Count() == 1); |
|
1408 |
|
1409 theAttrList->AddL(TAttrRange(2000)); // 45-310, 2000 |
|
1410 test(theAttrList->Count() == 2); |
|
1411 test(theAttrList->InMatchList(2000)); |
|
1412 test(theAttrList->InMatchList(2001) == EFalse); |
|
1413 |
|
1414 theAttrList->AddL(TAttrRange(2002)); // 45-310, 2000, 2002 |
|
1415 test(theAttrList->Count() == 3); |
|
1416 |
|
1417 theAttrList->AddL(TAttrRange(2004)); // 45-310, 2000, 2002, 2004 |
|
1418 test(theAttrList->Count() == 4); |
|
1419 test(theAttrList->InMatchList(2004)); |
|
1420 test(theAttrList->InMatchList(2003) == EFalse); |
|
1421 |
|
1422 theAttrList->AddL(TAttrRange(2003)); // 45-310, 2000, 2002-2004 |
|
1423 test(theAttrList->Count() == 3); |
|
1424 |
|
1425 theAttrList->AddL(TAttrRange(301, 2001)); // 45-2004 |
|
1426 test(theAttrList->Count() == 1); |
|
1427 test(theAttrList->InMatchList(45)); |
|
1428 test(theAttrList->InMatchList(2004)); |
|
1429 test(theAttrList->InMatchList(0) == EFalse); |
|
1430 test(theAttrList->InMatchList(2010) == EFalse); |
|
1431 |
|
1432 TInt count = theAttrList->Count(); |
|
1433 for (TUint16 i = 3000; i < 4000; i += 2) |
|
1434 { |
|
1435 theAttrList->AddL(TAttrRange(i, i)); |
|
1436 ++count; |
|
1437 test(theAttrList->Count() == count); |
|
1438 test(theAttrList->InMatchList(i)); |
|
1439 test(theAttrList->InMatchList(TUint16(i-1)) == EFalse); |
|
1440 test(theAttrList->InMatchList(TUint16(i+1)) == EFalse); |
|
1441 } |
|
1442 |
|
1443 for (TUint16 j = 3001; j < 3501; j += 2) |
|
1444 { |
|
1445 theAttrList->AddL(TAttrRange(j, j)); |
|
1446 --count; |
|
1447 test(theAttrList->Count() == count); |
|
1448 test(theAttrList->InMatchList(j)); |
|
1449 test(theAttrList->InMatchList(TUint16(j-1))); |
|
1450 test(theAttrList->InMatchList(TUint16(j+1))); |
|
1451 } |
|
1452 |
|
1453 for (TUint16 k = 3001; k < 3400; k += 2) |
|
1454 { |
|
1455 theAttrList->RemoveL(TAttrRange(k, k)); |
|
1456 ++count; |
|
1457 test(theAttrList->Count() == count); |
|
1458 test(theAttrList->InMatchList(k) == EFalse); |
|
1459 test(theAttrList->InMatchList(TUint16(k-1))); |
|
1460 test(theAttrList->InMatchList(TUint16(k+1))); |
|
1461 } |
|
1462 |
|
1463 theAttrList->AddL(TAttrRange(0, 5000)); |
|
1464 test(theAttrList->Count() == 1); |
|
1465 test(theAttrList->InMatchList(0)); |
|
1466 test(theAttrList->InMatchList(5000)); |
|
1467 test(theAttrList->InMatchList(5001) == EFalse); |
|
1468 test(theAttrList->InMatchList(KMaxTUint16) == EFalse); |
|
1469 |
|
1470 theAttrList->RemoveL(TAttrRange(0, 5000)); |
|
1471 test(theAttrList->Count() == 0); |
|
1472 |
|
1473 delete theAttrList; |
|
1474 |
|
1475 test.End(); |
|
1476 |
|
1477 } |
|
1478 |
|
1479 /* moved out to the database dll as a utility method |
|
1480 CSdpDatabase * EncodeDb(CSdpDatabase * nonEncodedDb) |
|
1481 { |
|
1482 CSdpDatabase *encDb = CSdpDatabase::NewL(); |
|
1483 |
|
1484 TUint8 outbuf[72]; |
|
1485 TPtr8 writePtr (outbuf, 0, 72); |
|
1486 CSdpServRecord *theRec = CSdpServRecord::NewL(); |
|
1487 TElementEncoder theEncoder(writePtr); |
|
1488 |
|
1489 test.Next(_L("Test attribute encoder")); |
|
1490 for(TServRecordIter recIter(nonEncodedDb->RecordIter()); recIter; recIter++) |
|
1491 {// Iterate through records in Db |
|
1492 |
|
1493 for (TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
1494 {// iterate through attributes in record |
|
1495 writePtr.Set(outbuf, 0, 72); // bug, just declaring this (see above) didn't reset the pointer on each loop |
|
1496 |
|
1497 CAttrEncoderVisitor::EncodeAttributeL(theEncoder, (*attrIter).Value()); |
|
1498 TBuf8<sizeof(TUint)> val(2); |
|
1499 TElementEncoder::PutUint(&val[0], (*attrIter).AttributeID(), 2); |
|
1500 test.Printf(_L("AttrID:0x%02x%02x, <"), val[0], val[1]); |
|
1501 HexDes(writePtr); |
|
1502 test.Printf(_L(">\n")); |
|
1503 theRec->BuildUintL(val)->BuildEncodedL(writePtr); |
|
1504 } |
|
1505 encDb->AddRecord(theRec); |
|
1506 theRec = CSdpServRecord::NewL(); // need a new one |
|
1507 } |
|
1508 delete theRec; |
|
1509 return encDb; |
|
1510 } |
|
1511 */ |
|
1512 |
|
1513 // build an encoded version of the database then print it. |
|
1514 void Test7() |
|
1515 { |
|
1516 test.Start(_L("Test 7 -- Encoded database")); |
|
1517 CSdpDatabase *theDb = BuildUpf4DbL(); |
|
1518 theDb->EncodeDbL(); |
|
1519 |
|
1520 test.Next(_L("Print encoded attributes")); |
|
1521 PrintDb(*theDb, *test.Console()); |
|
1522 |
|
1523 delete theDb; |
|
1524 test.End(); |
|
1525 } |
|
1526 |
|
1527 // test the access routines. |
|
1528 void ShowCollected( CSizeAccumulator* aCollector) |
|
1529 { |
|
1530 __UHEAP_MARK; |
|
1531 CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(*test.Console()); |
|
1532 TInt indRec, indAtt; |
|
1533 TUint leftOver; |
|
1534 TInt startSize = 0; |
|
1535 TInt nextLeft; |
|
1536 TInt nextSize; |
|
1537 TBool succ = EFalse; |
|
1538 TInt orig = aCollector->SizeLeft(); |
|
1539 TInt hcount = aCollector->HandleCount(); |
|
1540 test.Printf(_L("Size:%d, handles %d\n"), orig, hcount); |
|
1541 for (TInt i = 0; i<hcount; i++) |
|
1542 { |
|
1543 TSdpServRecordHandle hhand = aCollector->HandleAt(i); |
|
1544 TInt atcount = aCollector->AttrCount(i); |
|
1545 test.Printf(_L("HandleID:%x, attrib count:%d\n"), hhand, atcount); |
|
1546 for (TInt j = 0; j<atcount; j++) |
|
1547 { |
|
1548 CAttrSizeItem* atpointer = aCollector->AttributeOf(i, j); |
|
1549 test.Printf(_L("Attribute Pointer:%x\n"), atpointer); |
|
1550 test.Printf(_L("Attr:")); |
|
1551 // HexDes(atpointer->Attr()->Value().Des()); |
|
1552 // just in case we get a non-encoded attribute |
|
1553 theVisitor->VisitAttributeL(*atpointer->Attr()); |
|
1554 theVisitor->VisitAttributeValueL(atpointer->Attr()->Value(), atpointer->Attr()->Value().Type()); |
|
1555 test.Printf(_L("\n")); |
|
1556 nextSize = atpointer->Size(); |
|
1557 startSize += nextSize; |
|
1558 startSize += 3; // the header size... |
|
1559 indRec = 0; |
|
1560 indAtt = 0; |
|
1561 leftOver = 0; |
|
1562 succ = aCollector->StartAt(startSize, leftOver, indRec, indAtt); |
|
1563 if (succ) |
|
1564 { |
|
1565 nextLeft = aCollector->SizeLeft(); |
|
1566 test.Printf(_L("updated start point by (%d+3) from %d to %d\n"), nextSize, orig, nextLeft); |
|
1567 test.Printf(_L("indices are L:%d, R:%d, A:%d\n"),leftOver, indRec, indAtt); |
|
1568 orig = nextLeft; |
|
1569 } |
|
1570 else |
|
1571 test.Printf(_L("failed to update start point by %d from %d\n"), nextSize, orig); |
|
1572 |
|
1573 |
|
1574 } |
|
1575 } |
|
1576 delete theVisitor; |
|
1577 __UHEAP_MARKEND; |
|
1578 test.Getch(); |
|
1579 } |
|
1580 |
|
1581 void Test8() |
|
1582 { |
|
1583 __UHEAP_MARK; |
|
1584 test.Start(_L("Test 8 -- Size visitor")); |
|
1585 CSdpDatabase *theDb = BuildUpf4DbL(); |
|
1586 theDb->EncodeDbL(); |
|
1587 |
|
1588 // test.Next(_L("Testing sizes of records")); |
|
1589 CSdpAttrIdMatchList *theAttrList = CSdpAttrIdMatchList::NewL(); |
|
1590 |
|
1591 theAttrList->AddL(TAttrRange(4)); // protocol descriptor list |
|
1592 |
|
1593 theAttrList->AddL(TAttrRange(50, 300)); // mostly text based stuff |
|
1594 |
|
1595 CSdpSearchPattern* thePattern = CSdpSearchPattern::NewL(); |
|
1596 //Service pattern with one UUID in it... |
|
1597 thePattern->AddL(TUUID(TUint16(0x1103))); |
|
1598 CSizeAccumulator* collector = CSizeAccumulator::NewL(); |
|
1599 test.Next(_L("Testing for UUID 1103\n")); |
|
1600 CResponseSizeVisitor::SizeRespSSL(*theDb, *thePattern, *collector); |
|
1601 ShowCollected(collector); |
|
1602 // Iterate thru records in Db for SizeRespARL |
|
1603 test.Next(_L("Testing for attr 4, 50-300\n")); |
|
1604 for(TServRecordIter recIter(theDb->RecordIter()); recIter; recIter++) |
|
1605 { |
|
1606 test.Printf(_L("\n...Sizing Record 0x%x\n"), (*recIter).Handle()); |
|
1607 delete collector; |
|
1608 collector = CSizeAccumulator::NewL(); |
|
1609 CResponseSizeVisitor::SizeRespARL((*recIter), *theAttrList, *collector); // what does it do if the collectors been used ? |
|
1610 ShowCollected(collector); |
|
1611 } |
|
1612 // |
|
1613 test.Next(_L("Testing for attr 100\n")); |
|
1614 delete theAttrList; |
|
1615 theAttrList = CSdpAttrIdMatchList::NewL(); |
|
1616 theAttrList->AddL(TAttrRange(0x0100)); // names |
|
1617 delete thePattern; |
|
1618 thePattern = CSdpSearchPattern::NewL(); |
|
1619 //Service pattern with one UUID in it... |
|
1620 thePattern->AddL(TUUID(TUint16(0x1002))); |
|
1621 delete collector; |
|
1622 collector = CSizeAccumulator::NewL(); |
|
1623 CResponseSizeVisitor::SizeRespSAL(*theDb, *thePattern, *theAttrList, *collector); |
|
1624 ShowCollected(collector); |
|
1625 delete collector; |
|
1626 delete theAttrList; |
|
1627 delete thePattern; |
|
1628 delete theDb; |
|
1629 __UHEAP_MARKEND; |
|
1630 test.End(); |
|
1631 } |
|
1632 |
|
1633 |
|
1634 void Test9(TInt flag) |
|
1635 { |
|
1636 CSdpDatabase *theDb; |
|
1637 __UHEAP_MARK; |
|
1638 TChar c = 'c'; |
|
1639 if(!flag) |
|
1640 { |
|
1641 c = test.Getch(); |
|
1642 switch (c) |
|
1643 { |
|
1644 case 'A': case 'a': |
|
1645 test.Start(_L("Test 9 -- \"Rhubarb\" Continuation")); |
|
1646 //FIXME: TRAPD? |
|
1647 theDb = BuildContinuationDbL(); |
|
1648 break; |
|
1649 case 'B': case 'b': |
|
1650 test.Start(_L("Test 9 -- Continuation with Nested Lists")); |
|
1651 //FIXME: TRAPD? |
|
1652 theDb = BuildNestedListDbL(); |
|
1653 break; |
|
1654 default: |
|
1655 return; |
|
1656 } |
|
1657 } |
|
1658 else |
|
1659 { |
|
1660 test.Start(_L("Test 9 -- Prequal Database")); |
|
1661 //FIXME: TRAPD? |
|
1662 theDb = BuildPrequalDbL(); |
|
1663 } |
|
1664 |
|
1665 test(theDb!=NULL); |
|
1666 CleanupStack::PushL(theDb); |
|
1667 TServRecordIter recIter(theDb->RecordIter()); |
|
1668 TServAttrIter attrIter((*recIter).AttributeIter()); |
|
1669 TServAttrIter attrIter2((*recIter).AttributeIter()); |
|
1670 for(; recIter; recIter++) |
|
1671 {// Iterate thru records in Db |
|
1672 attrIter = (*recIter).AttributeIter(); |
|
1673 for(; attrIter; attrIter++) |
|
1674 {// Iterate thru attributes in record |
|
1675 if((*attrIter).Value().Type()==ETypeString) |
|
1676 { |
|
1677 TPtrC8 ptr((*attrIter).Value().Des()); |
|
1678 if(ptr.Length()<0x100) |
|
1679 { |
|
1680 attrIter2 = attrIter; |
|
1681 } |
|
1682 } |
|
1683 } |
|
1684 } |
|
1685 if((*attrIter2).Value().Type()==ETypeString) |
|
1686 { |
|
1687 TPtrC8 ptr1((*attrIter2).Value().Des()); |
|
1688 TBuf16<0x100> ptr(0); |
|
1689 for(TInt i = 0;i<ptr1.Length()&&i<(ptr.MaxLength()-3);++i) |
|
1690 ptr.Append(ptr1[i]); |
|
1691 if(c=='a'||c=='A') |
|
1692 { |
|
1693 test.Printf(_L("Id: %d\n"),(*attrIter2).AttributeID()); |
|
1694 test.Printf(_L("String length: %d\n"),ptr.Length()); |
|
1695 if(ptr.Length()<0x100) |
|
1696 test.Printf(_L("%s\n"),&ptr[0]); |
|
1697 } |
|
1698 } |
|
1699 |
|
1700 RSdp sdp; |
|
1701 RSdpDatabase db; |
|
1702 TInt ret; |
|
1703 LoadLDD_PDD(); |
|
1704 |
|
1705 test.Next(_L("Opening SDP Database")); |
|
1706 ret = sdp.Connect(); |
|
1707 if(ret!=KErrNone) |
|
1708 { |
|
1709 if(ret==KErrNotFound) |
|
1710 test.Printf(_L("Cannot start sdp server, could not find bluetooth.\n")); |
|
1711 else |
|
1712 test.Printf(_L("Cannot start sdp server.\n")); |
|
1713 test.Next(_L("PRESS ANY KEY.\n")); |
|
1714 test.Getch(); |
|
1715 |
|
1716 CleanupStack::PopAndDestroy(); // theDb |
|
1717 goto end; |
|
1718 } |
|
1719 test(ret==KErrNone); |
|
1720 CleanupClosePushL(sdp); |
|
1721 ret = db.Open(sdp); |
|
1722 test(ret==KErrNone); |
|
1723 CleanupClosePushL(db); |
|
1724 |
|
1725 test.Next(_L("Storing database")); |
|
1726 RegisterDatabaseInServerL(db, *theDb); |
|
1727 |
|
1728 test.Next(_L("Database stored. Now run your tests!")); |
|
1729 test.Next(_L("Press any key to close SDDB")); |
|
1730 test.Getch(); |
|
1731 |
|
1732 CleanupStack::PopAndDestroy(3); // db, sdp, theDb |
|
1733 end: |
|
1734 __UHEAP_MARKEND; |
|
1735 test.End(); |
|
1736 } |
|
1737 |
|
1738 void Test10() |
|
1739 { |
|
1740 __UHEAP_MARK; |
|
1741 //TUint32 |
|
1742 TInt64 putVal32 = static_cast<TInt64>(0xBA1EFACE); |
|
1743 TPckgBuf<TUint32> value32Packaged; |
|
1744 SdpUtil::PutUint(&value32Packaged[0], putVal32, 4); |
|
1745 |
|
1746 TUint32 getVal32= SdpUtil::GetUint(value32Packaged); |
|
1747 test.Printf(_L("SdpUtil: TPckgBuf<TUint32> created with 0x%08lx would return 0x%x\n"), putVal32, getVal32); |
|
1748 |
|
1749 |
|
1750 TBuf8<32/8> testValue32Packaged; |
|
1751 testValue32Packaged.SetLength(4); |
|
1752 testValue32Packaged = value32Packaged; |
|
1753 |
|
1754 CSdpAttrValue* attrVal = 0; |
|
1755 attrVal = CSdpAttrValueUint::NewUintL(testValue32Packaged); |
|
1756 TUint getter = attrVal->Uint(); |
|
1757 delete attrVal; |
|
1758 |
|
1759 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%08lx returns 0x%x\n"), putVal32, getter); |
|
1760 |
|
1761 |
|
1762 // Now we have confirmed that exercising SdpUtil this way is equivalent to using CSdpAttrValueUint's methods. |
|
1763 // The CSdpAttrValueUint::Uint64 and CSdpAttrValueUint::Uint128 methods are now exported so we can test them, |
|
1764 // but they use SdpUtil too, so.. |
|
1765 |
|
1766 //TUint64 |
|
1767 // TPckgBuf<TUint64> putVal64Packaged =0x1234FACE5678ABCD; // Use this to test the full functionality |
|
1768 TPckgBuf<TUint64> putVal64Packaged =0x1234FACE; // This number is acceptable to the gcc_xml compiler |
|
1769 |
|
1770 TUint64 putVal64 = putVal64Packaged(); |
|
1771 |
|
1772 TPckgBuf<TUint64> val64Packaged; |
|
1773 SdpUtil::PutUint64(&val64Packaged[0], putVal64); |
|
1774 |
|
1775 TUint64 getVal64; |
|
1776 SdpUtil::GetUint64(val64Packaged, getVal64); |
|
1777 |
|
1778 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx would return 0x%lx\n"), putVal64, getVal64); |
|
1779 |
|
1780 TBuf8<64/8> testValue64Packaged; |
|
1781 testValue64Packaged.SetLength(8); |
|
1782 testValue64Packaged = val64Packaged; |
|
1783 |
|
1784 CSdpAttrValue* attrVal64 = 0; |
|
1785 attrVal64 = CSdpAttrValueUint::NewUintL(testValue64Packaged); |
|
1786 TUint size64 = attrVal64->DataSize(); |
|
1787 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx would be %d bytes long\n"), putVal64, size64); |
|
1788 |
|
1789 CSdpAttrValueUint& attrValueUint64 = static_cast<CSdpAttrValueUint&>(*attrVal64); |
|
1790 attrValueUint64.Uint64(getVal64); |
|
1791 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx would return 0x%lx\n"), putVal64, getVal64); |
|
1792 |
|
1793 delete attrVal64; |
|
1794 |
|
1795 |
|
1796 //two TUint64s |
|
1797 // TUint64 putLoVal = 0x1234FACE5678ABCD; // Use these to test the full functionality |
|
1798 // TUint64 putHiVal = 0x3456789BA1EFACED; |
|
1799 |
|
1800 TUint64 putLoVal = 0x1234FACE; // These numbers are acceptable to the gcc_xml compiler |
|
1801 TUint64 putHiVal = 0xBA1EACED; |
|
1802 |
|
1803 TBuf8<128/8> putValue128Packaged; |
|
1804 putValue128Packaged.SetLength(16); |
|
1805 |
|
1806 SdpUtil::PutUint128(&putValue128Packaged[0], putLoVal, putHiVal); |
|
1807 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx,0x%lx would be %d bytes long\n"), putHiVal, putLoVal, 16); |
|
1808 |
|
1809 TUint64 getLoVal128; |
|
1810 TUint64 getHiVal128; |
|
1811 SdpUtil::GetUint128(putValue128Packaged, getLoVal128, getHiVal128); |
|
1812 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx,0x%lx would return 0x%lx,0x%lx\n"), putHiVal, putLoVal, getHiVal128, getLoVal128); |
|
1813 |
|
1814 TBuf8<128/8> testValue128Packaged; |
|
1815 testValue128Packaged.SetLength(16); |
|
1816 testValue128Packaged = putValue128Packaged; |
|
1817 |
|
1818 CSdpAttrValue* attrVal128 = 0; |
|
1819 attrVal128 = CSdpAttrValueUint::NewUintL(testValue128Packaged); |
|
1820 TUint size128 = attrVal128->DataSize(); |
|
1821 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx,0x%lx would be %d bytes long\n"), putHiVal, putLoVal, size128); |
|
1822 |
|
1823 CSdpAttrValueUint& attrValueUint128 = static_cast<CSdpAttrValueUint&>(*attrVal128); |
|
1824 attrValueUint128.Uint128(getLoVal128, getHiVal128); |
|
1825 test.Printf(_L("SdpUtil: CSdpAttrValueUint created with 0x%lx,0x%lx would return 0x%lx,0x%lx\n"), putHiVal, putLoVal, getHiVal128, getLoVal128); |
|
1826 |
|
1827 delete attrVal128; |
|
1828 |
|
1829 __UHEAP_MARKEND; |
|
1830 |
|
1831 } |
|
1832 |
|
1833 void IntConversionTest() |
|
1834 /** |
|
1835 Checks compiler has done uint-int cast correctly |
|
1836 in CSdpAttrValueInt::Int(). |
|
1837 **/ |
|
1838 { |
|
1839 TBuf8<4> tstr; |
|
1840 tstr.FillZ(4); |
|
1841 tstr[0] = 0xff; |
|
1842 tstr[1] = 0xff; |
|
1843 tstr[2] = 0xff; |
|
1844 tstr[3] = 0xff; |
|
1845 TInt ret = 0; |
|
1846 CSdpAttrValueInt* avi = 0; |
|
1847 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
1848 ret = avi->Int(); |
|
1849 delete avi; |
|
1850 avi = 0; |
|
1851 __ASSERT_DEBUG(ret==-1, User::Panic(_L("Bad4ByteIntConversion"), KErrGeneral)); |
|
1852 tstr.SetLength(2); |
|
1853 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
1854 ret = avi->Int(); |
|
1855 delete avi; |
|
1856 avi = 0; |
|
1857 __ASSERT_DEBUG(ret==-1, User::Panic(_L("Bad2ByteIntConversion"), KErrGeneral)); |
|
1858 //tstr[0] = 0x0e; |
|
1859 tstr.SetLength(1); |
|
1860 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
1861 ret = avi->Int(); |
|
1862 delete avi; |
|
1863 avi = 0; |
|
1864 __ASSERT_DEBUG(ret==-1, User::Panic(_L("BadByteIntConversion"), KErrGeneral)); |
|
1865 |
|
1866 (void)(ret != 0); // keep compiler happy by referencing ret as an r-value in urel |
|
1867 |
|
1868 return; |
|
1869 } |
|
1870 |
|
1871 void RunAppL() |
|
1872 { |
|
1873 // TInt ret; |
|
1874 test.Title(); |
|
1875 test.Start(_L("Running SDP server tests")); |
|
1876 // For some reason, you have to do the following to |
|
1877 // ensure that the file server behaves properly. |
|
1878 RFs fs; |
|
1879 (void)fs.Connect(); |
|
1880 fs.Close(); |
|
1881 // Run through tests |
|
1882 IntConversionTest(); |
|
1883 FOREVER |
|
1884 { |
|
1885 test.Printf(_L("Choose the test to run...\n")); |
|
1886 test.Printf(_L("************************\n")); |
|
1887 test.Printf(_L("0. Run client/server\n")); |
|
1888 test.Printf(_L("1. Run client/server building the John Pagonis database\n")); |
|
1889 test.Printf(_L("2. Build static DB & print\n")); |
|
1890 test.Printf(_L("3. Build static DB & copy it over into the SDP database server\n")); |
|
1891 test.Printf(_L("4. Service Search (no continuation)\n")); |
|
1892 test.Printf(_L("5. Attribute Request (no continuation)\n")); |
|
1893 test.Printf(_L("6. Sizing and encoding stuff\n")); |
|
1894 test.Printf(_L("7. encoded database\n")); |
|
1895 test.Printf(_L("8. size visitor\n")); |
|
1896 test.Printf(_L("9a.(Press keys SLOWLY) Build \"Rhubarb\" continuation database\n")); |
|
1897 test.Printf(_L("9b.(Press keys SLOWLY) Build nested lists continuation database\n")); |
|
1898 test.Printf(_L("B. Run UPF back to back tests\n")); |
|
1899 test.Printf(_L("C. Continuation stress tests\n")); |
|
1900 // test.Printf(_L("U. Unplugfest tests\n")); |
|
1901 test.Printf(_L("P. Prequal tests database\n")); |
|
1902 test.Printf(_L("Q. SdpUtil tests\n")); |
|
1903 test.Printf(_L("\n")); |
|
1904 test.Printf(_L("A. Run All tests\n")); |
|
1905 test.Printf(_L("************************\n")); |
|
1906 test.Printf(_L("press Escape to quit\n\n")); |
|
1907 |
|
1908 __UHEAP_MARK; |
|
1909 TChar c = test.Getch(); |
|
1910 switch (c) |
|
1911 { |
|
1912 case 'A': case 'a': |
|
1913 Test1(); |
|
1914 __UHEAP_CHECK(0); |
|
1915 Test2(); |
|
1916 __UHEAP_CHECK(0); |
|
1917 Test3(); |
|
1918 __UHEAP_CHECK(0); |
|
1919 Test4(); |
|
1920 __UHEAP_CHECK(0); |
|
1921 Test5(); |
|
1922 __UHEAP_CHECK(0); |
|
1923 Test6(); |
|
1924 __UHEAP_CHECK(0); |
|
1925 break; |
|
1926 case '0': |
|
1927 Test0(); |
|
1928 break; |
|
1929 case '1': |
|
1930 WhichTest(); |
|
1931 break; |
|
1932 case '2': |
|
1933 Test2(); |
|
1934 break; |
|
1935 case '3': |
|
1936 Test3(); |
|
1937 break; |
|
1938 case '4': |
|
1939 Test4(); |
|
1940 break; |
|
1941 case '5': |
|
1942 Test5(); |
|
1943 break; |
|
1944 case '6': |
|
1945 Test6(); |
|
1946 break; |
|
1947 case '7': |
|
1948 Test7(); |
|
1949 break; |
|
1950 case '8': |
|
1951 Test8(); |
|
1952 break; |
|
1953 case '9': |
|
1954 Test9(0); |
|
1955 break; |
|
1956 case 'B': case 'b': |
|
1957 TestBL(test); |
|
1958 break; |
|
1959 case 'C': case 'c': |
|
1960 __UHEAP_MARK; |
|
1961 TestCL(test, BuildContinuationDbL()); |
|
1962 __UHEAP_MARKEND; |
|
1963 break; |
|
1964 case 'D': case 'd': |
|
1965 TestD(); |
|
1966 break; |
|
1967 case 'E': case 'e': |
|
1968 TestE(); |
|
1969 break; |
|
1970 case 'P': case 'p': |
|
1971 Test9(1); |
|
1972 break; |
|
1973 case 'Q': case 'q': |
|
1974 Test10(); |
|
1975 break; |
|
1976 |
|
1977 case EKeyEscape: |
|
1978 goto done; |
|
1979 default: |
|
1980 test.Printf(_L("Unknown command\n")); |
|
1981 }; |
|
1982 __UHEAP_MARKEND; |
|
1983 } |
|
1984 |
|
1985 done: |
|
1986 |
|
1987 test.Printf(_L("Finished! Press any key...\r\n")); |
|
1988 test.Getch(); |
|
1989 test.End(); |
|
1990 } |
|
1991 |
|
1992 |
|
1993 TInt E32Main() |
|
1994 { |
|
1995 |
|
1996 test.SetLogged(ETrue); |
|
1997 test.Title(); |
|
1998 __UHEAP_MARK; |
|
1999 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
2000 TRAPD(error,RunAppL()); // Run the App |
|
2001 __ASSERT_ALWAYS(error==KErrNone,User::Panic(_L("EPOC32EX"),error)); |
|
2002 delete cleanup; |
|
2003 __UHEAP_MARKEND; |
|
2004 test.Close(); |
|
2005 return KErrNone; |
|
2006 } |