datacommsserver/esockserver/test/TE_Socket/SocketTestSection19.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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 // This contains ESock Test cases from section 19
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include "SocketTestSection19.h"
       
    22 #include "ES_DUMMY.H"
       
    23 
       
    24 
       
    25 // Test step 19.1
       
    26 const TDesC& CSocketTest19_1::GetTestName()
       
    27 	{
       
    28 	_LIT(ret,"Test19.1");
       
    29 	return ret;
       
    30 	}
       
    31 
       
    32 enum TVerdict CSocketTest19_1::InternalDoTestStepL( void )
       
    33 	{
       
    34 	Logger().WriteFormat(_L("Test 19.1 Test connect with connect data"));
       
    35 	
       
    36     Logger().WriteFormat(_L("- connecting to the socket server"));
       
    37 	RSocketServ ss;
       
    38     TInt nRes = OptimalConnect(ss);
       
    39     TESTL(nRes == KErrNone);
       
    40  	CleanupClosePushL(ss);
       
    41 	RSocket sock;
       
    42 	Logger().WriteFormat(_L("Openning a connection to PDummy 3"));
       
    43 	nRes = sock.Open(ss,KDummyThreeName);
       
    44     TESTL(nRes == KErrNone);
       
    45     CleanupClosePushL(sock);
       
    46 	
       
    47 	TSockAddr addr;
       
    48 	_LIT8(desOut,"Some test stuff to send to protocol");
       
    49 	TBuf8<50> desIn;
       
    50 	TRequestStatus stat;
       
    51     Logger().WriteFormat(_L("Performing a connect with connect Data"));
       
    52 	sock.Connect(addr, desOut, desIn, stat);
       
    53 	User::WaitForRequest(stat);
       
    54 	TESTL(stat == KErrNone);
       
    55 	TESTL(desIn == desOut);
       
    56 	CleanupStack::PopAndDestroy(&sock); 
       
    57     CleanupStack::PopAndDestroy(&ss); 
       
    58 	SetTestStepResult(EPass);
       
    59 	return EPass;
       
    60 	}
       
    61 
       
    62 
       
    63 // Test step 19.2
       
    64 const TDesC& CSocketTest19_2::GetTestName()
       
    65 	{
       
    66 	_LIT(ret, "Test19.2");
       
    67 	return ret;
       
    68 	}
       
    69 
       
    70 enum TVerdict CSocketTest19_2::InternalDoTestStepL( void )
       
    71 	{
       
    72 	Logger().WriteFormat(_L("- connecting to the socket server"));
       
    73 	RSocketServ ss;
       
    74     TInt nRes = OptimalConnect(ss);
       
    75     TESTL(nRes == KErrNone);
       
    76  	CleanupClosePushL(ss);
       
    77 	RSocket sock;
       
    78 	Logger().WriteFormat(_L("Openning a connection to PDummy 3"));
       
    79 	nRes = sock.Open(ss, KDummyThreeName);
       
    80     TESTL(nRes == KErrNone);
       
    81     CleanupClosePushL(sock);
       
    82     
       
    83     RSocket sock2;
       
    84     Logger().WriteFormat(_L("Openning a Null socket"));
       
    85 	nRes = sock2.Open(ss);
       
    86     TESTL(nRes == KErrNone);
       
    87     CleanupClosePushL(sock2);
       
    88 	
       
    89 	TInt err;
       
    90 	TSockAddr addr;
       
    91 	Logger().WriteFormat(_L("Performing a bind"));
       
    92 	err = sock.Bind(addr);
       
    93 	TESTL(KErrNone == err);
       
    94 	
       
    95 	_LIT8(desOut, "Some test stuff to send to protocol");
       
    96 	TBuf8<50> desIn;
       
    97 	Logger().WriteFormat(_L("Performing a listen with connect data"));
       
    98 	err = sock.Listen(5, desOut);
       
    99 	TESTL(KErrNone == err);
       
   100 	
       
   101 	TRequestStatus stat;
       
   102     Logger().WriteFormat(_L("Performing an accept with connect Data"));
       
   103 	sock.Accept(sock2, desIn, stat);
       
   104 	TESTL(KRequestPending == stat.Int()); // there must be something wrong if it's not pending
       
   105 	//Now we need to complete the accept
       
   106 	err = sock.SetOpt(KDummyOptionSetConnectComplete, 3462, 0);
       
   107 	TESTL(KErrNone == err);
       
   108 	User::WaitForRequest(stat);
       
   109 	TESTL(stat == KErrNone);
       
   110 	TESTL(desIn == desOut);
       
   111 	CleanupStack::PopAndDestroy(&sock2); 
       
   112 	CleanupStack::PopAndDestroy(&sock); 
       
   113     CleanupStack::PopAndDestroy(&ss); 
       
   114 	SetTestStepResult(EPass);
       
   115 	return EPass;
       
   116 	}
       
   117 
       
   118