Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -112,44 +112,10 @@ ], [have_getaddrinfo="yes"], [have_getaddrinfo="no"]) AC_MSG_RESULT($have_getaddrinfo) test x"$have_getaddrinfo" = x"yes" && \ AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether we have getaddrinfo]) -AC_MSG_CHECKING(whether we have IPv6 support) -AS_IF([test x"$have_getaddrinfo" = x"yes"], [ - AC_CACHE_VAL(ac_cv_have_ipv6, [ - AC_TRY_RUN([ - #ifndef _WIN32 - #include - #include - #include - #else - #include - #include - #endif - - #ifndef INVALID_SOCKET - #define INVALID_SOCKET -1 - #endif - - int - main() - { - int fd; - struct sockaddr_in6 addr; - - fd = socket(AF_INET6, SOCK_STREAM, 0); - - exit(fd != INVALID_SOCKET ? 0 : 1); - }], - ac_cv_have_ipv6="yes", - ac_cv_have_ipv6="no", - ac_cv_have_ipv6="no")])], [ac_cv_have_ipv6="no"]) -AC_MSG_RESULT($ac_cv_have_ipv6) -test x"$ac_cv_have_ipv6" = x"yes" && \ - AC_DEFINE(HAVE_IPV6, 1, "Whether we have IPv6 support") - AC_CHECK_FUNC(madvise, [AC_DEFINE(HAVE_MADVISE, 1, [Whether we have madvise])]) AC_LANG([Objective C]) AC_PROG_OBJC Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,11 +1,10 @@ include ../extra.mk SUBDIRS = OFDataArray \ OFHashes \ ${OFPLUGIN} \ - OFTCPSocket \ OFThread \ OFXMLElement \ OFXMLParser \ ${OBJC_SYNC} DELETED tests/OFTCPSocket/Makefile Index: tests/OFTCPSocket/Makefile ================================================================== --- tests/OFTCPSocket/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -PROG_NOINST = oftcpsocket${PROG_SUFFIX} -SRCS = OFTCPSocket.m - -include ../../buildsys.mk -include ../../extra.mk - -CPPFLAGS += -I../../src -I../.. -LIBS := -L../../src -lobjfw ${LIBS} - -.PHONY: run - -all: run -run: ${PROG_NOINST} - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib - if test -f ../../src/libobjfw.so; then \ - ln -s ../../src/libobjfw.so libobjfw.so.0; \ - ln -s ../../src/libobjfw.so libobjfw.so.0.1; \ - fi - if test -f ../../src/libobjfw.dll; then \ - ln ../../src/libobjfw.dll libobjfw.dll; \ - fi - if test -f ../../src/libobjfw.dylib; then \ - ln -s ../../src/libobjfw.dylib libobjfw.dylib; \ - fi - LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ - DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ - ${TEST_LAUNCHER} ./${PROG_NOINST}; EXIT=$$?; \ - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib; \ - exit $$EXIT DELETED tests/OFTCPSocket/OFTCPSocket.m Index: tests/OFTCPSocket/OFTCPSocket.m ================================================================== --- tests/OFTCPSocket/OFTCPSocket.m +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#include "config.h" - -#include -#include -#include -#include - -#import "OFTCPSocket.h" -#import "OFExceptions.h" - -inline uint16_t get_port() -{ - uint16_t port = (uint16_t)rand(); - - if (port < 1024) - port += 1024; - - printf("Using port %d...\n", port); - - return port; -} - -int -main() -{ - uint16_t port; - OFString *service; - - srand(time(NULL)); - - @try { - OFSocket *server = [OFTCPSocket socket]; - OFSocket *client = [OFTCPSocket socket]; - OFSocket *accepted; - char buf[7]; - - puts("== IPv4 =="); - port = get_port(); - service = [OFString stringWithFormat: @"%d", port]; - - [server bindService: service - onNode: @"localhost" - withFamily: AF_INET]; - [server listen]; - - [client connectToService: service - onNode: @"localhost"]; - - accepted = [server accept]; - - [client writeString: @"Hallo!"]; - [accepted readNBytes: 6 - intoBuffer: buf]; - buf[6] = 0; - - if (!strcmp(buf, "Hallo!")) - puts("Received correct string!"); - else { - puts("Received INCORRECT string!"); - return 1; - } - -#ifdef HAVE_IPV6 - memset(buf, 0, 7); - - [accepted release]; - [client close]; - [server close]; - - puts("== IPv6 =="); - port = get_port(); - service = [OFString stringWithFormat: @"%d", port]; - - [server bindService: service - onNode: @"::1" - withFamily: AF_INET6]; - [server listen]; - - [client connectToService: service - onNode: @"::1"]; - - accepted = [server accept]; - - [client writeString: @"IPv6:)"]; - [accepted readNBytes: 6 - intoBuffer: buf]; - buf[6] = 0; - - if (!strcmp(buf, "IPv6:)")) - puts("Received correct string!"); - else { - puts("Received INCORRECT string!"); - return 1; - } -#endif - - [accepted release]; - } @catch (OFException *e) { - printf("EXCEPTION: %s\n", [[e string] cString]); - return 1; - } - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -2,11 +2,12 @@ SRCS = array.m \ dictionary.m \ list.m \ main.m \ object.m \ - string.m + string.m \ + tcpsocket.m include ../buildsys.mk include ../extra.mk CPPFLAGS += -I../src -I.. -DSTDOUT Index: tests_new/main.m ================================================================== --- tests_new/main.m +++ tests_new/main.m @@ -22,10 +22,11 @@ extern void array_tests(); extern void dictionary_tests(); extern void list_tests(); extern void object_tests(); extern void string_tests(); +extern void tcpsocket_tests(); static int fails = 0; static void output(OFString *str, int color) @@ -91,8 +92,9 @@ object_tests(); string_tests(); array_tests(); dictionary_tests(); list_tests(); + tcpsocket_tests(); return fails; } ADDED tests_new/tcpsocket.m Index: tests_new/tcpsocket.m ================================================================== --- /dev/null +++ tests_new/tcpsocket.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008 - 2009 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#include "config.h" + +#include +#include +#include + +#import "OFTCPSocket.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" +#import "OFMacros.h" + +#import "main.h" + +static OFString *module = @"OFTCPSocket"; + +void +tcpsocket_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFSocket *server, *client, *accepted; + OFString *service, *msg; + uint16_t port; + char buf[6]; + + srand(time(NULL)); + port = (uint16_t)rand(); + if (port < 1024) + port += 1024; + service = [OFString stringWithFormat: @"%d", port]; + + TEST(@"+[socket]", (server = [OFTCPSocket socket]) && + (client = [OFTCPSocket socket])) + + msg = [OFString stringWithFormat: + @"-[bindService:onNode:withFamily:] (port %d)", port]; + TEST(msg, [server bindService: service + onNode: @"localhost" + withFamily: AF_INET]) + + TEST(@"-[listen]", [server listen]) + + TEST(@"-[connectToService:onNode:]", + [client connectToService: service + onNode: @"localhost"]) + + TEST(@"-[accept]", (accepted = [server accept])) + + TEST(@"-[writeString:]", [client writeString: @"Hello!"]) + + TEST(@"-[readNBytes:intoBuffer:]", [accepted readNBytes: 6 + intoBuffer: buf] && + !memcmp(buf, "Hello!", 6)) + + [pool release]; +}