bluetooth/btexample/test/cit/ROMConfig/src/cteststepbtromconfiguser002.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 //
       
    15 
       
    16 #include "cteststepbtromconfiguser002.h"
       
    17 #include <bluetoothav.h>
       
    18 
       
    19 /**
       
    20    Unnamed namespaces are a superior replacement for the static
       
    21    declaration of variables. They allow variables and functions to be
       
    22    visible within an entire translation unit, yet not visible
       
    23    externally. Although entities in an unnamed namespace might have
       
    24    external linkage, they are effectively qualified by a name unique
       
    25    to their translation unit and therefore can never be seen from any
       
    26    other translation unit.
       
    27 */
       
    28 namespace
       
    29 	{
       
    30 	/** 
       
    31 		Panic string if an invalid test subcase is specified Panic
       
    32 		number is the invalid subcase
       
    33 	*/
       
    34 	_LIT(KInvalidTestPanicString, "Invalid Test subcase specified");
       
    35 	_LIT(KUnexpectedError, "Unexpected error");
       
    36 	_LIT(KProtocolSdp, "SDP");
       
    37 	_LIT(KProtocolBtLinkManager, "BTLinkManager");
       
    38 	_LIT(KProtocolAvctp, "AVCTP");
       
    39 	}
       
    40 
       
    41 CTestStepBtRomConfigUser002::~CTestStepBtRomConfigUser002()
       
    42 	{
       
    43 	if (iSocketServ.Handle())
       
    44 		{
       
    45 		iSocketServ.Close();
       
    46 		}
       
    47 	}
       
    48 
       
    49 CTestStepBtRomConfigUser002::CTestStepBtRomConfigUser002(CTestServer& aParent) 
       
    50 	: CTestStepBtRomConfigBase(aParent)
       
    51 	{
       
    52 	SetTestStepName(KTestNameUser002);
       
    53 	}
       
    54 
       
    55 /**
       
    56 Static Constructor
       
    57 Note the lack of ELeave. This means that having insufficient memory
       
    58 will return NULL;
       
    59 */
       
    60 CTestStepBtRomConfigUser002* 
       
    61 CTestStepBtRomConfigUser002::New(CTestServer& aParent)
       
    62 	{
       
    63 	return new CTestStepBtRomConfigUser002(aParent); 
       
    64 	}
       
    65 
       
    66 /**
       
    67 See BT_ROMCONFIG_USER_002.script
       
    68 */
       
    69 TVerdict CTestStepBtRomConfigUser002::doTestStepL()
       
    70 	{
       
    71 	INFO_PRINTF1(_L("&gt;&gt;CTestStepBtRomConfigUser002::doTestStepL()"));
       
    72 	
       
    73 	CActiveScheduler* sched(new (ELeave)CActiveScheduler);
       
    74 	CActiveScheduler::Install(sched);
       
    75 	CleanupStack::PushL(sched);
       
    76 
       
    77 	User::LeaveIfError(iSocketServ.Connect());
       
    78 	
       
    79 	TInt expectedError(KErrNotSupported);
       
    80 
       
    81 	const TInt numTestCases(25);
       
    82 	
       
    83 	for (TInt testCase(0); testCase < numTestCases; ++testCase)
       
    84 		{
       
    85 		TRAPD(err, TestBluetoothSocketConstructorL(testCase, expectedError));
       
    86 		
       
    87 		if (expectedError != err)
       
    88 			{
       
    89 			// this is only used for logging readability purposes
       
    90 			const TDesC* expectedErrorDesPtr(0);
       
    91 
       
    92 			switch (expectedError)
       
    93 				{
       
    94 			case KErrNotFound:
       
    95 				expectedErrorDesPtr = &KErrNotFoundLit;
       
    96 				break;
       
    97 			case KErrNone:
       
    98 				expectedErrorDesPtr = &KErrNoneLit;
       
    99 				break;
       
   100 			case KErrBadName:
       
   101 				expectedErrorDesPtr = &KErrBadNameLit;
       
   102 				break;
       
   103 			case KErrNotSupported:
       
   104 				expectedErrorDesPtr = &KErrNotSupportedLit;
       
   105 				break;
       
   106 			default:
       
   107 				User::Panic(KUnexpectedError, testCase);
       
   108 				}
       
   109 
       
   110 			INFO_PRINTF5(_L("Failed: Expected %S(%d) and got %d calling CBluetoothSocket constructor case %d"), 
       
   111 						 expectedErrorDesPtr, expectedError, err, testCase);
       
   112 			SetTestStepResult(EFail);
       
   113 			}
       
   114 		}
       
   115 	
       
   116 	INFO_PRINTF2(_L("Tested %d cases"), numTestCases);
       
   117 	
       
   118 	iSocketServ.Close();
       
   119 	
       
   120 	CleanupStack::PopAndDestroy(sched);
       
   121 	INFO_PRINTF1(_L("&lt;&lt;CTestStepBtRomConfigUser002::doTestStepL()"));
       
   122 	
       
   123 	CheckAndSetTestResult();
       
   124 	return TestStepResult();
       
   125 	}
       
   126 
       
   127 void CTestStepBtRomConfigUser002::
       
   128 TestBluetoothSocketConstructorL(TInt aTestSubCase, TInt& aExpectedError)
       
   129 	{
       
   130 		
       
   131 	// must set the expected error BEFORE the test calls a leaving function
       
   132 	CBluetoothSocket* btsocket(0);
       
   133 	switch(aTestSubCase)
       
   134 		{
       
   135 	case 0:
       
   136 		{
       
   137 		// Even if BT is missing from the ROM, this test will succeed.
       
   138 		// This is because we are only passing a hint to the socket server,
       
   139 		// not actually instantiating a Bluetooth connection
       
   140 		aExpectedError = KErrNone; 
       
   141 		
       
   142 		RSocketServ socketServ;
       
   143 		TSessionPref pref;
       
   144 		
       
   145 		// ToDo Check that these are correct
       
   146 		pref.iAddrFamily = KSockStream;
       
   147 		pref.iProtocol = KRFCOMM;
       
   148 
       
   149 		User::LeaveIfError(socketServ.Connect(pref));
       
   150 		if (socketServ.Handle())
       
   151 			{
       
   152 			socketServ.Close();
       
   153 			}
       
   154 		}
       
   155 		break;
       
   156 
       
   157 	case 1:
       
   158 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   159 
       
   160 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   161 										  KSockStream, KRFCOMM);
       
   162 		delete btsocket;
       
   163 		break;
       
   164 
       
   165 	case 2:
       
   166 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   167 
       
   168 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   169 										  KSockSeqPacket, KL2CAP);
       
   170 		delete btsocket;
       
   171 		break;
       
   172 	
       
   173 	case 3:
       
   174 		aExpectedError = iBtExcluded ? KErrBadName : KErrNotSupported;
       
   175 
       
   176 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   177 										  KSockStream, KSDP);
       
   178 		delete btsocket;
       
   179 		break;	
       
   180 
       
   181 	case 4:
       
   182 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   183 
       
   184 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   185 										  KUndefinedSockType, KBTLinkManager);
       
   186 		delete btsocket;
       
   187 		break;
       
   188 		
       
   189 	case 5:
       
   190 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   191 
       
   192 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   193 										  KSockDatagram, KAVCTP);
       
   194 		delete btsocket;
       
   195 		break;					
       
   196 		
       
   197 	case 6:
       
   198 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   199 
       
   200 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   201 										  KSockDatagram, KAVDTP);
       
   202 		delete btsocket;
       
   203 		break;						
       
   204 			
       
   205 	case 7:
       
   206 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   207 
       
   208 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   209 										  KSockStream, KRFCOMM);
       
   210 		CleanupStack::PopAndDestroy(btsocket);
       
   211 		break;
       
   212 
       
   213 	case 8:
       
   214 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   215 
       
   216 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   217 										  KSockSeqPacket, KL2CAP);
       
   218 		CleanupStack::PopAndDestroy(btsocket);
       
   219 		break;
       
   220 	
       
   221 	case 9:
       
   222 		aExpectedError = iBtExcluded ? KErrBadName : KErrNotSupported;
       
   223 
       
   224 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   225 										  KSockStream, KSDP);
       
   226 		CleanupStack::PopAndDestroy(btsocket);
       
   227 		break;	
       
   228 
       
   229 	case 10:
       
   230 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   231 
       
   232 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   233 										  KUndefinedSockType, KBTLinkManager);
       
   234 		CleanupStack::PopAndDestroy(btsocket);
       
   235 		break;
       
   236 		
       
   237 	case 11:
       
   238 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   239 
       
   240 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   241 										  KSockDatagram, KAVCTP);
       
   242 		CleanupStack::PopAndDestroy(btsocket);
       
   243 		break;					
       
   244 		
       
   245 	case 12:
       
   246 		aExpectedError = iBtExcluded ? KErrBadName : KErrNone;
       
   247 
       
   248 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   249 										  KSockDatagram, KAVDTP);
       
   250 		CleanupStack::PopAndDestroy(btsocket);
       
   251 		break;	
       
   252 		
       
   253 	case 13: // use the protocol descriptor from bt_sock
       
   254 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   255 
       
   256 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, KRFCOMMDesC);
       
   257 		delete btsocket;
       
   258 		break;		
       
   259 
       
   260 	case 14: // use the protocol descriptor from bt_sock
       
   261 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   262 
       
   263 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, KL2CAPDesC);
       
   264 		delete btsocket;
       
   265 		break;		
       
   266 		
       
   267 	case 15:
       
   268 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNotSupported;
       
   269 
       
   270 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, KProtocolSdp);
       
   271 		delete btsocket;
       
   272 		break;				
       
   273 
       
   274 	case 16:
       
   275 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   276 
       
   277 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   278 										  KProtocolBtLinkManager);
       
   279 		delete btsocket;
       
   280 		break;				
       
   281 
       
   282 	case 17:
       
   283 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   284 
       
   285 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ, 
       
   286 										  KAVDTPProtocolName);
       
   287 		delete btsocket;
       
   288 		break;				
       
   289 
       
   290 	case 18: // use the protocol descriptor from bt_sock
       
   291 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   292 
       
   293 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, KRFCOMMDesC);
       
   294 		CleanupStack::PopAndDestroy(btsocket);
       
   295 		break;		
       
   296 
       
   297 	case 19: // use the protocol descriptor from bt_sock
       
   298 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   299 
       
   300 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, KL2CAPDesC);
       
   301 		CleanupStack::PopAndDestroy(btsocket);
       
   302 		break;		
       
   303 		
       
   304 	case 20:
       
   305 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNotSupported;
       
   306 
       
   307 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, KProtocolSdp);
       
   308 		CleanupStack::PopAndDestroy(btsocket);
       
   309 		break;				
       
   310 
       
   311 	case 21:
       
   312 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   313 
       
   314 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   315 										   KProtocolBtLinkManager);
       
   316 		CleanupStack::PopAndDestroy(btsocket);
       
   317 		break;				
       
   318 
       
   319 	case 22:
       
   320 		aExpectedError = iBtExcluded ? KErrNotFound : KErrNone;
       
   321 
       
   322 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ, 
       
   323 										   KAVDTPProtocolName);
       
   324 		CleanupStack::PopAndDestroy(btsocket);
       
   325 		break;			
       
   326 
       
   327 	case 23:
       
   328 		aExpectedError = KErrNone; // even with no BT, this will succeed 
       
   329 		btsocket = CBluetoothSocket::NewL(*this, iSocketServ);
       
   330 		// Even though we can create a blank (CBluetooth)Socket, this isn't
       
   331 		// of any use without an instantiated Bluetooth socket, so it doesn't
       
   332 		// make sense to do any further API calls with this
       
   333 		delete btsocket;
       
   334 		break;
       
   335 
       
   336 	case 24:
       
   337 		aExpectedError = KErrNone; // even with no BT, this will succeed
       
   338 		btsocket = CBluetoothSocket::NewLC(*this, iSocketServ);
       
   339 		// Even though we can create a blank (CBluetooth)Socket, this isn't
       
   340 		// of any use without an instantiated Bluetooth socket, so it doesn't
       
   341 		// make sense to do any further API calls with this
       
   342 		CleanupStack::PopAndDestroy(btsocket);
       
   343 		break;		
       
   344 
       
   345 	/*
       
   346 	CBluetoothSocket* NewL and NewLC taking an RConnection does not
       
   347 	have to be tested, the RConnection cannot be started over
       
   348 	Bluetooth BT_ROMCONFIG_PAN_001 confirms that this is not possible
       
   349 	without BT on ROM
       
   350 	*/	
       
   351 	
       
   352 	/* CBluetoothSocket* NewL and NewLC taking parameters
       
   353 	(MBluetoothSocketNotifier &aNotifier, RSocketServ &aServer,
       
   354 	RSocket &aSocket); does not have to be tested, as the API states:
       
   355 	"This should be used where an existing API returned a RSocket
       
   356 	representing a Bluetooth connection."  BT_ROMCONFIG_RSOCKET_001
       
   357 	confirms that this is not possible without BT on ROM
       
   358 	*/	
       
   359 
       
   360 	default:
       
   361 		User::Panic(KInvalidTestPanicString, aTestSubCase);
       
   362 		break;
       
   363 		}
       
   364 	}
       
   365 
       
   366 // stubs
       
   367 void CTestStepBtRomConfigUser002::HandleConnectCompleteL(TInt/*aErr*/)
       
   368 	{
       
   369 	}
       
   370 	
       
   371 void CTestStepBtRomConfigUser002::HandleAcceptCompleteL(TInt/*aErr*/)
       
   372 	{
       
   373 	}
       
   374 		
       
   375 void CTestStepBtRomConfigUser002::HandleShutdownCompleteL(TInt/*aErr*/)
       
   376 	{
       
   377 	}
       
   378 		
       
   379 void CTestStepBtRomConfigUser002::HandleSendCompleteL(TInt/*aErr*/)
       
   380 	{
       
   381 	}
       
   382 		
       
   383 void CTestStepBtRomConfigUser002::HandleReceiveCompleteL(TInt/*aErr*/)
       
   384 	{
       
   385 	}
       
   386 		
       
   387 void CTestStepBtRomConfigUser002::HandleIoctlCompleteL(TInt/*aErr*/)
       
   388 	{
       
   389 	}
       
   390 		
       
   391 void CTestStepBtRomConfigUser002::
       
   392 HandleActivateBasebandEventNotifierCompleteL(TInt, 
       
   393 											 TBTBasebandEventNotification&)
       
   394 	{
       
   395 	}	
       
   396 	
       
   397 // EOF