1#include <cppunit/extensions/HelperMacros.h>
6static const char send_msg[] =
"The quick brown fox jumps over the lazy dog";
10class TCPSocket_TEST :
public CppUnit::TestFixture
12 CPPUNIT_TEST_SUITE( TCPSocket_TEST );
13 CPPUNIT_TEST( testSocketHandle );
14 CPPUNIT_TEST( testPeerStatus );
15 CPPUNIT_TEST_SUITE_END();
34 void testSocketHandle()
36 server_socket->
bind(
"127.0.0.1", 47777);
38 client_socket->
connect(
"127.0.0.1", 47777);
41 tmp_handle = server_socket->
accept();
45 CPPUNIT_ASSERT( !handle );
46 CPPUNIT_ASSERT( tmp_handle );
48 CPPUNIT_ASSERT( handle );
49 CPPUNIT_ASSERT( !tmp_handle );
51 CPPUNIT_ASSERT( !handle );
59 server_socket->
bind(
"127.0.0.1", 47777);
63 client_socket->
connect(
"127.0.0.1", 47777);
65 CPPUNIT_ASSERT( handle );
67 CPPUNIT_ASSERT( !handle );
71 CPPUNIT_ASSERT_EQUAL(
len, ret );
77 CPPUNIT_ASSERT_EQUAL( -1, ret );
CPPUNIT_TEST_SUITE_REGISTRATION(TCPSocket_TEST)
static NET::can_frame recv_msg
static NET::can_frame send_msg
void bind(unsigned short localPort=0)
void connect(std::string_view foreignAddress, unsigned short foreignPort)
establish a connection with the given foreign address and port
Signals a problem with the execution of a socket call.
void disconnect()
Disconnect and unset any foreign addresses.
int send(const void *buffer, size_t len)
send data through a connected socket
bool peerDisconnected() const
returns whether a peer disconnected
int receive(void *buffer, size_t len)
receive data from a bound socket
SocketHandle< TCPSocket > Handle
Handle for a new socket returned by accept.
void listen(int backlog=5)
listen for incoming connections
Handle accept() const
wait for another socket to connect