diff options
Diffstat (limited to 'src/test.cpp')
-rw-r--r-- | src/test.cpp | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/src/test.cpp b/src/test.cpp index 5267b2768..b66f65daf 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1293,26 +1293,56 @@ struct TestSocket: public TestBase void Run() { const int port = 30003; - UDPSocket socket; - socket.Bind(port); - const char sendbuffer[] = "hello world!"; - socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer)); + // IPv6 socket test + { + UDPSocket socket6(true); + socket6.Bind(port); - sleep_ms(50); + const char sendbuffer[] = "hello world!"; + IPv6AddressBytes bytes; + bytes.bytes[15] = 1; + socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer)); + + sleep_ms(50); + + char rcvbuffer[256]; + memset(rcvbuffer, 0, sizeof(rcvbuffer)); + Address sender; + for(;;) + { + int bytes_read = socket6.Receive(sender, rcvbuffer, sizeof(rcvbuffer)); + if(bytes_read < 0) + break; + } + //FIXME: This fails on some systems + UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0); + UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr, Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0); + } - char rcvbuffer[256]; - memset(rcvbuffer, 0, sizeof(rcvbuffer)); - Address sender; - for(;;) + // IPv4 socket test { - int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer)); - if(bytes_read < 0) - break; + UDPSocket socket(false); + socket.Bind(port); + + const char sendbuffer[] = "hello world!"; + socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer)); + + sleep_ms(50); + + char rcvbuffer[256]; + memset(rcvbuffer, 0, sizeof(rcvbuffer)); + Address sender; + for(;;) + { + int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer)); + if(bytes_read < 0) + break; + } + //FIXME: This fails on some systems + UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0); + UASSERT(sender.getAddress().sin_addr.s_addr == Address(127,0,0,1, 0).getAddress().sin_addr.s_addr); } - //FIXME: This fails on some systems - UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0); - UASSERT(sender.getAddress() == Address(127,0,0,1, 0).getAddress()); } }; @@ -1412,12 +1442,12 @@ struct TestConnection: public TestBase Handler hand_client("client"); infostream<<"** Creating server Connection"<<std::endl; - con::Connection server(proto_id, 512, 5.0, &hand_server); + con::Connection server(proto_id, 512, 5.0, false, &hand_server); server.Serve(30001); infostream<<"** Creating client Connection"<<std::endl; - con::Connection client(proto_id, 512, 5.0, &hand_client); - + con::Connection client(proto_id, 512, 5.0, false, &hand_client); + UASSERT(hand_server.count == 0); UASSERT(hand_client.count == 0); |