bluetooth/btsdp/test/tsdpag.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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 #include <e32test.h>
       
    19 #include <f32file.h>
       
    20 #include <btmanclient.h>
       
    21 #include <btsdp.h>
       
    22 #include <btextnotifiers.h>
       
    23 #include "sdpkey.h"
       
    24 #include "SDPDatabase.h"
       
    25 #include "MAttributeVisitor.h"
       
    26 #include "ServiceSearchVisitor.h"
       
    27 #include "DataEncoder.h"
       
    28 #include "ExtractorVisitor.h"
       
    29 #include "EncoderVisitor.h"
       
    30 #include "debug.h"
       
    31 #ifdef __EPOC32__
       
    32 #include <c32comm.h>
       
    33 #endif
       
    34 
       
    35 
       
    36 #include <es_sock.h>
       
    37 #include <bt_sock.h>
       
    38 #include <c32comm.h>
       
    39 #include <btsdp.h>
       
    40 #include "agtypes.h"
       
    41 #include "agutil.h"
       
    42 #include "ProtocolWrapper.h"
       
    43 
       
    44 #include "TSDPSAS.h"
       
    45 
       
    46 
       
    47 
       
    48 GLDEF_D RTest test(_L("SDP database DLL tests"));
       
    49 
       
    50 void AgPanic(TSdpAgPanic aCode)
       
    51 	{
       
    52 	User::Panic(_L("SdpAgent"),aCode);
       
    53 	}
       
    54 
       
    55 
       
    56 #if defined (__WINS__)
       
    57 #define PDD_NAME _L("ECDRV")
       
    58 #define LDD_NAME _L("ECOMM")
       
    59 #else  // __GCC32__
       
    60 #define PDD_NAME _L("EUART1")
       
    61 #define LDD_NAME _L("ECOMM")
       
    62 // #define ETNA_PDD_NAME _L("EUART2") // for debugging over com2
       
    63 #endif
       
    64 
       
    65 CSdpDatabase *BuildDbL();
       
    66 CSdpDatabase *BuildUpf4DbL();
       
    67 // in Builddb.cpp
       
    68 
       
    69 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5bff094c));	//Cambridge CASIRA
       
    70 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5bff0a4c));	//Cambridge CASIRA 2
       
    71 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5b013434));	//PANCAS 03
       
    72 GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5b0136bc));	//PANCAS 13
       
    73 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5b013610));	//PANCAS 16
       
    74 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0xee4d6133));	//NICK'S 7650
       
    75 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0060, 0x57411ee1));	//ANDY P'S 3650
       
    76 //
       
    77 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0080, 0x370f2e22));
       
    78 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0050, 0xcd0002e0));
       
    79 
       
    80 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5bffbbb9));	//Hasse's Casira
       
    81 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00e0, 0x0370b5d3));	//Helge Board 1
       
    82 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00e0, 0x0326d3b4));	//Helge Board 2
       
    83 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0xb70329b8));	//EBMK sn:001 0028 0438
       
    84 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0xb7032bbb));	//EBMK sn:001 0028 0353
       
    85 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0xb7030ece));	//EBMK sn:001 0017 0344
       
    86 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0xb7031750));	//EBMK sn:001 0017 0346
       
    87 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0xaebd, 0x99000201)); //Ericcson 
       
    88 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0xaec3, 0xdd562e32)); //RTX Telecom A/S
       
    89 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0xae2d, 0xaa343536)); //Widcomm
       
    90 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0080, 0x3712205d)); //SSL
       
    91 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0080, 0x370F287D)); //SSL
       
    92 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0002, 0x5bff0609)); //John T's blue dongly
       
    93 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0080, 0x375A000E)); // EBDK 1 (0081 0097...)
       
    94 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0080, 0x375A000F)); // EBDK 3 (001 0008 0095)
       
    95 
       
    96 
       
    97 //static const TUint16 KUnplugUUID = 0x1103;
       
    98 //static const TUint16 KUnplugUUID = 3;
       
    99 //static const TUint16 KUnplugAttribId = 4;
       
   100 
       
   101 //static const TInt KSDPMaxRequestSize = 100;
       
   102 
       
   103 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0001, 0xec0cdfda));	// EBDK 1
       
   104 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0050, 0xcd0002e1));	// PC Card
       
   105 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x0050, 0xcd003038));	// RS232 card
       
   106 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0x5a000064));	// Harold
       
   107 //GLDEF_D TBTDevAddr devAddr(MAKE_TINT64(0x00d0, 0x5a000064));	// Harold
       
   108 
       
   109 
       
   110 
       
   111 
       
   112 void LoadLDD_PDD()
       
   113 	{
       
   114 	TInt r;
       
   115 #ifdef __EPOC32__
       
   116 	r=StartC32();
       
   117 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   118 		{
       
   119 		test.Printf(_L("Failed %d!\n\r"),r);
       
   120 		test(r==KErrNone);
       
   121 		}
       
   122 	else
       
   123 		test.Printf(_L("Started C32\n"));
       
   124 #endif
       
   125 	test.Printf(_L("Loading PDD\n"));
       
   126 	r=User::LoadPhysicalDevice(PDD_NAME);
       
   127 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   128 		{
       
   129 		test.Printf(_L("Failed %d!\n\r"),r);
       
   130 		test(r==KErrNone);
       
   131 		}
       
   132 	else 
       
   133 		test.Printf(_L("Loaded PDD\n"));
       
   134 	test.Printf(_L("Loading LDD\n"));
       
   135 	r=User::LoadLogicalDevice(LDD_NAME);
       
   136 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   137 		{
       
   138 		test.Printf(_L("Failed %d!\n\r"),r);
       
   139 		test(r==KErrNone);
       
   140 		}
       
   141 	else
       
   142 		test.Printf(_L("Loaded LDD\n"));
       
   143 	}
       
   144 
       
   145 // plagiarised from tsdp.cpp
       
   146 // actually Mel can't cast from Shortest form (TPtrC8) to a TDesC8 without this call
       
   147 void HexDes(const TDesC8& aDes)
       
   148 	{
       
   149 	for (TInt i = 0; i < aDes.Length(); ++i)
       
   150 		test.Printf(_L("%02x"), aDes[i]);
       
   151 	}
       
   152 
       
   153 void HexDump(const TDesC8& aDes)
       
   154 	{
       
   155 	for (TInt i = 0; i < aDes.Length(); ++i)
       
   156 		{
       
   157 		if (i%8 == 0)
       
   158 			test.Printf(_L("0x%04x:   "), i);
       
   159 		test.Printf(_L("0x%02x "), aDes[i]);
       
   160 		if (i%8 == 7 || i == aDes.Length() - 1)
       
   161 			test.Printf(_L("\n"));
       
   162 		}
       
   163 	}
       
   164 
       
   165 class CConsoleBuilder : public CBase, public MSdpElementBuilder
       
   166 	{
       
   167 public:
       
   168 	CConsoleBuilder(CConsoleBase& aConsole) :iConsole(aConsole) {};
       
   169 	MSdpElementBuilder* BuildUnknown(TUint8 aType, TUint8 aSizeDesc, const TDesC8& aData)
       
   170 		{
       
   171 		iConsole.SetPos(iIndent);
       
   172 		iConsole.Printf(_L("Got Unknown: <type %d, sizedesc %d, length %d>\n"), aType, aSizeDesc, aData.Length());
       
   173 		HexDump(aData);
       
   174 		return this;
       
   175 		};
       
   176 	MSdpElementBuilder* BuildNilL()
       
   177 		{
       
   178 		iConsole.SetPos(iIndent);
       
   179 		iConsole.Printf(_L("Got Nil: <>\n"));
       
   180 		return this;
       
   181 		};
       
   182 	MSdpElementBuilder* BuildUintL(TUint aUint)
       
   183 		{
       
   184 		iConsole.SetPos(iIndent);
       
   185 		iConsole.Printf(_L("Got Uint: <%d>\n"), aUint);
       
   186 		return this;
       
   187 		};
       
   188 	MSdpElementBuilder* BuildUintL(const TDesC8& aLongUint)
       
   189 		{
       
   190 		iConsole.SetPos(iIndent);
       
   191 		iConsole.Printf(_L("Got Long Uint: <Length %d>\n"), aLongUint.Length());
       
   192 		HexDump(aLongUint);
       
   193 		return this;
       
   194 		};
       
   195 	MSdpElementBuilder* BuildIntL(TUint aInt)
       
   196 		{
       
   197 		iConsole.SetPos(iIndent);
       
   198 		iConsole.Printf(_L("Got Int: <%d>\n"), aInt);
       
   199 		return this;
       
   200 		};
       
   201 	MSdpElementBuilder* BuildIntL(const TDesC8& aLongInt)
       
   202 		{
       
   203 		iConsole.SetPos(iIndent);
       
   204 		iConsole.Printf(_L("Got Long Int: <Length %d>\n"), aLongInt.Length());
       
   205 		HexDump(aLongInt);
       
   206 		return this;
       
   207 		};
       
   208 	MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID)
       
   209 		{
       
   210 		iConsole.SetPos(iIndent);
       
   211 		iConsole.Printf(_L("Got UUID: <length %d>\n"), aUUID.ShortestForm().Length());
       
   212 		HexDump(aUUID.ShortestForm());
       
   213 		return this;
       
   214 		};
       
   215 	MSdpElementBuilder* BuildBooleanL(TBool aBool)
       
   216 		{
       
   217 		iConsole.SetPos(iIndent);
       
   218 		iConsole.Printf(_L("Got Boolean: <%d>\n"), aBool);
       
   219 		return this;
       
   220 		};
       
   221 	MSdpElementBuilder* BuildStringL(const TDesC8& aString)
       
   222 		{
       
   223 		TBuf<512> ustr;
       
   224 		ustr.Copy(aString.Left(Min(aString.Length(), ustr.MaxLength())));
       
   225 		iConsole.SetPos(iIndent);
       
   226 		iConsole.Printf(_L("Got String: <length %d, Contents %S>\n"), ustr.Length(), &ustr);
       
   227 		return this;
       
   228 		};
       
   229 	MSdpElementBuilder* BuildDESL()
       
   230 		{
       
   231 		return StartListL();
       
   232 		};
       
   233 
       
   234 	MSdpElementBuilder* BuildDEAL()
       
   235 		{
       
   236 		return StartListL();
       
   237 		};
       
   238 
       
   239 	MSdpElementBuilder* StartListL(/*prob want list type here*/)
       
   240 		{
       
   241 		iConsole.SetPos(iIndent);
       
   242 		iConsole.Printf(_L("<START LIST>\n"));
       
   243 		iIndent += 2;
       
   244 		return this;
       
   245 		};
       
   246 	MSdpElementBuilder* EndListL()
       
   247 		{
       
   248 		if (iIndent > 0)
       
   249 			{
       
   250 			iIndent-=2;
       
   251 			iConsole.SetPos(iIndent);
       
   252 			iConsole.Printf(_L("<END LIST>\n"));
       
   253 			}
       
   254 		else
       
   255 			{
       
   256 			iConsole.Printf(_L("WARNING: UNMATCHED END LIST!"));
       
   257 			}
       
   258 		return this;
       
   259 		};
       
   260 	MSdpElementBuilder* BuildURLL(const TDesC8& aString)
       
   261 		{
       
   262 		iConsole.SetPos(iIndent);
       
   263 		iConsole.Printf(_L("Got URL: <%S>\n"), &aString);
       
   264 		return this;
       
   265 		};
       
   266 
       
   267 private:
       
   268 	CConsoleBase&	iConsole;
       
   269 	TInt			iIndent;
       
   270 	};
       
   271 
       
   272 
       
   273 
       
   274 TInt ParseL(TDesC8& aDes)
       
   275 {
       
   276 	// Parse attribute list
       
   277 	CConsoleBuilder* builder = new(ELeave) CConsoleBuilder(*test.Console());
       
   278 	CElementParser* parser = CElementParser::NewL(builder);
       
   279 
       
   280 	test.Next(_L("Parsing simple attribute list"));
       
   281 	TUint rem=0;
       
   282 	TRAPD(err,rem=parser->ParseElementsL(aDes.Mid(2)));
       
   283 	if (err)
       
   284 		test.Printf(_L("Parser left with error %d\n"), err);
       
   285 	else
       
   286 		test.Printf(_L("Parser returned %d\n"), rem);
       
   287 	test.Getch();
       
   288 	return rem;
       
   289 }
       
   290 
       
   291 
       
   292 
       
   293 class CAttrPrintVisitor : public CBase, public MAttributeVisitor
       
   294 	{
       
   295 public:
       
   296 	CAttrPrintVisitor(CConsoleBase& aConsole) : iConsole(aConsole) {iIndent=0;}
       
   297 	~CAttrPrintVisitor() {/*iConsole.Getch();*/}
       
   298     void VisitAttributeL(CSdpAttr &aAttribute)
       
   299 		{
       
   300 		Indent();
       
   301 		test.Printf(_L("\nID:0x%x:"), aAttribute.AttributeID());
       
   302 		}
       
   303 	void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType)
       
   304 		{
       
   305 // FIXME need a new object like the match list that will just store the object in
       
   306 // FIXME an array, or perhaps just print it ? Is it a visitor ?
       
   307 //		CSdpSearchPattern* encAttrList = new (ELeave) CSdpSearchPattern;
       
   308 //		CleanupStack::PushL(encAttrList);
       
   309 
       
   310 //		CElementParser* parser = CElementParser::NewL(encAttrList);
       
   311 //		CleanupStack::PushL(parser);
       
   312 
       
   313 //		TInt rem;
       
   314 
       
   315 		TBuf16<0x64> iString;
       
   316 //		TInt iFound;
       
   317 		switch (aType)
       
   318 			{
       
   319 			case ETypeString:
       
   320 				{
       
   321 				TInt len = aValue.Des().Length();
       
   322 				if(len<0x60)
       
   323 					//cannot cope with strings longer than 100 bytes!
       
   324 					{
       
   325 					iString.Copy(aValue.Des());
       
   326 					test.Printf(_L("\"%S\""),&iString);
       
   327 					}
       
   328 				else
       
   329 					{
       
   330 					test.Printf(_L("String attribute too long for CONSOLE: Length %d"),len);
       
   331 					}
       
   332 				break;
       
   333 				}
       
   334 			case ETypeDES:
       
   335 				test.Printf(_L(" DES"));
       
   336 				break;
       
   337 			case ETypeUint:
       
   338 				test.Printf(_L(" UInt:0x%x"), aValue.Uint());
       
   339 				break;
       
   340 			case ETypeUUID:
       
   341 				test.Printf(_L(" UUID:0x"));
       
   342 				HexDes(aValue.UUID().ShortestForm());
       
   343 				break;
       
   344 			case ETypeEncoded:
       
   345 				HexDes(aValue.Des());  // simplest
       
   346 //parse out the elements in this encoded attribute
       
   347 //				rem = parser->ParseElementsL(aValue.Des());
       
   348 //				CleanupStack::PopAndDestroy(/*parser*/);
       
   349 //				for (iFound=0 ; iFound++ ; (iFound < (encAttrList->Length())))
       
   350 //				{
       
   351 //					VisitAttributeValueL(encAttrList->At(iFound).Value, encAttrList->At(iFound).Type);
       
   352 //				}
       
   353 //				CleanupStack::PopAndDestroy(/*encAttrList*/);
       
   354 				break;
       
   355 			default:
       
   356 				test.Printf(_L("type %d\n"), aType);
       
   357 			}
       
   358 		}
       
   359 	void StartListL(CSdpAttrValueList &/*aList*/)
       
   360 		{
       
   361 		++iIndent;
       
   362 		test.Printf(_L("{"));
       
   363 		}
       
   364     void EndListL()
       
   365 		{
       
   366 		if(iIndent<=0)
       
   367 			{
       
   368 			test.Printf(_L("\nERROR! Unmatched EndList!\n"));
       
   369 			__DEBUGGER();
       
   370 			}
       
   371 		test.Printf(_L("}"));
       
   372 		--iIndent;
       
   373 		}
       
   374 private:
       
   375 	void Indent() {/*test.SetPos(iIndent)*/;}
       
   376 	CConsoleBase &iConsole;
       
   377 	TInt iIndent;
       
   378 	};
       
   379 
       
   380 void PrintDb(CSdpDatabase& aDb, CConsoleBase& aConsole)
       
   381 	{
       
   382 	aConsole.Printf(_L("Printing Database...\n"));
       
   383 
       
   384 	for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++)
       
   385 		{// Iterate thru records in Db
       
   386 		aConsole.Printf(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle());
       
   387 		for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++)
       
   388 			{// Iterate thru attributes in record
       
   389 			CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(aConsole);
       
   390 			(*attrIter).AcceptVisitorL(*theVisitor);
       
   391 			delete theVisitor;
       
   392 			}
       
   393 		}
       
   394 	}
       
   395 
       
   396 class CAttrFlogVisitor : public CBase, public MAttributeVisitor
       
   397 	{
       
   398 public:
       
   399 	CAttrFlogVisitor(){}
       
   400 #ifdef _DEBUG
       
   401     void VisitAttributeL(CSdpAttr& aAttribute)
       
   402 		{
       
   403 		Indent();
       
   404 		FTRACE(FPrint(_L("Attribute ID: 0x%x\n"), aAttribute.AttributeID()));
       
   405 		}
       
   406 #else
       
   407     void VisitAttributeL(CSdpAttr&)
       
   408 		{
       
   409 		Indent();
       
   410 		}
       
   411 #endif // _DEBUG
       
   412 	void VisitAttributeValueL(CSdpAttrValue & aValue, TSdpElementType aType)
       
   413 		{
       
   414 		TBuf16<64> iString;
       
   415 		switch (aType)
       
   416 			{
       
   417 			case ETypeString:
       
   418 				iString.Copy(aValue.Des());
       
   419 				FTRACE(FPrint(_L("\"%S\""),&iString));
       
   420 				break;
       
   421 			case ETypeDES:
       
   422 				FTRACE(FPrint(_L(" DES")));
       
   423 				break;
       
   424 			case ETypeUint:
       
   425 				FTRACE(FPrint(_L(" UInt:0x%x"), aValue.Uint()));
       
   426 				break;
       
   427 			case ETypeUUID:
       
   428 				FTRACE(FPrint(_L(" UUID:0x")));
       
   429 				HexDes(aValue.UUID().ShortestForm());
       
   430 				break;
       
   431 			case ETypeEncoded:
       
   432 				HexDes(aValue.Des());  // simplest
       
   433 				break;
       
   434 			default:
       
   435 				FTRACE(FPrint(_L("type %d\n"), aType));
       
   436 			}
       
   437 		}
       
   438     void StartListL(CSdpAttrValueList &/*aList*/)
       
   439 		{
       
   440 		++iIndent;
       
   441 		Indent();
       
   442 		FTRACE(FPrint(_L("{\n")));
       
   443 		}
       
   444     void EndListL()
       
   445 		{
       
   446 		if(iIndent<=0)
       
   447 			{
       
   448 			FTRACE(FPrint(_L("\nERROR! Unmatched EndList!\n")));
       
   449 			__DEBUGGER();
       
   450 			}
       
   451 		Indent();
       
   452 		FTRACE(FPrint(_L("}\n")));
       
   453 		--iIndent;
       
   454 		}
       
   455 private:
       
   456 	void HexDes(const TDesC8& aDes)
       
   457 		{
       
   458 		for (TInt i = 0; i < aDes.Length(); ++i) 
       
   459 			{
       
   460 			FTRACE(FPrint(_L("%02x"), aDes[i]));
       
   461 			}
       
   462 		}
       
   463 
       
   464 	void Indent() 
       
   465 		{
       
   466 		for(TInt i=0; i<iIndent;++i)
       
   467 			{
       
   468 			FTRACE(FPrint(_L("  ")));
       
   469 			}
       
   470 		}
       
   471 	TInt iIndent;
       
   472 	};
       
   473 
       
   474 
       
   475 void FlogDb(CSdpDatabase& aDb)
       
   476 	{
       
   477 	FTRACE(FPrint(_L("\n\nPrinting Database...\n\n")));
       
   478 
       
   479 	for(TServRecordIter recIter(aDb.RecordIter()); recIter; recIter++)
       
   480 		{// Iterate thru records in Db
       
   481 		FTRACE(FPrint(_L("\n...Printing Record 0x%x\n"), (*recIter).Handle()));
       
   482 		for(TServAttrIter attrIter((*recIter).AttributeIter()); attrIter; attrIter++)
       
   483 			{// Iterate thru attributes in record
       
   484 			CAttrFlogVisitor* theVisitor = new CAttrFlogVisitor();
       
   485 			(*attrIter).AcceptVisitorL(*theVisitor);
       
   486 			delete theVisitor;
       
   487 			}
       
   488 		}
       
   489 	FTRACE(FPrint(_L("\n\nEnd Printing Database...\n\n\n\n")));
       
   490 	}
       
   491 
       
   492 
       
   493 
       
   494 void Test1()
       
   495 /**
       
   496 	RSdpAgent Test.
       
   497 **/
       
   498 	{
       
   499 	test.Start(_L("Testing RSdpAgent used with BT NetDb connection"));	// SOCKSERV CONNECTION
       
   500     RSocketServ ss;
       
   501 	TInt ret=ss.Connect();
       
   502     test(ret==KErrNone || ret==KErrAlreadyExists);
       
   503 	 
       
   504 
       
   505 	TUint32 uuid = 0x1100;
       
   506 
       
   507 	do
       
   508 		{
       
   509 		RSdpAgent sa;
       
   510 		TInt bufSize;
       
   511 		TUint16 maxAttrByteCount = 0x200;
       
   512 		TRequestStatus stat;
       
   513 		TSDPConnectQuery connQ;
       
   514 		TBuf8<512> result;
       
   515 		TBuf8<255> request;
       
   516 		TInt len;
       
   517 		TBuf8<2> contState(0);
       
   518 		//BigEndian::Put16(&contState[0], 0);
       
   519 
       
   520 	    test.Next(_L("Opening SDP Net Database"));
       
   521 			
       
   522 		ret=sa.Open(ss);
       
   523 		if (ret==KErrNone)
       
   524 			{
       
   525 			test.Printf(_L("Created netdb OK\n"));
       
   526 			}
       
   527 		else// if(ret<KErrNone)
       
   528 			{
       
   529 			test.Printf(_L("Failed to open netdb, return = %d\n"),ret); 
       
   530 			goto end;
       
   531 			}
       
   532 
       
   533 		// Do a version inquiry...
       
   534 
       
   535 
       
   536 		FOREVER
       
   537 			{
       
   538 			test.Printf(_L("\n==================\nPress x to exit\ns to do a service search, a to get server version list\nS to search for a used service record, A to do search and attribs\nN for crazy newing tests\n==================\n"));
       
   539 			TChar c = test.Getch(); 
       
   540 			switch (c)
       
   541 				{
       
   542 			case 'x':
       
   543 				goto end;
       
   544 			case 'S':
       
   545 			case 'A':
       
   546 				{
       
   547 				sa.Connect(devAddr, stat);
       
   548 				User::WaitForRequest(stat);
       
   549 				if (stat!=KErrNone)
       
   550 					{
       
   551 					test.Printf(_L("Connect query failed with error: %d\r\n"), stat.Int());
       
   552 					goto end;
       
   553 					}
       
   554 				TSDPServiceSearchKey key;
       
   555 				for (uuid = 0; uuid < 0x300; ++uuid)
       
   556 					{
       
   557 					if (uuid%8 == 0)
       
   558 						test.Printf(_L("Using UUID 0x%04x\r"),uuid);
       
   559 					CSdpAttrValueDES* list = CSdpAttrValueDES::NewDESL(NULL);
       
   560 					MSdpElementBuilder* bldr = list;
       
   561 					CleanupStack::PushL(list);
       
   562 					bldr
       
   563 						->StartListL()
       
   564 							->BuildUUIDL(uuid)
       
   565 						->EndListL();
       
   566 
       
   567 					sa.SdpSearchRequestL(bufSize, *list, 0x20, contState, stat);
       
   568 					User::WaitForRequest(stat);
       
   569 					CleanupStack::PopAndDestroy(); //list
       
   570 					if (stat!=KErrNone)
       
   571 						{
       
   572 						test.Printf(_L("Failed with %d on search query\r\n"), stat.Int());
       
   573 						goto end;
       
   574 						}
       
   575 					HBufC8* bufS = HBufC8::NewMaxL(bufSize);
       
   576 					CleanupStack::PushL(bufS);
       
   577 					TPtr8 ptrS = bufS->Des();
       
   578 
       
   579 					sa.RetrieveResult(ptrS);
       
   580 					if (ptrS.Length() < 5)
       
   581 						{
       
   582 						CleanupStack::PopAndDestroy(); //bufS
       
   583 						continue;
       
   584 						}
       
   585 					len=BigEndian::Get16(&ptrS[2]);
       
   586 					if (len != 0)
       
   587 						{
       
   588 						if (len*4 > ptrS.Length() - 5)
       
   589 							{
       
   590 							test.Printf(_L("Bad length field %d on records length %d\r\n"),
       
   591 								len*4, ptrS.Length());
       
   592 							CleanupStack::PopAndDestroy(); //bufS
       
   593 							goto end;
       
   594 							}
       
   595 						test.Printf(_L("\nFound %d Service records for UUID 0x%04x\n"), len, uuid);
       
   596 						HexDump(ptrS.Mid(4, len*4));
       
   597 						if (c == 'A')
       
   598 							{
       
   599 							for (TInt rec=0;rec<len;++rec)
       
   600 								{
       
   601 								test.Printf(_L("Getting all Attributes for record %d..."), rec);
       
   602 								CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
   603 								CleanupStack::PushL(matchList);
       
   604 								matchList->AddL(TAttrRange(0x0000, 0xFFFF));
       
   605 								sa.SdpAttributeRequestL(bufSize, 
       
   606 														BigEndian::Get32(&ptrS[4+(rec*4)]),
       
   607 														maxAttrByteCount,
       
   608 														*matchList, 
       
   609 														contState, 
       
   610 														stat);
       
   611 								User::WaitForRequest(stat);
       
   612 								CleanupStack::PopAndDestroy(); //matchList
       
   613 								if (stat!=KErrNone)
       
   614 									{
       
   615 									test.Printf(_L("Failed with %d on attribute query\r\n"), stat.Int());
       
   616 									CleanupStack::PopAndDestroy(); //bufS
       
   617 									goto end;
       
   618 									}
       
   619 								HBufC8* bufA = HBufC8::NewMaxL(bufSize);
       
   620 								CleanupStack::PushL(bufA);
       
   621 								TPtr8 ptrA = bufA->Des();
       
   622 
       
   623 								sa.RetrieveResult(ptrA);
       
   624 								test.Printf(_L("... got attributes for record %d, Here's the result....\n"), rec);
       
   625 								// Parse aatribute list
       
   626 								CConsoleBuilder* builder = new(ELeave) CConsoleBuilder(*test.Console());
       
   627 								CleanupStack::PushL(builder);
       
   628 								CElementParser* parser = CElementParser::NewL(builder);
       
   629 								CleanupStack::PushL(parser);
       
   630 
       
   631 								TUint rem=0;
       
   632 								TRAPD(err,rem=parser->ParseElementsL(ptrA.Mid(2)));
       
   633 								if (err)
       
   634 									test.Printf(_L("Parser left with error %d - press any key\n"), err);
       
   635 								else
       
   636 									test.Printf(_L("Parser returned %d - press any key\n"), rem);
       
   637 								test.Getch();
       
   638 								CleanupStack::PopAndDestroy(3); //parser, builder, bufA
       
   639 								}
       
   640 							}
       
   641 						}
       
   642 					CleanupStack::PopAndDestroy(); //bufS
       
   643 					}
       
   644 				}
       
   645 				continue;
       
   646 			case 'N':
       
   647 				{
       
   648 				test.Next(_L("Crazy Newing test. Warning! Will OOM eventually..."));
       
   649 				for (TInt i = 0; i < 256; ++i)
       
   650 					{
       
   651 					test.Printf(_L("Firing off parallel query %d\r"),i);
       
   652 					RNetDatabase* n = new RNetDatabase;
       
   653 					while((ret=n->Open(ss,KBTAddrFamily,KSDP)) == KErrServerBusy)
       
   654 						{
       
   655 						test.Printf(_L("\nProblem getting in contact with esock. Will try again\n"));
       
   656 						User::After(2);
       
   657 						};
       
   658 					test(ret == KErrNone);
       
   659 					TRequestStatus *r = new TRequestStatus;
       
   660 					connQ.iQueryType = KSDPConnectQuery;
       
   661 					connQ.iAddr = devAddr;
       
   662 					result.SetMax();
       
   663 					while((ret=n->Query(TSDPConnectBuf(connQ), result)) == KErrServerBusy)
       
   664 						{
       
   665 						test.Printf(_L("\nProblem getting in contact with esock. Will try again\n"));
       
   666 						User::After(2);
       
   667 						};
       
   668 					test(ret == KErrNone);
       
   669 					TSDPAttributeKey key;
       
   670 					key.iQueryType = KSDPAttributeQuery;
       
   671 					key.iServiceRecordHandle = 0;
       
   672 					key.iMaxLength = 100;
       
   673 					key.iRange = ETrue;
       
   674 					key.iAttribute = 0x0000FFFF;
       
   675 					key.iStateLength = 0;
       
   676 					result.SetMax();
       
   677 					n->Query(TSDPAttributeKeyBuf(key), result, *r);
       
   678 					continue;
       
   679 					}
       
   680 				}
       
   681 			case 's':
       
   682 				{
       
   683 				test.Next(_L("Doing a service Search Query..."));
       
   684 				test.Printf(_L("Using UUID %04x\n"),uuid);
       
   685 				sa.Connect(devAddr, stat);
       
   686 				User::WaitForRequest(stat);
       
   687 				if (stat!=KErrNone)
       
   688 					{
       
   689 					test.Printf(_L("Connect query failed with error: %d\r\n"), stat.Int());
       
   690 					goto end;
       
   691 					}
       
   692 
       
   693 				
       
   694 				CSdpAttrValueDES* list = CSdpAttrValueDES::NewDESL(NULL);
       
   695 				MSdpElementBuilder* bldr= list;
       
   696 				CleanupStack::PushL(list);
       
   697 
       
   698 				bldr
       
   699 					->StartListL()
       
   700 						->BuildUUIDL(uuid++)
       
   701 						//->BuildUUIDL(TUUID(TUint32(0x11112222), TUint32(0x33334444), 
       
   702 						//					  TUint32(0x55556666), TUint32(0x77778888)))
       
   703 						//->BuildUUIDL(TUUID(TUint32(0x40000)))
       
   704 					->EndListL();
       
   705 				if(uuid>=0x1105||uuid<0x1100)
       
   706 					uuid = 0x1100;
       
   707 				sa.SdpSearchRequestL(bufSize, *list, 20, contState, stat);
       
   708 				User::WaitForRequest(stat);
       
   709 				if (stat!=KErrNone)
       
   710 					{
       
   711 					test.Printf(_L("Failed with %d on search query\r\n"), stat.Int());
       
   712 					CleanupStack::PopAndDestroy(); //list
       
   713 					goto end;
       
   714 					}
       
   715 				HBufC8* buf = HBufC8::NewMaxLC(bufSize);
       
   716 				TPtr8 ptr = buf->Des();
       
   717 				ptr.SetMax();
       
   718 				sa.RetrieveResult(ptr);
       
   719 				test.Printf(_L("Successful query!!\r\nHere's the result....\n"));
       
   720 				HexDump(ptr);
       
   721 				CleanupStack::PopAndDestroy(2); //list, buf
       
   722 				}
       
   723 				continue;
       
   724 			case 'a':
       
   725 				{
       
   726 				test.Next(_L("Doing a service Attribute Query..."));
       
   727 				sa.Connect(devAddr, stat);
       
   728 				User::WaitForRequest(stat);
       
   729 				if (stat!=KErrNone)
       
   730 					{
       
   731 					test.Printf(_L("Connect query failed with error: %d\r\n"), stat.Int());
       
   732 					goto end;
       
   733 					}
       
   734 				CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
   735 				CleanupStack::PushL(matchList);
       
   736 				matchList->AddL(TAttrRange(0x0000, 0xFFFF));
       
   737 				sa.SdpAttributeRequestL(bufSize, 
       
   738 										0,
       
   739 										maxAttrByteCount,
       
   740 										*matchList, 
       
   741 										contState, 
       
   742 										stat);
       
   743 				User::WaitForRequest(stat);
       
   744 				if (stat!=KErrNone)
       
   745 					{
       
   746 					test.Printf(_L("Failed with %d on attribute query\r\n"), stat.Int());
       
   747 					CleanupStack::PopAndDestroy(); //matchList
       
   748 					goto end;
       
   749 					}
       
   750 				HBufC8* buf = HBufC8::NewMaxLC(bufSize);
       
   751 				TPtr8 ptr = buf->Des();
       
   752 				ptr.SetMax();
       
   753 				sa.RetrieveResult(ptr);
       
   754 				test.Printf(_L("Successful query!!\r\nHere's the result....\n"));
       
   755 				HexDump(ptr);
       
   756 				CleanupStack::PopAndDestroy(2); //matchList, buf
       
   757 				}
       
   758 				continue;
       
   759 			default:
       
   760 				continue;
       
   761 				}
       
   762 			}
       
   763 
       
   764 end:
       
   765 		test.Next(_L("\r\nClosing netdb... "));			// CLOSING NETDB
       
   766 		test.Getch();
       
   767 		sa.Close();
       
   768 		test.Printf(_L("\r\nPress c to reconnect, or x to quit"));
       
   769 		}
       
   770 	while(test.Getch() == 'c');
       
   771 	ss.Close();									// CLOSING SOCKSERV 
       
   772 	test.End();			
       
   773 	}
       
   774 
       
   775 
       
   776 class CSdpResultReceiver : public CBase, public MSdpAgentNotifier
       
   777 	{
       
   778 public:
       
   779 	virtual ~CSdpResultReceiver();
       
   780 	void SetAgent(CSdpAgent* aAgent)
       
   781 		{
       
   782 		iAgent = aAgent;
       
   783 		};
       
   784 	virtual void HandleTimeout(){};
       
   785 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount) = 0;
       
   786 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttr) = 0;
       
   787 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError) = 0;
       
   788 protected:
       
   789 	void ConstructL();
       
   790 	CSdpResultReceiver(CConsoleBase& aConsole) 
       
   791 	:iConsole(aConsole), iBuilder(0), iAgent(0)
       
   792 		{
       
   793 		iCounter = 0;
       
   794 		};
       
   795 protected:
       
   796 	TInt				iCounter;
       
   797 	CConsoleBase&		iConsole;
       
   798 	TInt				iIndent;
       
   799 	CConsoleBuilder*	iBuilder;
       
   800 	CSdpAgent*			iAgent;
       
   801 	};
       
   802 
       
   803 CSdpResultReceiver::~CSdpResultReceiver()
       
   804 	{
       
   805 	delete iBuilder;
       
   806 	}
       
   807 
       
   808 void CSdpResultReceiver::ConstructL()
       
   809 	{
       
   810 	iBuilder = new(ELeave)CConsoleBuilder(iConsole);
       
   811 	}
       
   812 
       
   813 /**
       
   814 	Allow a timeout for SDP agent tests
       
   815 **/
       
   816 class CTestTimeout : public CTimer
       
   817 	{
       
   818 public:
       
   819 	static CTestTimeout* NewLC( CSdpResultReceiver& aParent);
       
   820 	static CTestTimeout* NewL( CSdpResultReceiver& aParent);
       
   821 	~CTestTimeout();
       
   822 	void IssueRequest(TInt aConnectionTime);
       
   823 	void RunL();
       
   824 	void DoCancel();
       
   825 private:
       
   826 	void ConstructL( );
       
   827 	CTestTimeout( CSdpResultReceiver& aParent);
       
   828 private:
       
   829 	CSdpResultReceiver& iParent;
       
   830 	
       
   831 	};
       
   832 
       
   833 CTestTimeout* CTestTimeout::NewL( CSdpResultReceiver& aParent)
       
   834 	{
       
   835 	CTestTimeout* self = CTestTimeout::NewLC(aParent);
       
   836 	CleanupStack::Pop();
       
   837 	return self;
       
   838 	}
       
   839 
       
   840 CTestTimeout* CTestTimeout::NewLC( CSdpResultReceiver& aParent)
       
   841 	{
       
   842 	CTestTimeout* self = new(ELeave) CTestTimeout( aParent);
       
   843 	CleanupStack::PushL(self);
       
   844 	self->ConstructL();
       
   845 	return self;
       
   846 	}
       
   847 
       
   848 CTestTimeout::CTestTimeout( CSdpResultReceiver& aParent )
       
   849 	: CTimer(EPriorityStandard),
       
   850 	iParent(aParent)
       
   851 	{
       
   852 	}
       
   853 
       
   854 CTestTimeout::~CTestTimeout()
       
   855 	{
       
   856 	Cancel();
       
   857 	}
       
   858 
       
   859 void CTestTimeout::IssueRequest(TInt aConnectionTime)
       
   860 	{
       
   861 	After(aConnectionTime*1000000);
       
   862 	}
       
   863 
       
   864 
       
   865 void CTestTimeout::RunL()
       
   866 	{
       
   867 	iParent.HandleTimeout();
       
   868 	}
       
   869 
       
   870 void CTestTimeout::DoCancel()
       
   871 	{
       
   872 	CTimer::DoCancel();
       
   873 	}
       
   874 
       
   875 void CTestTimeout::ConstructL( )
       
   876 	{
       
   877 	CTimer::ConstructL();
       
   878 	CActiveScheduler::Add(this);
       
   879 	}
       
   880 
       
   881 
       
   882 
       
   883 
       
   884 class CSdpResultReceiverTest2 : public CSdpResultReceiver
       
   885 	{
       
   886 public:
       
   887 	static CSdpResultReceiverTest2* NewL(CConsoleBase& aConsole);
       
   888 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
   889 		{
       
   890 		iCounter++;
       
   891 		if(!iAgent || iCounter > aTotalRecordsCount || aError == KErrEof)
       
   892 			{
       
   893 			iCounter = 0;
       
   894 			CActiveScheduler::Stop();
       
   895 			return;
       
   896 			}
       
   897 		iConsole.SetPos(iIndent);
       
   898 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
   899 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
   900 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
   901 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
   902 		if(aError)
       
   903 			{
       
   904 			iAgent->NextRecordRequestL();
       
   905 			}
       
   906 		else
       
   907 			{
       
   908 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
   909 			CleanupStack::PushL(matchList);
       
   910 			matchList->AddL(TAttrRange(0x0000, 0xFFFF)); //getemall
       
   911 			iAgent->AttributeRequestL(aHandle, *matchList);
       
   912 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
   913 			}
       
   914 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
   915 		test.Getch();
       
   916 		};
       
   917 
       
   918 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
   919 		{
       
   920 		iConsole.SetPos(iIndent);
       
   921 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
   922 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
   923 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
   924 		delete aAttrValue; //ownership is passed here
       
   925 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
   926 		test.Getch();
       
   927 		if(!iAgent)
       
   928 			{
       
   929 			CActiveScheduler::Stop();
       
   930 			}
       
   931 		else
       
   932 			{
       
   933 			}
       
   934 		};
       
   935 
       
   936 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError)
       
   937 		{
       
   938 		iConsole.SetPos(iIndent);
       
   939 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
   940 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
   941 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
   942 		test.Getch();
       
   943 		if(!iAgent||aError)
       
   944 			{
       
   945 			CActiveScheduler::Stop();
       
   946 			return;
       
   947 			}
       
   948 		iAgent->NextRecordRequestL();
       
   949 		};
       
   950 private:
       
   951 	CSdpResultReceiverTest2(CConsoleBase& aConsole) :CSdpResultReceiver(aConsole){};
       
   952 	};
       
   953 
       
   954 CSdpResultReceiverTest2* CSdpResultReceiverTest2::NewL(CConsoleBase& aConsole)
       
   955 	{
       
   956 	CSdpResultReceiverTest2* self = new(ELeave) CSdpResultReceiverTest2(aConsole);
       
   957 	CleanupStack::PushL(self);
       
   958 	self->ConstructL();
       
   959 	CleanupStack::Pop();
       
   960 	return self;
       
   961 	}
       
   962 
       
   963 
       
   964 
       
   965 void Test2()
       
   966 /**
       
   967 	Test2()
       
   968 **/
       
   969 	{
       
   970 	test.Start(_L("Test 2 -- Published Agent API"));
       
   971 	CSdpResultReceiverTest2* rcvr = CSdpResultReceiverTest2::NewL(*test.Console());
       
   972 	CleanupStack::PushL(rcvr);
       
   973 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
   974 	rcvr->SetAgent(agent);
       
   975 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
   976 	CleanupStack::PushL(list);
       
   977 	list->AddL(0x1102);
       
   978 	list->AddL(0x0100);
       
   979 	agent->SetRecordFilterL(*list);
       
   980 	agent->NextRecordRequestL();
       
   981 	CActiveScheduler::Start();
       
   982 	test.Next(_L("\n\n\nEnd of test 2\n\n\n"));
       
   983 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
   984 
       
   985 	test.End();
       
   986 	}
       
   987 
       
   988 class CSdpResultReceiverTest3 : public CSdpResultReceiver
       
   989 	{
       
   990 public:
       
   991 	static CSdpResultReceiverTest3* NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList);
       
   992 
       
   993 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
   994 		{
       
   995 		iCounter++;
       
   996 		if(!iAgent||iCounter>aTotalRecordsCount||aError)
       
   997 			{
       
   998 			iCounter = 0;
       
   999 			CActiveScheduler::Stop();
       
  1000 			return;
       
  1001 			}
       
  1002 		iConsole.SetPos(iIndent);
       
  1003 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1004 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1005 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1006 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1007 		iConsole.Printf(_L("PRESS ANY KEY (***ESC*** TO STOP)\n"));
       
  1008 		TInt c = test.Getch();
       
  1009 		if(c==27)
       
  1010 			{
       
  1011 			iAgent->Cancel();
       
  1012 			CActiveScheduler::Stop();
       
  1013 			return;
       
  1014 			}
       
  1015 		else
       
  1016 			{
       
  1017 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1018 			CleanupStack::PushL(matchList);
       
  1019 			matchList->AddL(TAttrRange(0x0000, 0xFFFF)); //getemall
       
  1020 			iAgent->AttributeRequestL(aHandle, *matchList);
       
  1021 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1022 			}
       
  1023 
       
  1024 		};
       
  1025 
       
  1026 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1027 		{
       
  1028 		iConsole.SetPos(iIndent);
       
  1029 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1030 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1031 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1032 		CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(iConsole);
       
  1033 		//theVisitor->VisitAttributeValueL(*aAttrValue, aAttrValue->Type());
       
  1034 		aAttrValue->AcceptVisitorL(*theVisitor);
       
  1035 		delete theVisitor;
       
  1036 		iConsole.Printf(_L("\nPRESS ANY KEY\n"));
       
  1037 		test.Getch();
       
  1038 		delete aAttrValue; //ownership is passed here
       
  1039 		//if(iCounter>1)
       
  1040 		//	User::Leave(KErrCompletion);
       
  1041 		if(!iAgent)
       
  1042 			{
       
  1043 			CActiveScheduler::Stop();
       
  1044 			return;
       
  1045 			}
       
  1046 		else
       
  1047 			{
       
  1048 			}
       
  1049 		};
       
  1050 
       
  1051 	virtual void AttributeRequestComplete(TSdpServRecordHandle /*aHandle*/, TInt aError)
       
  1052 		{
       
  1053 		iConsole.SetPos(iIndent);
       
  1054 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1055 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1056 		iConsole.Printf(_L("PRESS ANY KEY (***ESC*** TO STOP)\n"));
       
  1057 		TInt c = test.Getch();
       
  1058 		if(!iAgent||aError)
       
  1059 			{
       
  1060 			CActiveScheduler::Stop();
       
  1061 			return;
       
  1062 			}
       
  1063 		if(c==27)
       
  1064 			{
       
  1065 			iAgent->Cancel();
       
  1066 			CActiveScheduler::Stop();
       
  1067 			return;
       
  1068 			}
       
  1069 		else
       
  1070 			{
       
  1071 			iAgent->NextRecordRequestL();
       
  1072 			}
       
  1073 		};
       
  1074 	~CSdpResultReceiverTest3()
       
  1075 		{
       
  1076 		};
       
  1077 
       
  1078 private:
       
  1079 	CSdpResultReceiverTest3(CConsoleBase& aConsole, CSdpSearchPattern& aList) 
       
  1080 		:CSdpResultReceiver(aConsole), iList(aList)
       
  1081 		{
       
  1082 		};
       
  1083 	CSdpSearchPattern& iList;
       
  1084 	};
       
  1085 
       
  1086 CSdpResultReceiverTest3* CSdpResultReceiverTest3::NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList)
       
  1087 	{
       
  1088 	CSdpResultReceiverTest3* self = new(ELeave) CSdpResultReceiverTest3(aConsole, aList);
       
  1089 	CleanupStack::PushL(self);
       
  1090 	self->ConstructL();
       
  1091 	CleanupStack::Pop();
       
  1092 	return self;
       
  1093 	}
       
  1094 
       
  1095 
       
  1096 
       
  1097 
       
  1098 void Test3()
       
  1099 /**
       
  1100 	Test3()
       
  1101 **/
       
  1102 	{
       
  1103 	test.Start(_L("Test 3 -- Published Agent API"));
       
  1104 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1105 	CleanupStack::PushL(list);
       
  1106 	list->AddL(0x0100);
       
  1107 	CSdpResultReceiverTest3* rcvr = CSdpResultReceiverTest3::NewL(*test.Console(), *list);
       
  1108 	CleanupStack::PushL(rcvr);
       
  1109 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1110 	rcvr->SetAgent(agent);
       
  1111 	agent->SetRecordFilterL(*list);
       
  1112 	agent->NextRecordRequestL();
       
  1113 	CActiveScheduler::Start();
       
  1114 	test.Next(_L("\n\n\nEnd of test 3\n\n\n"));
       
  1115 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1116 	test.End();
       
  1117 	}
       
  1118 
       
  1119 class CSdpResultReceiverTest4 : public CSdpResultReceiver
       
  1120 	{
       
  1121 public:
       
  1122 	static CSdpResultReceiverTest4* NewL(CConsoleBase& aConsole);
       
  1123 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1124 		{
       
  1125 		iCounter++;
       
  1126 		if(!iAgent||iCounter>aTotalRecordsCount||aError)
       
  1127 			{
       
  1128 			iCounter = 0;
       
  1129 			CActiveScheduler::Stop();
       
  1130 			return;
       
  1131 			}
       
  1132 		iConsole.SetPos(iIndent);
       
  1133 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1134 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1135 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1136 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1137 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1138 		test.Getch();
       
  1139 		iAgent->NextRecordRequestL();
       
  1140 		};
       
  1141 
       
  1142 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1143 		{
       
  1144 		iConsole.SetPos(iIndent);
       
  1145 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1146 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1147 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1148 		delete aAttrValue; //ownership is passed here
       
  1149 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1150 		test.Getch();
       
  1151 		if(!iAgent)
       
  1152 			{
       
  1153 			CActiveScheduler::Stop();
       
  1154 			}
       
  1155 		else
       
  1156 			{
       
  1157 			}
       
  1158 
       
  1159 		};
       
  1160 
       
  1161 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError)
       
  1162 		{
       
  1163 		iConsole.SetPos(iIndent);
       
  1164 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1165 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1166 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1167 		test.Getch();
       
  1168 		if(!iAgent||aError)
       
  1169 			{
       
  1170 			CActiveScheduler::Stop();
       
  1171 			return;
       
  1172 			}
       
  1173 		iAgent->NextRecordRequestL();
       
  1174 		};
       
  1175 private:
       
  1176 	CSdpResultReceiverTest4(CConsoleBase& aConsole) :CSdpResultReceiver(aConsole){};
       
  1177 	};
       
  1178 
       
  1179 CSdpResultReceiverTest4* CSdpResultReceiverTest4::NewL(CConsoleBase& aConsole)
       
  1180 	{
       
  1181 	CSdpResultReceiverTest4* self = new(ELeave) CSdpResultReceiverTest4(aConsole);
       
  1182 	CleanupStack::PushL(self);
       
  1183 	self->ConstructL();
       
  1184 	CleanupStack::Pop();
       
  1185 	return self;
       
  1186 	}
       
  1187 
       
  1188 
       
  1189 
       
  1190 void Test4()
       
  1191 /**
       
  1192 	Test4()
       
  1193 **/
       
  1194 	{
       
  1195 	test.Start(_L("Test 4 -- Published Agent API"));
       
  1196 	CSdpResultReceiverTest4* rcvr = CSdpResultReceiverTest4::NewL(*test.Console());
       
  1197 	CleanupStack::PushL(rcvr);
       
  1198 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1199 	rcvr->SetAgent(agent);
       
  1200 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1201 	CleanupStack::PushL(list);
       
  1202 	//Use serial port UUID
       
  1203 	// - This is used in 165+ service records in our 
       
  1204 	//   prequal test SDP database.
       
  1205 	list->AddL(0x1101); 
       
  1206 	agent->SetRecordFilterL(*list);
       
  1207 	agent->NextRecordRequestL();
       
  1208 	CActiveScheduler::Start();
       
  1209 	test.Next(_L("\n\n\nEnd of test 4\n\n\n"));
       
  1210 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1211 
       
  1212 	test.End();
       
  1213 	}
       
  1214 
       
  1215 
       
  1216 class CSdpResultReceiverTest5 : public CSdpResultReceiver
       
  1217 	{
       
  1218 public:
       
  1219 	static CSdpResultReceiverTest5* NewL(CConsoleBase& aConsole);
       
  1220 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1221 		{
       
  1222 		iCounter++;
       
  1223 		if(!iAgent || iCounter > aTotalRecordsCount || aError == KErrEof)
       
  1224 			{
       
  1225 			iCounter = 0;
       
  1226 			CActiveScheduler::Stop();
       
  1227 			return;
       
  1228 			}
       
  1229 		iConsole.SetPos(iIndent);
       
  1230 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1231 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1232 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1233 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1234 		if(aError)
       
  1235 			{
       
  1236 			iAgent->NextRecordRequestL();
       
  1237 			}
       
  1238 		else
       
  1239 			{
       
  1240 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1241 			CleanupStack::PushL(matchList);
       
  1242 			matchList->AddL(TAttrRange(0x0000));
       
  1243 			iAgent->AttributeRequestL(aHandle, *matchList);
       
  1244 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1245 			}
       
  1246 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1247 		test.Getch();
       
  1248 		};
       
  1249 
       
  1250 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1251 		{
       
  1252 		iConsole.SetPos(iIndent);
       
  1253 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1254 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1255 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1256 		delete aAttrValue; //ownership is passed here
       
  1257 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1258 		test.Getch();
       
  1259 		if(!iAgent)
       
  1260 			{
       
  1261 			CActiveScheduler::Stop();
       
  1262 			}
       
  1263 		else
       
  1264 			{
       
  1265 			}
       
  1266 		};
       
  1267 
       
  1268 	virtual void AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError)
       
  1269 		{
       
  1270 		iConsole.SetPos(iIndent);
       
  1271 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1272 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1273 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1274 		test.Getch();
       
  1275 		if(!iAgent||aError||iARCounter>=4)
       
  1276 			{
       
  1277 			iARCounter = 0;
       
  1278 			CActiveScheduler::Stop();
       
  1279 			return;
       
  1280 			}
       
  1281 		CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1282 		CleanupStack::PushL(matchList);
       
  1283 		switch(iARCounter)
       
  1284 			{
       
  1285 		case 0:
       
  1286 			matchList->AddL(TAttrRange(0x01, 0x02));
       
  1287 			break;
       
  1288 		case 1:
       
  1289 			matchList->AddL(TAttrRange(0x03, 0x04));
       
  1290 			break;
       
  1291 		case 2:
       
  1292 			matchList->AddL(TAttrRange(0x05));
       
  1293 			break;
       
  1294 		case 3:
       
  1295 			matchList->AddL(TAttrRange(0x06, 0x07));
       
  1296 			matchList->AddL(TAttrRange(0x0201));
       
  1297 			break;
       
  1298 		default:
       
  1299 			matchList->AddL(TAttrRange(0x0000, 0xffff)); //getemall
       
  1300 			break;
       
  1301 			}
       
  1302 		iAgent->AttributeRequestL(aHandle, *matchList);
       
  1303 		CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1304 		iARCounter++;
       
  1305 		};
       
  1306 private:
       
  1307 	CSdpResultReceiverTest5(CConsoleBase& aConsole) :CSdpResultReceiver(aConsole), iARCounter(0){};
       
  1308 	TUint iARCounter;
       
  1309 	};
       
  1310 
       
  1311 CSdpResultReceiverTest5* CSdpResultReceiverTest5::NewL(CConsoleBase& aConsole)
       
  1312 	{
       
  1313 	CSdpResultReceiverTest5* self = new(ELeave) CSdpResultReceiverTest5(aConsole);
       
  1314 	CleanupStack::PushL(self);
       
  1315 	self->ConstructL();
       
  1316 	CleanupStack::Pop();
       
  1317 	return self;
       
  1318 	}
       
  1319 
       
  1320 
       
  1321 void Test5()
       
  1322 /**
       
  1323 	Test5()
       
  1324 **/
       
  1325 	{
       
  1326 	test.Start(_L("Test 2 -- Published Agent API"));
       
  1327 	CSdpResultReceiverTest5* rcvr = CSdpResultReceiverTest5::NewL(*test.Console());
       
  1328 	CleanupStack::PushL(rcvr);
       
  1329 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1330 	rcvr->SetAgent(agent);
       
  1331 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1332 	CleanupStack::PushL(list);
       
  1333 	list->AddL(0x0100);
       
  1334 	agent->SetRecordFilterL(*list);
       
  1335 	agent->NextRecordRequestL();
       
  1336 	CActiveScheduler::Start();
       
  1337 	test.Next(_L("\n\n\nEnd of test 5\n\n\n"));
       
  1338 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1339 
       
  1340 	test.End();
       
  1341 	}
       
  1342 
       
  1343 
       
  1344 class CSdpResultReceiverTest6 : public CSdpResultReceiver
       
  1345 	{
       
  1346 public:
       
  1347 	static CSdpResultReceiverTest6* NewL(CConsoleBase& aConsole);
       
  1348 	~CSdpResultReceiverTest6();
       
  1349 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1350 		{
       
  1351 		iCounter++;
       
  1352 		if(!iAgent || iCounter > aTotalRecordsCount || aError == KErrEof)
       
  1353 			{
       
  1354 			iCounter = 0;
       
  1355 			CActiveScheduler::Stop();
       
  1356 			return;
       
  1357 			}
       
  1358 		iConsole.SetPos(iIndent);
       
  1359 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1360 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1361 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1362 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1363 		if(aError)
       
  1364 			{
       
  1365 			iAgent->NextRecordRequestL();
       
  1366 			}
       
  1367 		else
       
  1368 			{
       
  1369 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1370 			CleanupStack::PushL(matchList);
       
  1371 			matchList->AddL(TAttrRange(0x0000, 0x0007)); //get up to id 6
       
  1372 			iAgent->AttributeRequestL(iBuilder, aHandle, *matchList);
       
  1373 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1374 			}
       
  1375 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1376 		test.Getch();
       
  1377 		};
       
  1378 
       
  1379 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1380 		{
       
  1381 		iConsole.SetPos(iIndent);
       
  1382 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1383 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1384 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1385 		delete aAttrValue; //ownership is passed here
       
  1386 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1387 		test.Getch();
       
  1388 		if(!iAgent)
       
  1389 			{
       
  1390 			CActiveScheduler::Stop();
       
  1391 			}
       
  1392 		else
       
  1393 			{
       
  1394 			}
       
  1395 		};
       
  1396 
       
  1397 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError)
       
  1398 		{
       
  1399 		iConsole.SetPos(iIndent);
       
  1400 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1401 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1402 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1403 		test.Getch();
       
  1404 		if(!iAgent||aError)
       
  1405 			{
       
  1406 			CActiveScheduler::Stop();
       
  1407 			return;
       
  1408 			}
       
  1409 		iAgent->NextRecordRequestL();
       
  1410 		};
       
  1411 private:
       
  1412 	CSdpResultReceiverTest6(CConsoleBase& aConsole) :CSdpResultReceiver(aConsole){};
       
  1413 	void ConstructL();
       
  1414 private:
       
  1415 	CConsoleBuilder* iBuilder;
       
  1416 	};
       
  1417 
       
  1418 CSdpResultReceiverTest6* CSdpResultReceiverTest6::NewL(CConsoleBase& aConsole)
       
  1419 	{
       
  1420 	CSdpResultReceiverTest6* self = new(ELeave) CSdpResultReceiverTest6(aConsole);
       
  1421 	CleanupStack::PushL(self);
       
  1422 	self->ConstructL();
       
  1423 	CleanupStack::Pop();
       
  1424 	return self;
       
  1425 	}
       
  1426 
       
  1427 CSdpResultReceiverTest6::~CSdpResultReceiverTest6()
       
  1428 	{
       
  1429 	delete iBuilder;
       
  1430 	}
       
  1431 
       
  1432 void CSdpResultReceiverTest6::ConstructL()
       
  1433 	{
       
  1434 	iBuilder = new(ELeave) CConsoleBuilder(iConsole);
       
  1435 	}
       
  1436 
       
  1437 void Test6()
       
  1438 /**
       
  1439 	Test6()
       
  1440 **/
       
  1441 	{
       
  1442 	test.Start(_L("Test 6 -- Published Agent API"));
       
  1443 	CSdpResultReceiverTest6* rcvr = CSdpResultReceiverTest6::NewL(*test.Console());
       
  1444 	CleanupStack::PushL(rcvr);
       
  1445 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1446 	rcvr->SetAgent(agent);
       
  1447 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1448 	CleanupStack::PushL(list);
       
  1449 	list->AddL(0x0100);
       
  1450 	agent->SetRecordFilterL(*list);
       
  1451 	agent->NextRecordRequestL();
       
  1452 	CActiveScheduler::Start();
       
  1453 	test.Next(_L("\n\n\nEnd of test 6\n\n\n"));
       
  1454 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1455 
       
  1456 	test.End();
       
  1457 	}
       
  1458 
       
  1459 void Test7()
       
  1460 /**
       
  1461 	Test7()
       
  1462 **/
       
  1463 	{
       
  1464 	test.Start(_L("Test 7 -- Published Agent API"));
       
  1465 	CSdpVerificationTests::RunTestL(*test.Console());
       
  1466 	test.Next(_L("\n\n\nEnd of test 7\n\n\n"));
       
  1467 
       
  1468 	test.End();
       
  1469 	}
       
  1470 
       
  1471 class CSdpResultReceiverTest8 : public CSdpResultReceiver
       
  1472 	{
       
  1473 public:
       
  1474 	static CSdpResultReceiverTest8* NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList);
       
  1475 	void HandleTimeout()
       
  1476 		{
       
  1477 		iCounter = 0;
       
  1478 		CActiveScheduler::Stop();
       
  1479 		return;
       
  1480 		};
       
  1481 
       
  1482 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1483 		{
       
  1484 		iCounter++;
       
  1485 		if(!iAgent||iCounter>aTotalRecordsCount||aError)
       
  1486 			{
       
  1487 			iCounter = 0;
       
  1488 			CActiveScheduler::Stop();
       
  1489 			return;
       
  1490 			}
       
  1491 		iConsole.SetPos(iIndent);
       
  1492 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1493 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1494 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1495 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1496 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1497 		test.Getch();
       
  1498 		iAgent->NextRecordRequestL();
       
  1499 		};
       
  1500 
       
  1501 
       
  1502 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1503 		{
       
  1504 		iConsole.SetPos(iIndent);
       
  1505 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1506 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1507 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1508 		CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(iConsole);
       
  1509 		//theVisitor->VisitAttributeValueL(*aAttrValue, aAttrValue->Type());
       
  1510 		aAttrValue->AcceptVisitorL(*theVisitor);
       
  1511 		delete theVisitor;
       
  1512 		iConsole.Printf(_L("\nPRESS ANY KEY\n"));
       
  1513 		test.Getch();
       
  1514 		delete aAttrValue; //ownership is passed here
       
  1515 		//if(iCounter>1)
       
  1516 		//	User::Leave(KErrCompletion);
       
  1517 		if(!iAgent)
       
  1518 			{
       
  1519 			CActiveScheduler::Stop();
       
  1520 			return;
       
  1521 			}
       
  1522 		else
       
  1523 			{
       
  1524 			}
       
  1525 		};
       
  1526 
       
  1527 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError)
       
  1528 		{
       
  1529 		iConsole.SetPos(iIndent);
       
  1530 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1531 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1532 		iConsole.Printf(_L("PRESS ANY KEY (***ESC*** TO STOP)\n"));
       
  1533 		TInt c = test.Getch();
       
  1534 		if(!iAgent||aError)
       
  1535 			{
       
  1536 			CActiveScheduler::Stop();
       
  1537 			return;
       
  1538 			}
       
  1539 		if(c==27)
       
  1540 			{
       
  1541 			iAgent->Cancel();
       
  1542 			CActiveScheduler::Stop();
       
  1543 			return;
       
  1544 			}
       
  1545 		iAgent->NextRecordRequestL();
       
  1546 		};
       
  1547 	~CSdpResultReceiverTest8()
       
  1548 		{
       
  1549 		iTimeout->Cancel();
       
  1550 		delete iTimeout;
       
  1551 		};
       
  1552 
       
  1553 private:
       
  1554 	void ConstructL();
       
  1555 private:
       
  1556 	CSdpResultReceiverTest8(CConsoleBase& aConsole, CSdpSearchPattern& aList) 
       
  1557 		:CSdpResultReceiver(aConsole), iTimeout(0), iList(aList)
       
  1558 		{
       
  1559 		iTimeoutCounter = 0;
       
  1560 		iDelay = 1;
       
  1561 		};
       
  1562     TInt iTimeoutCounter;
       
  1563 	CTestTimeout* iTimeout;
       
  1564 	TInt iDelay;
       
  1565 	TInt iRenew;
       
  1566 	CSdpSearchPattern& iList;
       
  1567 	};
       
  1568 
       
  1569 CSdpResultReceiverTest8* CSdpResultReceiverTest8::NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList)
       
  1570 	{
       
  1571 	CSdpResultReceiverTest8* self = new(ELeave) CSdpResultReceiverTest8(aConsole, aList);
       
  1572 	CleanupStack::PushL(self);
       
  1573 	self->ConstructL();
       
  1574 	CleanupStack::Pop();
       
  1575 	return self;
       
  1576 	}
       
  1577 
       
  1578 void CSdpResultReceiverTest8::ConstructL()
       
  1579 	{
       
  1580 	iTimeout = CTestTimeout::NewL(*this);
       
  1581 	iTimeout->IssueRequest(iDelay);
       
  1582 	}
       
  1583 
       
  1584 
       
  1585 
       
  1586 void Test8()
       
  1587 /**
       
  1588 	Test8()
       
  1589 **/
       
  1590 	{
       
  1591 	test.Start(_L("Test 8 -- Published Agent API"));
       
  1592 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1593 	CleanupStack::PushL(list);
       
  1594 	list->AddL(0x0100);
       
  1595 	CSdpResultReceiverTest8* rcvr = CSdpResultReceiverTest8::NewL(*test.Console(), *list);
       
  1596 	CleanupStack::PushL(rcvr);
       
  1597 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1598 	rcvr->SetAgent(agent);
       
  1599 	agent->SetRecordFilterL(*list);
       
  1600 	agent->NextRecordRequestL();
       
  1601 	CActiveScheduler::Start();
       
  1602 	test.Next(_L("\n\n\nEnd of test 8\n\n\n"));
       
  1603 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1604 	test.End();
       
  1605 	}
       
  1606 
       
  1607 class CSdpResultReceiverTest9 : public CSdpResultReceiver
       
  1608 	{
       
  1609 public:
       
  1610 	static CSdpResultReceiverTest9* NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList);
       
  1611 	void HandleTimeout()
       
  1612 		{
       
  1613 		iAgent->Cancel();
       
  1614 		iConsole.Printf(_L("Type in an interrupt time delay, and THEN press..."));
       
  1615 		iConsole.Printf(_L("\n...return to restart"));
       
  1616 		iConsole.Printf(_L("\n...'d' to await next time out"));
       
  1617 		iConsole.Printf(_L("\n...'n' to restart and not do a further timeout"));
       
  1618 		iConsole.Printf(_L("\n...ESC to stop\n"));
       
  1619 		iDelay = 0;
       
  1620 		TInt c = test.Getch();
       
  1621 		TBool stop = EFalse;
       
  1622 		while(!stop)
       
  1623 			{
       
  1624 			switch(c)
       
  1625 				{
       
  1626 			case '0':
       
  1627 			case '1':
       
  1628 			case '2':
       
  1629 			case '3':
       
  1630 			case '4':
       
  1631 			case '5':
       
  1632 			case '6':
       
  1633 			case '7':
       
  1634 			case '8':
       
  1635 			case '9':
       
  1636 				iConsole.Printf(_L("%c"), c);
       
  1637 				iDelay*=10;
       
  1638 				iDelay+=(c - '0');
       
  1639 				c = test.Getch();
       
  1640 				break;
       
  1641 			case '\b':
       
  1642 				iDelay/=10;
       
  1643 				iConsole.Printf(_L("\b"));
       
  1644 				c = test.Getch();
       
  1645 				break;
       
  1646 			case 13:
       
  1647 				iAgent->SetRecordFilterL(iList);
       
  1648 				iAgent->NextRecordRequestL();
       
  1649 				iTimeout->IssueRequest(iDelay);
       
  1650 				stop = ETrue;
       
  1651 				break;
       
  1652 			case 'd':
       
  1653 			case 'D':
       
  1654 				iTimeout->IssueRequest(iDelay);
       
  1655 				stop = ETrue;
       
  1656 				break;
       
  1657 			case 'n':
       
  1658 			case 'N':
       
  1659 				iAgent->SetRecordFilterL(iList);
       
  1660 				iAgent->NextRecordRequestL();
       
  1661 				stop = ETrue;
       
  1662 				break;
       
  1663 			case 27:
       
  1664 				CActiveScheduler::Stop();
       
  1665 				stop = ETrue;
       
  1666 				break;
       
  1667 			default:
       
  1668 				c = test.Getch();
       
  1669 				break;
       
  1670 				}
       
  1671 			}
       
  1672 		iConsole.Printf(_L("\n"));
       
  1673 		};
       
  1674 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1675 		{
       
  1676 		iCounter++;
       
  1677 		if(iCounter==2)
       
  1678 			{
       
  1679 			User::Leave(KErrGeneral);
       
  1680 			}
       
  1681 		if(!iAgent||aError==KErrEof)
       
  1682 			{
       
  1683 			iCounter = 0;
       
  1684 			CActiveScheduler::Stop();
       
  1685 			return;
       
  1686 			}
       
  1687 		if(iCounter>aTotalRecordsCount)
       
  1688 			{
       
  1689 			iCounter = 0;
       
  1690 			}
       
  1691 		iConsole.SetPos(iIndent);
       
  1692 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1693 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1694 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1695 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1696 		iConsole.Printf(_L("PRESS ANY KEY (***ESC*** TO STOP)\n"));
       
  1697 		TInt c = test.Getch();
       
  1698 		if(c==27)
       
  1699 			{
       
  1700 			iAgent->Cancel();
       
  1701 			CActiveScheduler::Stop();
       
  1702 			return;
       
  1703 			}
       
  1704 		if(aError!=KErrNone)
       
  1705 			{
       
  1706 			iAgent->SetRecordFilterL(iList);
       
  1707 			iAgent->NextRecordRequestL();
       
  1708 			}
       
  1709 		else
       
  1710 			{
       
  1711 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1712 			CleanupStack::PushL(matchList);
       
  1713 			matchList->AddL(TAttrRange(0x0000, 0xFFFF)); //getemall
       
  1714 			iAgent->AttributeRequestL(aHandle, *matchList);
       
  1715 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1716 			}
       
  1717 
       
  1718 		};
       
  1719 
       
  1720 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1721 		{
       
  1722 		iConsole.SetPos(iIndent);
       
  1723 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1724 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1725 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1726 		CAttrPrintVisitor* theVisitor = new CAttrPrintVisitor(iConsole);
       
  1727 		//theVisitor->VisitAttributeValueL(*aAttrValue, aAttrValue->Type());
       
  1728 		aAttrValue->AcceptVisitorL(*theVisitor);
       
  1729 		delete theVisitor;
       
  1730 		iConsole.Printf(_L("\nPRESS ANY KEY\n"));
       
  1731 		test.Getch();
       
  1732 		delete aAttrValue; //ownership is passed here
       
  1733 		//if(iCounter>1)
       
  1734 		//	User::Leave(KErrCompletion);
       
  1735 		if(!iAgent)
       
  1736 			{
       
  1737 			CActiveScheduler::Stop();
       
  1738 			return;
       
  1739 			}
       
  1740 		else
       
  1741 			{
       
  1742 			}
       
  1743 		};
       
  1744 
       
  1745 	virtual void AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError)
       
  1746 		{
       
  1747 		iConsole.SetPos(iIndent);
       
  1748 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1749 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1750 		iConsole.Printf(_L("PRESS ANY KEY (***ESC*** TO STOP)\n"));
       
  1751 		TInt c = test.Getch();
       
  1752 		if(!iAgent||aError==KErrEof)
       
  1753 			{
       
  1754 			CActiveScheduler::Stop();
       
  1755 			return;
       
  1756 			}
       
  1757 		if(c==27)
       
  1758 			{
       
  1759 			iAgent->Cancel();
       
  1760 			CActiveScheduler::Stop();
       
  1761 			return;
       
  1762 			}
       
  1763 		if(aError)
       
  1764 		//try again
       
  1765 			{
       
  1766 			CSdpAttrIdMatchList* matchList = CSdpAttrIdMatchList::NewL();
       
  1767 			CleanupStack::PushL(matchList);
       
  1768 			matchList->AddL(TAttrRange(0x0000, 0xFFFF)); //getemall
       
  1769 			iAgent->AttributeRequestL(aHandle, *matchList);
       
  1770 			CleanupStack::PopAndDestroy(); //matchList - AttributeRequestL makes a copy
       
  1771 			}
       
  1772 		else
       
  1773 			{
       
  1774 			iAgent->NextRecordRequestL();
       
  1775 			}
       
  1776 		};
       
  1777 	~CSdpResultReceiverTest9()
       
  1778 		{
       
  1779 		iTimeout->Cancel();
       
  1780 		delete iTimeout;
       
  1781 		};
       
  1782 
       
  1783 private:
       
  1784 	void ConstructL();
       
  1785 private:
       
  1786 	CSdpResultReceiverTest9(CConsoleBase& aConsole, CSdpSearchPattern& aList) 
       
  1787 		:CSdpResultReceiver(aConsole), iTimeout(0), iList(aList)
       
  1788 		{
       
  1789 		iTimeoutCounter = 0;
       
  1790 		iDelay = 5;
       
  1791 		};
       
  1792     TInt iTimeoutCounter;
       
  1793 	CTestTimeout* iTimeout;
       
  1794 	TInt iDelay;
       
  1795 	TInt iRenew;
       
  1796 	CSdpSearchPattern& iList;
       
  1797 	};
       
  1798 
       
  1799 CSdpResultReceiverTest9* CSdpResultReceiverTest9::NewL(CConsoleBase& aConsole, CSdpSearchPattern& aList)
       
  1800 	{
       
  1801 	CSdpResultReceiverTest9* self = new(ELeave) CSdpResultReceiverTest9(aConsole, aList);
       
  1802 	CleanupStack::PushL(self);
       
  1803 	self->ConstructL();
       
  1804 	CleanupStack::Pop();
       
  1805 	return self;
       
  1806 	}
       
  1807 
       
  1808 void CSdpResultReceiverTest9::ConstructL()
       
  1809 	{
       
  1810 	iTimeout = CTestTimeout::NewL(*this);
       
  1811 	iTimeout->IssueRequest(iDelay);
       
  1812 	}
       
  1813 
       
  1814 
       
  1815 
       
  1816 void Test9()
       
  1817 /**
       
  1818 	Test9()
       
  1819 **/
       
  1820 	{
       
  1821 	test.Start(_L("Test 9 -- Published Agent API"));
       
  1822 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1823 	CleanupStack::PushL(list);
       
  1824 	list->AddL(0x0100);
       
  1825 	CSdpResultReceiverTest9* rcvr = CSdpResultReceiverTest9::NewL(*test.Console(), *list);
       
  1826 	CleanupStack::PushL(rcvr);
       
  1827 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1828 	rcvr->SetAgent(agent);
       
  1829 	agent->SetRecordFilterL(*list);
       
  1830 	agent->NextRecordRequestL();
       
  1831 	CActiveScheduler::Start();
       
  1832 	test.Next(_L("\n\n\nEnd of test 9\n\n\n"));
       
  1833 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1834 	test.End();
       
  1835 	}
       
  1836 
       
  1837 
       
  1838 
       
  1839 class CSdpResultReceiverTest0 : public CSdpResultReceiver
       
  1840 	{
       
  1841 public:
       
  1842 	static CSdpResultReceiverTest0* NewL(CConsoleBase& aConsole);
       
  1843 	virtual void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount)
       
  1844 		{
       
  1845 		iCounter++;
       
  1846 		if(iCounter==2)
       
  1847 			{
       
  1848 			User::Leave(KErrGeneral);
       
  1849 			}
       
  1850 		if(!iAgent||(iCounter>aTotalRecordsCount && aError==KErrNone))
       
  1851 			{
       
  1852 			iCounter = 0;
       
  1853 			CActiveScheduler::Stop();
       
  1854 			return;
       
  1855 			}
       
  1856 		iConsole.SetPos(iIndent);
       
  1857 		iConsole.Printf(_L("\n\nNextRecordRequestComplete\n"));
       
  1858 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1859 		iConsole.Printf(_L("Got Total Records Count: <%d>\n"), aTotalRecordsCount);
       
  1860 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1861 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1862 		test.Getch();
       
  1863 		iAgent->NextRecordRequestL();
       
  1864 		};
       
  1865 
       
  1866 	virtual void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue)
       
  1867 		{
       
  1868 		iConsole.SetPos(iIndent);
       
  1869 		iConsole.Printf(_L("\n\nAttributeRequestResult\n"));
       
  1870 		iConsole.Printf(_L("Got Handle: <0x%x>\n"), aHandle);
       
  1871 		iConsole.Printf(_L("Got Attribute: ID is: <0x%04x>\n"), aAttrID);
       
  1872 		delete aAttrValue; //ownership is passed here
       
  1873 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1874 		test.Getch();
       
  1875 		if(!iAgent)
       
  1876 			{
       
  1877 			CActiveScheduler::Stop();
       
  1878 			}
       
  1879 		else
       
  1880 			{
       
  1881 			}
       
  1882 
       
  1883 		};
       
  1884 
       
  1885 	virtual void AttributeRequestComplete(TSdpServRecordHandle, TInt aError)
       
  1886 		{
       
  1887 		iConsole.SetPos(iIndent);
       
  1888 		iConsole.Printf(_L("\n\nAttributeRequestComplete\n"));
       
  1889 		iConsole.Printf(_L("Got Error: <%d>\n"), aError);
       
  1890 		iConsole.Printf(_L("PRESS ANY KEY\n"));
       
  1891 		test.Getch();
       
  1892 		if(!iAgent||aError)
       
  1893 			{
       
  1894 			CActiveScheduler::Stop();
       
  1895 			return;
       
  1896 			}
       
  1897 		iAgent->NextRecordRequestL();
       
  1898 		};
       
  1899 private:
       
  1900 	CSdpResultReceiverTest0(CConsoleBase& aConsole) :CSdpResultReceiver(aConsole){};
       
  1901 	};
       
  1902 
       
  1903 CSdpResultReceiverTest0* CSdpResultReceiverTest0::NewL(CConsoleBase& aConsole)
       
  1904 	{
       
  1905 	CSdpResultReceiverTest0* self = new(ELeave) CSdpResultReceiverTest0(aConsole);
       
  1906 	CleanupStack::PushL(self);
       
  1907 	self->ConstructL();
       
  1908 	CleanupStack::Pop();
       
  1909 	return self;
       
  1910 	}
       
  1911 
       
  1912 
       
  1913 
       
  1914 void Test0()
       
  1915 /**
       
  1916 	Test0()
       
  1917 **/
       
  1918 	{
       
  1919 	test.Start(_L("Test 0 -- Published Agent API"));
       
  1920 	CSdpResultReceiverTest0* rcvr = CSdpResultReceiverTest0::NewL(*test.Console());
       
  1921 	CleanupStack::PushL(rcvr);
       
  1922 	CSdpAgent* agent = CSdpAgent::NewLC(*rcvr, devAddr);
       
  1923 	rcvr->SetAgent(agent);
       
  1924 	CSdpSearchPattern* list = CSdpSearchPattern::NewL();
       
  1925 	CleanupStack::PushL(list);
       
  1926 	list->AddL(0x0100);
       
  1927 	agent->SetRecordFilterL(*list);
       
  1928 	agent->NextRecordRequestL();
       
  1929 	CActiveScheduler::Start();
       
  1930 	test.Next(_L("\n\n\nEnd of test 0\n\n\n"));
       
  1931 	CleanupStack::PopAndDestroy(3); //list, agent, rcvr
       
  1932 
       
  1933 	test.End();
       
  1934 	}
       
  1935 
       
  1936 void GetDeviceAddressL()
       
  1937 	{
       
  1938 	RNotifier notifier;
       
  1939     notifier.Connect();
       
  1940     TBTDeviceSelectionParamsPckg pckg;
       
  1941     TBTDeviceResponseParamsPckg resPckg;
       
  1942     //TBTDevAddrPckg resPckg;
       
  1943     TRequestStatus stat;
       
  1944     notifier.StartNotifierAndGetResponse(stat, KDeviceSelectionNotifierUid, pckg, resPckg);
       
  1945     User::WaitForRequest(stat);
       
  1946     notifier.CancelNotifier(KDeviceSelectionNotifierUid);
       
  1947     notifier.Close();
       
  1948     User::LeaveIfError(stat.Int());
       
  1949 	devAddr = resPckg().BDAddr();
       
  1950 
       
  1951 	TBTDeviceName dname = resPckg().DeviceName();
       
  1952 	TBTDeviceClass dclass = resPckg().DeviceClass();
       
  1953 	return;
       
  1954 	}
       
  1955 
       
  1956 void RunTest(TChar aUserSelection)
       
  1957 	{
       
  1958 	__UHEAP_MARK;
       
  1959 
       
  1960 	switch (aUserSelection)
       
  1961 		{
       
  1962 	case 'A':
       
  1963 	case 'a':
       
  1964 		TRAPD(errA, GetDeviceAddressL());
       
  1965 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, errA);
       
  1966 		break;
       
  1967 	case '1':
       
  1968 		TRAPD(err1, Test1());
       
  1969 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err1);
       
  1970 		break;
       
  1971 	case '2':
       
  1972 		TRAPD(err2, Test2());
       
  1973 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err2);
       
  1974 		break;
       
  1975 	case '3':
       
  1976 		TRAPD(err3, Test3());
       
  1977 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err3);
       
  1978 		break;
       
  1979 	case '4':
       
  1980 		TRAPD(err4, Test4());
       
  1981 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err4);
       
  1982 		break;
       
  1983 	case '5':
       
  1984 		TRAPD(err5, Test5());
       
  1985 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err5);
       
  1986 		break;
       
  1987 	case '6':
       
  1988 		TRAPD(err6, Test6());
       
  1989 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err6);
       
  1990 		break;
       
  1991 	case '7':
       
  1992 		TRAPD(err7, Test7());
       
  1993 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err7);
       
  1994 		break;
       
  1995 	case '8':
       
  1996 		TRAPD(err8, Test8());
       
  1997 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err8);
       
  1998 		break;
       
  1999 	case '9':
       
  2000 		TRAPD(err9, Test9());
       
  2001 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err9);
       
  2002 		break;
       
  2003 	case '0':
       
  2004 		TRAPD(err0, Test0());
       
  2005 		test.Printf(_L("Test %c finished with result %d\n"), (TUint) aUserSelection, err0);
       
  2006 		break;
       
  2007 	default:
       
  2008 		test.Printf(_L("Unknown command\r\n"));
       
  2009 		break;
       
  2010 		};		
       
  2011 	__UHEAP_MARKEND;	
       
  2012 	}
       
  2013 	
       
  2014 TInt E32Main()
       
  2015 	{
       
  2016 
       
  2017 	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
       
  2018 
       
  2019 //	TInt ret;
       
  2020 	test.SetLogged(EFalse);
       
  2021 	test.Title();
       
  2022 	test.Start(_L("Loading SDP Protocol Module"));
       
  2023 // For some reason, you have to do the following to
       
  2024 // ensure that the file server behaves properly.
       
  2025 	RFs fs;
       
  2026 	(void)fs.Connect();
       
  2027 	fs.Close();
       
  2028 
       
  2029 	LoadLDD_PDD();	// Loading the LDD/PDD pair
       
  2030 
       
  2031 
       
  2032 
       
  2033 	//Shove it all in a TRAP harness to allow cleanup to work...
       
  2034 	TRAPD(
       
  2035 		err,
       
  2036 		CActiveScheduler *scheduler = new (ELeave) CActiveScheduler;
       
  2037 		CleanupStack::PushL(scheduler);
       
  2038 		CActiveScheduler::Install(scheduler); 
       
  2039 		FOREVER
       
  2040 			{
       
  2041 			test.Printf(_L("Choose the test to run...\r\n"));
       
  2042 			test.Printf(_L("************************\r\n"));
       
  2043 			test.Printf(_L("1. Open, connect\r\n"));
       
  2044 			test.Printf(_L("2. CSdpAgent API - UUIDs restrict to one record\r\n"));
       
  2045 			test.Printf(_L("3. CSdpAgent API - UUIDs allow 3 records\r\n"));
       
  2046 			test.Printf(_L("4. CSdpAgent API - Just do record requests\r\n"));
       
  2047 			test.Printf(_L("5. CSdpAgent API - Do one record request + 5 attr requests\r\n"));
       
  2048 			test.Printf(_L("6. CSdpAgent API - Provide own builder\r\n"));
       
  2049 			test.Printf(_L("7. CSdpAgent API - Attempt in-house SDP prequal\r\n"));
       
  2050 			test.Printf(_L("8. CSdpAgent API - Interrupted Request\r\n"));
       
  2051 			test.Printf(_L("9. CSdpAgent API - UUIDs allow 3 records - with Cancel Facility and Forced Error\r\n"));
       
  2052 			test.Printf(_L("0. CSdpAgent API - Just do record requests - with Forced Error\r\n"));
       
  2053 			test.Printf(_L("************************\r\n\r\n"));
       
  2054 			test.Printf(_L("A. Alter Remote Device Address From Default Value\r\n(NB This action needs a compiled TEXT NOTIFIER)\r\n\r\n"));
       
  2055 			test.Printf(_L("press Escape to quit\r\n\r\n"));
       
  2056 
       
  2057 			
       
  2058 			TChar c = test.Getch();
       
  2059 			if (c == EKeyEscape)
       
  2060 				{
       
  2061 				goto done;
       
  2062 				}
       
  2063 			else
       
  2064 				{
       
  2065 				RunTest(c);
       
  2066 				}
       
  2067 			}
       
  2068 		done:
       
  2069 		CleanupStack::PopAndDestroy(/*scheduler*/);
       
  2070 	); //end of TRAPD!!!!!!!!!!
       
  2071 	if (err)
       
  2072 		{
       
  2073 		test.Printf(_L("Failed to allocate a CActiveScheduler. err: %d!\n"), err);
       
  2074 		}
       
  2075 	
       
  2076 	test.Printf(_L("Finished! Press any key...\r\n"));
       
  2077 	test.Getch();
       
  2078 	test.End();
       
  2079 
       
  2080 	delete cleanup; // destroy clean-up stack
       
  2081 	return KErrNone;
       
  2082 	}