linklayercontrol/nullagt/TS_nullagt/src/NullAgentTestSteps.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 <f32file.h>
       
    19 #include "NullAgentTestSteps.h"
       
    20 
       
    21 // Constructor
       
    22 NullAgentTestStep::NullAgentTestStep()
       
    23 {
       
    24 }
       
    25 
       
    26 // Destructor
       
    27 NullAgentTestStep::~NullAgentTestStep()
       
    28 	{ 
       
    29 	}	
       
    30 
       
    31 enum TVerdict NullAgentTestStep::doTestStepPreambleL(void)
       
    32 {
       
    33 	enum TVerdict result = EPass;
       
    34 
       
    35 	/*
       
    36 	 * Wait for all of the interfaces to close down
       
    37 	 */
       
    38 
       
    39 	RSocketServ ss;
       
    40 	
       
    41 	ss.Connect();
       
    42 	CleanupClosePushL(ss);
       
    43 
       
    44 	if (KErrNone == WaitForAllInterfacesToCloseL(ss))
       
    45 		result = EPass;
       
    46 	else
       
    47 		result = EFail;
       
    48 
       
    49 	ss.Close();
       
    50 	CleanupStack::Pop();
       
    51 
       
    52 	return result;
       
    53 }
       
    54 
       
    55 TInt NullAgentTestStep::WaitForAllInterfacesToCloseL(RSocketServ& ss)
       
    56 /*
       
    57  * Sit around waiting for all the interfaces to die (essentially poll every now 
       
    58  * and again until there are zero interfaces in this socket server left)
       
    59  * @return system wide error code
       
    60  */
       
    61 	{
       
    62 	TInt err;
       
    63 	TUint numOfConnections;
       
    64 	TUint count = 0;
       
    65 
       
    66 	RConnection conn;
       
    67 
       
    68 	err = OpenConnection(conn, ss);
       
    69 	TESTEL(KErrNone == err, err);
       
    70 	CleanupClosePushL(conn);
       
    71 
       
    72 	err = EnumerateConnections(conn, numOfConnections);
       
    73 	TESTEL(KErrNone == err, err);
       
    74 
       
    75 	while ((0 != numOfConnections) && (count < 60))
       
    76 	{
       
    77 		count++;
       
    78 		User::After(1000000); // wait a bit, a second sounds good
       
    79 		err = EnumerateConnections(conn, numOfConnections);
       
    80 	}
       
    81 
       
    82 	CloseConnection(conn);
       
    83 	CleanupStack::Pop();
       
    84 
       
    85 	if (numOfConnections != 0)
       
    86 		{
       
    87 		return KErrTimedOut;
       
    88 		}
       
    89 
       
    90 	return KErrNone;
       
    91 	}
       
    92 
       
    93 TInt NullAgentTestStep::OpenConnection(RConnection& conn, RSocketServ& ss)
       
    94 /*
       
    95  * Open the connection using the socket server too
       
    96  * @param conn the connection to open
       
    97  * @param ss the socket server within which the connection is to be opened
       
    98  * @return system wide error code
       
    99  */
       
   100 {
       
   101 	return (conn.Open(ss));
       
   102 }
       
   103 
       
   104 TInt NullAgentTestStep::EnumerateConnections(RConnection& conn, TUint& num)
       
   105 /*
       
   106  * Read how many connections (==interfaces?) exist at the moment
       
   107  * @param conn - to be used to read the count
       
   108  * @param num - on completion holds the number of connections
       
   109  * @return system wide error code
       
   110  */
       
   111 {
       
   112 	return (conn.EnumerateConnections(num));
       
   113 }
       
   114 
       
   115 void NullAgentTestStep::CloseConnection(RConnection& conn)
       
   116 /*
       
   117  * Close a connection
       
   118  * @param conn the connection to close
       
   119  * @return system wide error code
       
   120  */
       
   121 {
       
   122 	conn.Close();
       
   123 }
       
   124