datacommsserver/esockserver/test/TE_Socket/SocketTestSection17.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 17
       
    15 // Testing read from socket with KSockReadPeek flag set
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 
       
    22 #include "SocketTestSection17.h"
       
    23 
       
    24 
       
    25 // Test step 17.1
       
    26 const TDesC& CSocketTest17_1::GetTestName()
       
    27 	{
       
    28 	_LIT(ret,"Test17.1");
       
    29 	return ret;
       
    30 	}
       
    31 
       
    32 enum TVerdict CSocketTest17_1::InternalDoTestStepL( void )
       
    33 	{
       
    34 	Logger().WriteFormat(_L("Use a socket handle for a host resolver operation [PANIC STEP]."));
       
    35 	
       
    36     Logger().WriteFormat(_L("- connecting to the socket server"));
       
    37 	RSocketServ sockServ;
       
    38     TInt nRes = OptimalConnect(sockServ);
       
    39     TESTL(nRes == KErrNone);
       
    40 	RSocket sock;
       
    41 	Logger().WriteFormat(_L("- opening a null socket"));
       
    42 	nRes = sock.Open(sockServ);
       
    43     TESTL(nRes == KErrNone);
       
    44     CleanupClosePushL(sock);
       
    45 	
       
    46     Logger().WriteFormat(_L("- abusing the socket as a host resolver; should panic with \"eSock:0\""));
       
    47 	RHostResolver* hr = reinterpret_cast<RHostResolver*>(&sock);
       
    48 	TName name;
       
    49 	hr->GetHostName(name);
       
    50 	
       
    51     CleanupStack::PopAndDestroy(2); //sockServ, sock
       
    52 	SetTestStepResult(EFail);
       
    53 	return EFail;
       
    54 	}
       
    55 
       
    56 
       
    57 // Test step 17.2
       
    58 const TDesC& CSocketTest17_2::GetTestName()
       
    59 	{
       
    60 	_LIT(ret,"Test17.2");
       
    61 	return ret;
       
    62 	}
       
    63 
       
    64 enum TVerdict CSocketTest17_2::InternalDoTestStepL( void )
       
    65 	{
       
    66 	Logger().WriteFormat(_L("Use a stale socket handle [PANIC STEP]."));
       
    67 	
       
    68     Logger().WriteFormat(_L("- connecting to the socket server, creating & getting local name of null socket"));
       
    69 	RSocketServ sockServ;
       
    70     TInt nRes = OptimalConnect(sockServ);
       
    71     TESTL(nRes == KErrNone);
       
    72 	RSocket sock;
       
    73 	Logger().WriteFormat(_L("- opening connection to 'Dummy Protocol 2'"));
       
    74 	nRes = sock.Open(sockServ, _L("Dummy Protocol 2"));
       
    75     TESTL(nRes == KErrNone);
       
    76     CleanupClosePushL(sock);
       
    77 	TSockAddr addr;
       
    78 	Logger().WriteFormat(_L("- getting local name of socket'"));
       
    79 	sock.LocalName(addr);
       
    80 	
       
    81     Logger().WriteFormat(_L("- copying original socket to duplicateSock"));
       
    82 	RSocket duplicateSock(sock);
       
    83 	Logger().WriteFormat(_L("- getting local name of duplicateSock"));
       
    84 	duplicateSock.LocalName(addr);
       
    85     CleanupStack::Pop(&sock); //sock
       
    86     Logger().WriteFormat(_L("- closing original socket (sock)"));
       
    87     sock.Close();
       
    88 	RSocket newSock;
       
    89 	Logger().WriteFormat(_L("-opening a null socket on newsock"));
       
    90 	nRes = newSock.Open(sockServ);
       
    91     TESTL(nRes == KErrNone);
       
    92     CleanupClosePushL(newSock);
       
    93 	
       
    94     Logger().WriteFormat(_L("- getting local name of duplicate socket; should panic with \"eSock:0\""));
       
    95 	duplicateSock.LocalName(addr);
       
    96 	
       
    97     CleanupStack::PopAndDestroy(2); //sockServ, newSock
       
    98 	SetTestStepResult(EFail);
       
    99 	return EFail;
       
   100 	}
       
   101 
       
   102