X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftest.cpp;h=8a080454b6bf7f447bc66727360c6f3dd8d37b2b;hb=fa427d641b687dd8585adced708510b94588cf51;hp=fa7a82428182c604a960891f29f8d6c0c6717d16;hpb=06cdce1e1231fb5946ac9750f9b53b53c6f7e5f8;p=oweals%2Fminetest.git diff --git a/src/test.cpp b/src/test.cpp index fa7a82428..8a080454b 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -157,6 +157,8 @@ struct TestUtilities: public TestBase UASSERT(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001); UASSERT(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001); UASSERT(lowercase("Foo bAR") == "foo bar"); + UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR"); + UASSERT(trim("\n \t\r \r\n\t\t ") == ""); UASSERT(is_yes("YeS") == true); UASSERT(is_yes("") == false); UASSERT(is_yes("FAlse") == false); @@ -169,6 +171,10 @@ struct TestUtilities: public TestBase UASSERT(removeStringEnd("bc", ends) == "b"); UASSERT(removeStringEnd("12c", ends) == "12"); UASSERT(removeStringEnd("foo", ends) == ""); + UASSERT(urlencode("\"Aardvarks lurk, OK?\"") + == "%22Aardvarks%20lurk%2C%20OK%3F%22"); + UASSERT(urldecode("%22Aardvarks%20lurk%2C%20OK%3F%22") + == "\"Aardvarks lurk, OK?\""); } }; @@ -1500,37 +1506,46 @@ struct TestSocket: public TestBase void Run() { const int port = 30003; + Address address(0,0,0,0, port); + Address address6((IPv6AddressBytes*) NULL, port); // IPv6 socket test { UDPSocket socket6(true); - socket6.Bind(port); + socket6.Bind(address6); const char sendbuffer[] = "hello world!"; IPv6AddressBytes bytes; bytes.bytes[15] = 1; - socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer)); + + try { + socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer)); - sleep_ms(50); + 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; + 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); } - //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); + catch (SendFailedException e) { + errorstream << "IPv6 support enabled but not available!" << std::endl; + } + } // IPv4 socket test { UDPSocket socket(false); - socket.Bind(port); + socket.Bind(address); const char sendbuffer[] = "hello world!"; socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer)); @@ -1650,7 +1665,8 @@ struct TestConnection: public TestBase infostream<<"** Creating server Connection"<