linklayercontrol/nullagt/TS_nullagt/src/Nullagentoverrides.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2002-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 // Contain the implementation of the class for this null agent test
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "NullAgentTestSteps.h"
       
    19 #include "dummynifvar.h"
       
    20 #include "commdbconnpref.h"
       
    21 #include "in_sock.h"
       
    22 
       
    23 CTestStepNullAgtOverrides::CTestStepNullAgtOverrides(TPtrC aName)
       
    24 {
       
    25 	iTestStepName=aName;
       
    26 }
       
    27 
       
    28 enum TVerdict CTestStepNullAgtOverrides::doTestStepL(void)
       
    29 {	
       
    30 	__UHEAP_MARK;
       
    31 
       
    32 	TInt r;                // the result of various operations
       
    33 	TRequestStatus status; // status of asynchronous ops
       
    34 
       
    35 	RSocketServ server;    // connection paraphanelia
       
    36 	RConnection connection;
       
    37 	RSocket socket;
       
    38 
       
    39 	TInetAddr dest;
       
    40 	dest.SetAddress(KDummyNifLocalAddressBase + 4);
       
    41 	dest.SetPort(KPortNo);
       
    42 
       
    43 	TBuf8<KBufferLength> buffer;
       
    44 
       
    45 	// connect to the socket server
       
    46 	r = server.Connect();
       
    47 	TESTEL(r == KErrNone, r);
       
    48 	CleanupClosePushL(server);
       
    49 	
       
    50 	// this is why we needed a socket server...
       
    51 	r = connection.Open(server, KAfInet);
       
    52 	TESTEL(r == KErrNone, r);
       
    53 	CleanupClosePushL(connection);
       
    54 
       
    55 	// create the overrides
       
    56 	TCommDbConnPref prefs;
       
    57 	prefs.SetIapId(5);
       
    58 	prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
    59 
       
    60 	// start the connection with the overrides
       
    61 	connection.Start(prefs, status);
       
    62 	User::WaitForRequest(status);
       
    63 	TESTEL(status.Int() == KErrNone, status.Int());
       
    64 
       
    65 	// open a socket session
       
    66 	r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp);
       
    67 	TESTEL(r == KErrNone, r);
       
    68 	CleanupClosePushL(socket);
       
    69 	TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone);
       
    70 	// set the source port number - otherwise will panic cos it's zero
       
    71 	r = socket.SetLocalPort(KPortNo);
       
    72 	TESTEL(r == KErrNone, r);
       
    73 		
       
    74 	// build some data to send on the socket
       
    75 	buffer.SetMax();
       
    76 	buffer.FillZ();
       
    77 	buffer[0] = (TUint8) 0x8;
       
    78 	buffer[1] = (TUint8) 0x0;
       
    79 	buffer[2] = (TUint8) 0xF7;
       
    80 	buffer[3] = (TUint8) 0xFF;
       
    81 
       
    82 	// send the data out
       
    83 	socket.SendTo(buffer, dest, 0, status);
       
    84 	User::WaitForRequest(status);
       
    85 	TESTEL(status.Int() == KErrNone, status.Int());
       
    86 	
       
    87 	buffer.Zero();
       
    88 	// I expect to get the data looped back from the dummy NIF
       
    89 	socket.RecvFrom(buffer, dest, 0, status);
       
    90 	User::WaitForRequest(status);
       
    91 	TESTEL(status.Int() == KErrNone, status.Int());
       
    92 	
       
    93 	// check that what we sent is what we got back
       
    94 	if (status == KErrNone)
       
    95 	{
       
    96 		TESTL(buffer[0] == 0x08);
       
    97 		TESTL(buffer[1] == 0x00);
       
    98 		TESTL(buffer[2] == 0xF7);
       
    99 		TESTL(buffer[3] == 0xFF);
       
   100 	}
       
   101 	
       
   102 	// close the socket
       
   103 	socket.Shutdown(RSocket::ENormal, status);
       
   104 	User::WaitForRequest(status);
       
   105 	TESTEL(status.Int() == KErrNone, status.Int());
       
   106 	CleanupStack::Pop();
       
   107 
       
   108 	// force the destruction of the connection
       
   109 	r = connection.Stop();
       
   110 	TESTEL(r == KErrNone, r);
       
   111 	CleanupStack::Pop();
       
   112 
       
   113 	// close the socket server
       
   114 	server.Close();
       
   115 	CleanupStack::Pop();
       
   116 
       
   117 	__UHEAP_MARKEND;
       
   118 
       
   119 	return iTestStepResult;
       
   120 }