|
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 "listener.h" |
|
24 #include "reqhandler.h" |
|
25 #include "SDPDatabase.h" |
|
26 #include "protocolmanl.h" |
|
27 #include "MAttributeVisitor.h" |
|
28 #include "ServiceSearchVisitor.h" |
|
29 #include "DataEncoder.h" |
|
30 #include "ExtractorVisitor.h" |
|
31 #include "EncoderVisitor.h" |
|
32 #include "responsesizevisitor.h" |
|
33 #include "debug.h" |
|
34 //#ifdef __EPOC32__ |
|
35 #include <c32comm.h> |
|
36 //#endif |
|
37 |
|
38 GLDEF_D RTest test(_L("SDP database DLL tests")); |
|
39 |
|
40 #if defined (__WINS__) |
|
41 #define PDD_NAME _L("ECDRV") |
|
42 #define LDD_NAME _L("ECOMM") |
|
43 #else // __GCC32__ |
|
44 #define PDD_NAME _L("EUART1") |
|
45 #define LDD_NAME _L("ECOMM") |
|
46 // #define ETNA_PDD_NAME _L("EUART2") // for debugging over com2 |
|
47 #endif |
|
48 |
|
49 CSdpDatabase *BuildDbL(); |
|
50 CSdpDatabase *BuildUpf4DbL(); |
|
51 CSdpDatabase* BuildContinuationDbL(); |
|
52 CSdpDatabase* BuildNestedListDbL(); |
|
53 CSdpDatabase* BuildPrequalDbL(); |
|
54 // in Builddb.cpp |
|
55 |
|
56 void LoadLDD_PDD() |
|
57 { |
|
58 TInt r; |
|
59 //#ifdef __EPOC32__ |
|
60 r=StartC32(); |
|
61 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
62 { |
|
63 test.Printf(_L("Failed %d!\n\r"),r); |
|
64 test(r==KErrNone); |
|
65 } |
|
66 else |
|
67 test.Printf(_L("Started C32\n")); |
|
68 //#endif |
|
69 test.Printf(_L("Loading PDD\n")); |
|
70 r=User::LoadPhysicalDevice(PDD_NAME); |
|
71 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
72 { |
|
73 test.Printf(_L("Failed %d!\n\r"),r); |
|
74 test(r==KErrNone); |
|
75 } |
|
76 else |
|
77 test.Printf(_L("Loaded PDD\n")); |
|
78 test.Printf(_L("Loading LDD\n")); |
|
79 r=User::LoadLogicalDevice(LDD_NAME); |
|
80 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
81 { |
|
82 test.Printf(_L("Failed %d!\n\r"),r); |
|
83 test(r==KErrNone); |
|
84 } |
|
85 else |
|
86 test.Printf(_L("Loaded LDD\n")); |
|
87 } |
|
88 |
|
89 // plagiarised from tsdp.cpp |
|
90 // actually Mel can't cast from Shortest form (TPtrC8) to a TDesC8 without this call |
|
91 void HexDes(const TDesC8& aDes) |
|
92 { |
|
93 for (TInt i = 0; i < aDes.Length(); ++i) |
|
94 test.Printf(_L("%02x"), aDes[i]); |
|
95 } |
|
96 |
|
97 class CAttrPrintVisitor : public CBase, public MAttributeVisitor |
|
98 { |
|
99 public: |
|
100 CAttrPrintVisitor(CConsoleBase& aConsole) : iConsole(aConsole) {iIndent=0;} |
|
101 ~CAttrPrintVisitor() {/*iConsole.Getch();*/} |
|
102 void VisitAttributeL(CSdpAttr &aAttribute) |
|
103 { |
|
104 Indent(); |
|
105 test.Printf(_L("\nID:0x%x:"), aAttribute.AttributeID()); |
|
106 } |
|
107 void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType) |
|
108 { |
|
109 // FIXME need a new object like the match list that will just store the object in |
|
110 // FIXME an array, or perhaps just print it ? Is it a visitor ? |
|
111 // CSdpSearchPattern* encAttrList = new (ELeave) CSdpSearchPattern; |
|
112 // CleanupStack::PushL(encAttrList); |
|
113 |
|
114 // CElementParser* parser = CElementParser::NewL(encAttrList); |
|
115 // CleanupStack::PushL(parser); |
|
116 |
|
117 // TInt rem; |
|
118 |
|
119 TBuf16<64> iString; |
|
120 // TInt iFound; |
|
121 switch (aType) |
|
122 { |
|
123 case ETypeString: |
|
124 iString.Copy(aValue.Des()); |
|
125 test.Printf(_L("\"%S\""),&iString); |
|
126 break; |
|
127 case ETypeDES: |
|
128 test.Printf(_L(" DES")); |
|
129 break; |
|
130 case ETypeUint: |
|
131 test.Printf(_L(" UInt:0x%x"), aValue.Uint()); |
|
132 break; |
|
133 case ETypeUUID: |
|
134 test.Printf(_L(" UUID:0x")); |
|
135 HexDes(aValue.UUID().ShortestForm()); |
|
136 break; |
|
137 case ETypeEncoded: |
|
138 HexDes(aValue.Des()); // simplest |
|
139 //parse out the elements in this encoded attribute |
|
140 // rem = parser->ParseElementsL(aValue.Des()); |
|
141 // CleanupStack::PopAndDestroy(/*parser*/); |
|
142 // for (iFound=0 ; iFound++ ; (iFound < (encAttrList->Length()))) |
|
143 // { |
|
144 // VisitAttributeValueL(encAttrList->At(iFound).Value, encAttrList->At(iFound).Type); |
|
145 // } |
|
146 // CleanupStack::PopAndDestroy(/*encAttrList*/); |
|
147 break; |
|
148 default: |
|
149 test.Printf(_L("type %d\n"), aType); |
|
150 } |
|
151 } |
|
152 void StartListL(CSdpAttrValueList &/*aList*/) |
|
153 { |
|
154 ++iIndent; |
|
155 test.Printf(_L("{")); |
|
156 } |
|
157 void EndListL() |
|
158 { |
|
159 if(iIndent<=0) |
|
160 { |
|
161 test.Printf(_L("\nERROR! Unmatched EndList!\n")); |
|
162 __DEBUGGER(); |
|
163 } |
|
164 test.Printf(_L("}")); |
|
165 --iIndent; |
|
166 } |
|
167 private: |
|
168 void Indent() {/*test.SetPos(iIndent)*/;} |
|
169 CConsoleBase &iConsole; |
|
170 TInt iIndent; |
|
171 }; |
|
172 |
|
173 void PrintDb(CSdpDatabase& aDb, CConsoleBase& aConsole) |
|
174 { |
|
175 aConsole.Printf(_L("Printing Database...\n")); |
|
176 |
|
177 for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++) |
|
178 {// Iterate thru records in Db |
|
179 aConsole.Printf(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle()); |
|
180 for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
181 {// Iterate thru attributes in record |
|
182 CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(aConsole); |
|
183 (*attrIter).AcceptVisitorL(*theVisitor); |
|
184 delete theVisitor; |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 class CAttrFlogVisitor : public CBase, public MAttributeVisitor |
|
190 { |
|
191 public: |
|
192 CAttrFlogVisitor(){} |
|
193 void VisitAttributeL(CSdpAttr &aAttribute) |
|
194 { |
|
195 Indent(); |
|
196 |
|
197 //3 lines for one here, but prevents warning. |
|
198 TUint id; |
|
199 id= aAttribute.AttributeID(); |
|
200 FTRACE(FPrint(_L("Attribute ID: 0x%x\n"), id)); |
|
201 |
|
202 (void)(id != 0); // keep compiler happy by referencing id as an r-value in urel |
|
203 } |
|
204 void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType) |
|
205 { |
|
206 TBuf16<64> iString; |
|
207 switch (aType) |
|
208 { |
|
209 case ETypeString: |
|
210 iString.Copy(aValue.Des()); |
|
211 FTRACE(FPrint(_L("\"%S\""),&iString)); |
|
212 break; |
|
213 case ETypeDES: |
|
214 FTRACE(FPrint(_L(" DES"))); |
|
215 break; |
|
216 case ETypeUint: |
|
217 FTRACE(FPrint(_L(" UInt:0x%x"), aValue.Uint())); |
|
218 break; |
|
219 case ETypeUUID: |
|
220 FTRACE(FPrint(_L(" UUID:0x"))); |
|
221 HexDes(aValue.UUID().ShortestForm()); |
|
222 break; |
|
223 case ETypeEncoded: |
|
224 HexDes(aValue.Des()); // simplest |
|
225 break; |
|
226 default: |
|
227 FTRACE(FPrint(_L("type %d\n"), aType)); |
|
228 } |
|
229 } |
|
230 //void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType) |
|
231 // { |
|
232 // Indent(); |
|
233 // FTRACE(FPrint(_L("(Val: type %d)\n"), aType)); |
|
234 // if(aType==ETypeUUID) |
|
235 // { |
|
236 // TUUID u = aValue.UUID(); |
|
237 // FTRACE(FPrint(_L("(Val: uuid 0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x)\n"), |
|
238 // 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])); |
|
239 // } |
|
240 // |
|
241 // } |
|
242 void StartListL(CSdpAttrValueList &/*aList*/) |
|
243 { |
|
244 ++iIndent; |
|
245 Indent(); |
|
246 FTRACE(FPrint(_L("{\n"))); |
|
247 } |
|
248 void EndListL() |
|
249 { |
|
250 if(iIndent<=0) |
|
251 { |
|
252 FTRACE(FPrint(_L("\nERROR! Unmatched EndList!\n"))); |
|
253 __DEBUGGER(); |
|
254 } |
|
255 Indent(); |
|
256 FTRACE(FPrint(_L("}\n"))); |
|
257 --iIndent; |
|
258 } |
|
259 private: |
|
260 void HexDes(const TDesC8& aDes) |
|
261 { |
|
262 for (TInt i = 0; i < aDes.Length(); ++i) |
|
263 { |
|
264 FTRACE(FPrint(_L("%02x"), aDes[i])); |
|
265 } |
|
266 } |
|
267 |
|
268 void Indent() |
|
269 { |
|
270 for(TInt i=0; i<iIndent;++i) |
|
271 { |
|
272 FTRACE(FPrint(_L(" "))); |
|
273 } |
|
274 } |
|
275 TInt iIndent; |
|
276 }; |
|
277 |
|
278 |
|
279 void FlogDb(CSdpDatabase& aDb) |
|
280 { |
|
281 FTRACE(FPrint(_L("\n\nPrinting Database...\n\n"))); |
|
282 |
|
283 for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++) |
|
284 {// Iterate thru records in Db |
|
285 FTRACE(FPrint(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle())); |
|
286 for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++) |
|
287 {// Iterate thru attributes in record |
|
288 CAttrFlogVisitor* theVisitor = new CAttrFlogVisitor(); |
|
289 (*attrIter).AcceptVisitorL(*theVisitor); |
|
290 delete theVisitor; |
|
291 } |
|
292 } |
|
293 FTRACE(FPrint(_L("\n\nEnd Printing Database...\n\n\n\n"))); |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 void RegisterDatabaseInServerL (RSdpDatabase& aDb, CSdpDatabase& aDbStruct) |
|
299 { |
|
300 for(TServRecordIter recIter(aDbStruct.RecordIter()); recIter; recIter++) |
|
301 {// Iterate thru records in Db |
|
302 TServAttrIter attrIter((*recIter).AttributeIter()); |
|
303 if(!attrIter) |
|
304 continue; |
|
305 if((*attrIter).AttributeID() == 0) |
|
306 attrIter++; //Skip rec handle |
|
307 if(!attrIter) |
|
308 continue; |
|
309 if((*attrIter).AttributeID() != 1 || (*attrIter).Value().Type() != ETypeDES) |
|
310 continue; |
|
311 // Get service class list |
|
312 TSdpServRecordHandle handle; |
|
313 aDb.CreateServiceRecordL((CSdpAttrValueDES&)(*attrIter).Value(), handle); |
|
314 attrIter++; |
|
315 for(; attrIter; attrIter++) |
|
316 {// Iterate thru attributes in record |
|
317 aDb.UpdateAttributeL(handle, (*attrIter).AttributeID(), (*attrIter).Value()); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 TSdpServRecordHandle BuildPagonisL(RSdpDatabase& aDb, TUUID aUUID, TUint8 aCN) |
|
323 /** |
|
324 Record Pagonis should be used when building a record with a protocol ID |
|
325 list consisting of L2CAP and RFCOMM. This record is for a service of class |
|
326 "serial port" - UUID16 0x1101 |
|
327 note that attributes 2, 5 and 0x201 should be updated. |
|
328 also note only English, pas de Francais, keine Deutsch, non Espanol |
|
329 **/ |
|
330 { |
|
331 TBuf8<4> value1; |
|
332 TBuf8<4> value2; |
|
333 TSdpServRecordHandle recHandle; |
|
334 CSdpAttrValue* attrVal = 0; |
|
335 CSdpAttrValueDES* attrValDES = 0; |
|
336 |
|
337 |
|
338 value1.FillZ(4); |
|
339 value2.FillZ(4); |
|
340 |
|
341 // Set Attr 1 (service class list) to list with UUID = 0x1101 (serial port) |
|
342 // or 0x1102 (LANP) |
|
343 aDb.CreateServiceRecordL(aUUID, recHandle); |
|
344 test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
345 |
|
346 // Set Attr 2 (service record state) to 0 |
|
347 value1.FillZ(4); |
|
348 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
349 CleanupStack::PushL(attrVal); |
|
350 aDb.UpdateAttributeL(recHandle, 0x02, *attrVal); |
|
351 CleanupStack::PopAndDestroy(); |
|
352 attrVal = 0; |
|
353 |
|
354 // Set attr 4 (protocol list) to L2CAP, and RFCOMM |
|
355 value1.FillZ(4); |
|
356 value1[3] = 3; |
|
357 value2.FillZ(4); |
|
358 value2[3] = aCN; |
|
359 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
360 CleanupStack::PushL(attrValDES); |
|
361 attrValDES |
|
362 ->StartListL() |
|
363 ->BuildDESL() |
|
364 ->StartListL() |
|
365 ->BuildUUIDL(TUUID(TUint16(0x0100))) // L2CAP |
|
366 ->BuildUintL(value1) |
|
367 ->EndListL() |
|
368 ->BuildDESL() |
|
369 ->StartListL() |
|
370 ->BuildUUIDL(TUUID(TUint16(0x0003))) // RFCOMM |
|
371 ->BuildUintL(value2) |
|
372 ->EndListL() |
|
373 ->EndListL(); |
|
374 aDb.UpdateAttributeL(recHandle, 0x04, *attrValDES); |
|
375 CleanupStack::PopAndDestroy(); |
|
376 attrValDES = 0; |
|
377 |
|
378 // Set Attr 5 (browse group list) to list with one UUID |
|
379 // 0x1101 (serial port class) |
|
380 // this should be updated with other service classes when other services are added. |
|
381 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
382 CleanupStack::PushL(attrValDES); |
|
383 attrValDES |
|
384 ->StartListL() |
|
385 ->BuildUUIDL(TUUID(TUint32(0x1002))) |
|
386 ->EndListL(); |
|
387 aDb.UpdateAttributeL(recHandle, 0x05, *attrValDES); |
|
388 CleanupStack::PopAndDestroy(); |
|
389 attrValDES = 0; |
|
390 |
|
391 |
|
392 // Set Attr 0x006 (language base) |
|
393 value1.FillZ(4); |
|
394 value1[2] = 0x65; |
|
395 value1[3] = 0x6e; |
|
396 TBuf8<4> val2; |
|
397 TBuf8<4> val3; |
|
398 val2.FillZ(4); |
|
399 val3.FillZ(4); |
|
400 val2[3] = 0x6a; |
|
401 val3[2] = 0x01; |
|
402 |
|
403 attrValDES = CSdpAttrValueDES::NewDESL(0); |
|
404 CleanupStack::PushL(attrValDES); |
|
405 attrValDES |
|
406 ->StartListL() |
|
407 ->BuildUintL(value1) // english |
|
408 ->BuildUintL(val2) // UTF-8 |
|
409 ->BuildUintL(val3) // language base |
|
410 ->EndListL(); |
|
411 aDb.UpdateAttributeL(recHandle, 0x06, *attrValDES); |
|
412 CleanupStack::PopAndDestroy(); |
|
413 attrValDES = 0; |
|
414 |
|
415 // Set Attr 0x007 (time to live) to 1200 (0x4B0) seconds (20 minutes) |
|
416 value1.FillZ(4); |
|
417 value1[2]=4; |
|
418 value1[3]=0xb0; |
|
419 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
420 CleanupStack::PushL(attrVal); |
|
421 aDb.UpdateAttributeL(recHandle, 0x07, *attrVal); |
|
422 CleanupStack::PopAndDestroy(); |
|
423 attrVal = 0; |
|
424 |
|
425 // Set Attr 0x008 (availability) to 0xff - fully available - not in use |
|
426 value1.FillZ(4); |
|
427 value1[3]=0xff; |
|
428 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
429 CleanupStack::PushL(attrVal); |
|
430 aDb.UpdateAttributeL(recHandle, 0x08, *attrVal); |
|
431 CleanupStack::PopAndDestroy(); |
|
432 attrVal = 0; |
|
433 |
|
434 |
|
435 // Set Attr 0x100 (default Name) to string |
|
436 attrVal = CSdpAttrValueString::NewStringL(_L8("Pagonis Service")); |
|
437 CleanupStack::PushL(attrVal); |
|
438 aDb.UpdateAttributeL(recHandle, 0x0100, *attrVal); |
|
439 CleanupStack::PopAndDestroy(); |
|
440 attrVal = 0; |
|
441 |
|
442 // Set Attr 0x101 (def. description) to string |
|
443 attrVal = CSdpAttrValueString::NewStringL(_L8("It's all Greek to me!")); |
|
444 CleanupStack::PushL(attrVal); |
|
445 aDb.UpdateAttributeL(recHandle, 0x0101, *attrVal); |
|
446 CleanupStack::PopAndDestroy(); |
|
447 attrVal = 0; |
|
448 |
|
449 // Set Attr 0x102 (def. provider) to Symbian |
|
450 attrVal = CSdpAttrValueString::NewStringL(_L8("Symbian Ltd.")); |
|
451 CleanupStack::PushL(attrVal); |
|
452 aDb.UpdateAttributeL(recHandle, 0x0102, *attrVal); |
|
453 CleanupStack::PopAndDestroy(); |
|
454 attrVal = 0; |
|
455 |
|
456 // Set Attr 0x201 (service database state) to 0 |
|
457 value1.FillZ(4); |
|
458 attrVal = CSdpAttrValueUint::NewUintL(value1); |
|
459 CleanupStack::PushL(attrVal); |
|
460 aDb.UpdateAttributeL(recHandle, 0x0201, *attrVal); |
|
461 CleanupStack::PopAndDestroy(); |
|
462 attrVal = 0; |
|
463 |
|
464 return recHandle; |
|
465 } |
|
466 |
|
467 |
|
468 void Test0() |
|
469 /** |
|
470 Client/server test. |
|
471 **/ |
|
472 { |
|
473 FLOG(_L("Running test 0")); |
|
474 //FIXME: TRAPD? |
|
475 test.Start(_L("Test 0 -- Client/Server")); |
|
476 TInt ret; |
|
477 LoadLDD_PDD(); |
|
478 |
|
479 RSdp sdp; |
|
480 ret = sdp.Connect(); |
|
481 if(ret!=KErrNone) |
|
482 { |
|
483 test.End(); |
|
484 return; |
|
485 } |
|
486 RSdpDatabase db; |
|
487 ret = db.Open(sdp); |
|
488 if(ret!=KErrNone) |
|
489 { |
|
490 test.End(); |
|
491 return; |
|
492 } |
|
493 TSdpServRecordHandle recHandle = 0; |
|
494 TUUID uuid = TUUID(0x20000); //prevents warning |
|
495 db.CreateServiceRecordL(uuid, recHandle); |
|
496 test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
497 CSdpAttrValueDES* list = CSdpAttrValueDES::NewDESL(NULL); |
|
498 MSdpElementBuilder* bldr= list; |
|
499 CleanupStack::PushL(list); |
|
500 |
|
501 bldr |
|
502 ->StartListL() |
|
503 ->BuildUUIDL(TUUID(TUint32(0x20002000))) |
|
504 ->BuildUUIDL(TUUID(TUint32(0x11112222), TUint32(0x33334444), |
|
505 TUint32(0x55556666), TUint32(0x77778888))) |
|
506 ->BuildUUIDL(TUUID(TUint32(0x40000))) |
|
507 ->EndListL(); |
|
508 //db.CreateServiceRecordL(*list, recHandle); |
|
509 CleanupStack::PopAndDestroy(); //list |
|
510 //test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandle); |
|
511 //User::WaitForRequest(status); |
|
512 //if(status==KErrNone) |
|
513 // test.Printf(_L("Service Record Created - Handle: 0x%x!\n\n"), recHandlePckgBuf()); |
|
514 //else |
|
515 // test.Printf(_L("Service Record Creation ERROR %d!\n\n"), status.Int()); |
|
516 |
|
517 TBuf8<8> buf8(_L8("Mel!")); |
|
518 buf8[1] = 'E'; |
|
519 buf8[2] = 'L'; |
|
520 TDesC16 buf16(_L("Nicky!")); |
|
521 db.UpdateAttributeL(recHandle, 0x3454, buf8); |
|
522 db.UpdateAttributeL(recHandle, 0x3455, _L("Nicky!")); |
|
523 db.UpdateAttributeL(recHandle, 0x3455, _L("Micky!")); |
|
524 db.UpdateAttributeL(recHandle, 0x3456, 0x9999); |
|
525 db.DeleteAttributeL(recHandle, 0x3456); |
|
526 db.UpdateAttributeL(recHandle, 0x3456, 0x7777); |
|
527 db.DeleteAttributeL(recHandle, 0x5555); //does not exist! |
|
528 //db.DeleteRecordL(recHandleSpecial); |
|
529 db.Close(); |
|
530 sdp.Close(); |
|
531 test.End(); |
|
532 } |
|
533 |
|
534 |
|
535 void Test1() |
|
536 /** |
|
537 Client/server test for use with John Pagonis. |
|
538 Suitable database built on client side, and placed in server. |
|
539 Server left alive till user chooses to kill it. |
|
540 **/ |
|
541 { |
|
542 FLOG(_L("Running test 1")); |
|
543 //FIXME: TRAPD? |
|
544 test.Start(_L("Test 1 ...\n")); |
|
545 //__BREAKPOINT(); |
|
546 |
|
547 TChar c; |
|
548 RSdp sdp; |
|
549 RSdpDatabase db; |
|
550 TInt ret; |
|
551 LoadLDD_PDD(); |
|
552 |
|
553 test.Printf(_L("About to play with the SDP database\n - make sure the SDP database EXISTS, and then press any key.\n")); |
|
554 test.Getch(); |
|
555 test.Next(_L("Opening SDP Database")); |
|
556 ret = sdp.Connect(); |
|
557 if(ret!=KErrNone) |
|
558 { |
|
559 if(ret==KErrNotFound) |
|
560 test.Printf(_L("Cannot start sdp server, could not find bluetooth.\n")); |
|
561 else |
|
562 test.Printf(_L("Cannot start sdp server.\n")); |
|
563 test.Next(_L("PRESS ANY KEY.\n")); |
|
564 test.Getch(); |
|
565 |
|
566 test.End(); |
|
567 return; |
|
568 } |
|
569 test(ret==KErrNone); |
|
570 ret = db.Open(sdp); |
|
571 if(ret!=KErrNone) |
|
572 { |
|
573 test.Printf(_L("Starting SDP Server SESSION FAILED.\n")); |
|
574 test.End(); |
|
575 return; |
|
576 } |
|
577 |
|
578 TSdpServRecordHandle recHandle1 = 0x0010000; |
|
579 TUint16 attrId = 0x01; |
|
580 |
|
581 |
|
582 CSdpAttrValueDES* attrVal = CSdpAttrValueDES::NewDESL(NULL); |
|
583 CleanupStack::PushL(attrVal); |
|
584 MSdpElementBuilder* bldr = attrVal; |
|
585 bldr->StartListL()->BuildUUIDL(TUUID(TUint16(0x1000)))->EndListL(); |
|
586 TRAPD(err, db.UpdateAttributeL(recHandle1, attrId, *attrVal)); |
|
587 CleanupStack::PopAndDestroy(); |
|
588 |
|
589 test.Printf(_L("Update Attribute on Attr %d in Service Record %d in SDP Server's Database returned %d.\n"), attrId, recHandle1, err); |
|
590 test.Printf(_L("Press any key to continue.\n")); |
|
591 test.Getch(); |
|
592 |
|
593 attrId = 0x3455; |
|
594 TRAP(err, db.UpdateAttributeL(recHandle1, attrId, _L("Nicky!"))); |
|
595 test.Printf(_L("Update Attribute on Attr %d in Service Record %d in SDP Server's Database returned %d.\n"), attrId, recHandle1, err); |
|
596 test.Printf(_L("Press any key to continue.\n")); |
|
597 test.Getch(); |
|
598 |
|
599 attrId = 0x01; |
|
600 TRAP(err, db.DeleteAttributeL(recHandle1, attrId)); |
|
601 test.Printf(_L("Delete Attribute on Attr %d in Service Record %d in SDP Server's Database returned %d.\n"), attrId, recHandle1, err); |
|
602 test.Printf(_L("Press any key to continue.\n")); |
|
603 test.Getch(); |
|
604 |
|
605 TRAP(err, db.DeleteRecordL(recHandle1)); |
|
606 test.Printf(_L("Delete Service Record %d in SDP Server's Database returned %d.\n"), attrId, recHandle1, err); |
|
607 test.Printf(_L("Press any key to continue.\n")); |
|
608 test.Getch(); |
|
609 db.Close(); |
|
610 sdp.Close(); |
|
611 |
|
612 |
|
613 test.End(); |
|
614 } |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 void IntConversionTest() |
|
621 /** |
|
622 Checks compiler has done uint-int cast correctly |
|
623 in CSdpAttrValueInt::Int(). |
|
624 **/ |
|
625 { |
|
626 TBuf8<4> tstr; |
|
627 tstr.FillZ(4); |
|
628 tstr[0] = 0xff; |
|
629 tstr[1] = 0xff; |
|
630 tstr[2] = 0xff; |
|
631 tstr[3] = 0xff; |
|
632 TInt ret = 0; |
|
633 CSdpAttrValueInt* avi = 0; |
|
634 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
635 ret = avi->Int(); |
|
636 delete avi; |
|
637 avi = 0; |
|
638 __ASSERT_DEBUG(ret==-1, User::Panic(_L("Bad4ByteIntConversion"), KErrGeneral)); |
|
639 tstr.SetLength(2); |
|
640 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
641 ret = avi->Int(); |
|
642 delete avi; |
|
643 avi = 0; |
|
644 __ASSERT_DEBUG(ret==-1, User::Panic(_L("Bad2ByteIntConversion"), KErrGeneral)); |
|
645 //tstr[0] = 0x0e; |
|
646 tstr.SetLength(1); |
|
647 avi = CSdpAttrValueInt::NewIntL(tstr); |
|
648 ret = avi->Int(); |
|
649 delete avi; |
|
650 avi = 0; |
|
651 __ASSERT_DEBUG(ret==-1, User::Panic(_L("BadByteIntConversion"), KErrGeneral)); |
|
652 |
|
653 (void)(ret != 0); // keep compiler happy by referencing ret as an r-value in urel |
|
654 |
|
655 return; |
|
656 } |
|
657 |
|
658 void RunAppL() |
|
659 { |
|
660 // TInt ret; |
|
661 test.Title(); |
|
662 test.Start(_L("Running SDP server tests")); |
|
663 // For some reason, you have to do the following to |
|
664 // ensure that the file server behaves properly. |
|
665 RFs fs; |
|
666 (void)fs.Connect(); |
|
667 fs.Close(); |
|
668 // TUid uid; |
|
669 // uid.iUid = 0x00ce; |
|
670 // User::SetIdentity(uid); |
|
671 // Run through tests |
|
672 IntConversionTest(); |
|
673 FOREVER |
|
674 { |
|
675 Test1(); |
|
676 // uid = User::Identity(); |
|
677 test.Printf(_L("Press 'T' to retry.\r\n")); |
|
678 TInt c = test.Getch(); |
|
679 if(c!='t'&&c!='T')break; |
|
680 } |
|
681 |
|
682 |
|
683 test.Printf(_L("Finished! Press any key...\r\n")); |
|
684 test.Getch(); |
|
685 test.End(); |
|
686 } |
|
687 |
|
688 |
|
689 TInt E32Main() |
|
690 { |
|
691 //__BREAKPOINT(); |
|
692 test.SetLogged(ETrue); |
|
693 test.Title(); |
|
694 __UHEAP_MARK; |
|
695 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
696 TRAPD(error,RunAppL()); // Run the App |
|
697 test.Printf(_L("RunAppL left with result: %d"), error); |
|
698 delete cleanup; |
|
699 __UHEAP_MARKEND; |
|
700 test.Close(); |
|
701 return KErrNone; |
|
702 } |