ObjFW  Check-in [67cf530ed3]

Overview
Comment:Migration of OFTCPSocket tests to new testing framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 67cf530ed3a9040cceb1891a68b9ee62054566097b47172d8080ccec556f35c3
User & Date: js on 2009-09-30 13:23:33
Other Links: manifest | tags
Context
2009-09-30
13:33
Migration of OFXMLElement tests to new testing framework. check-in: 2437d2d0be user: js tags: trunk
13:23
Migration of OFTCPSocket tests to new testing framework. check-in: 67cf530ed3 user: js tags: trunk
2009-09-28
07:55
Migration of OFList tests to new testing framework. check-in: 1d802bf56c user: js tags: trunk
Changes

Modified configure.ac from [4862f25471] to [2fd83093d6].

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	struct addrinfo ai;
	getaddrinfo(NULL, NULL, NULL, NULL);
	], [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 <sys/types.h>
			#include <sys/socket.h>
			#include <netinet/in.h>
			#else
			#include <winsock2.h>
			#include <ws2tcpip.h>
			#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

OBJCFLAGS="$OBJCFLAGS -Wall -fobjc-exceptions"
OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString"







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







110
111
112
113
114
115
116


































117
118
119
120
121
122
123
	struct addrinfo ai;
	getaddrinfo(NULL, NULL, NULL, NULL);
	], [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_CHECK_FUNC(madvise, [AC_DEFINE(HAVE_MADVISE, 1, [Whether we have madvise])])

AC_LANG([Objective C])
AC_PROG_OBJC

OBJCFLAGS="$OBJCFLAGS -Wall -fobjc-exceptions"
OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstString"

Modified tests/Makefile from [65d045983b] to [843c47a19e].

1
2
3
4
5
6
7
8
9
10
11
12
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFHashes		\
	  ${OFPLUGIN}		\
	  OFTCPSocket		\
	  OFThread		\
	  OFXMLElement		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk





<






1
2
3
4
5

6
7
8
9
10
11
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFHashes		\
	  ${OFPLUGIN}		\

	  OFThread		\
	  OFXMLElement		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk

Deleted tests/OFTCPSocket/Makefile version [8dec58ac75].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 version [c7b8be1093].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#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;
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






































































































































































































































Modified tests_new/Makefile from [4ac30c970c] to [0c23107fa9].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\
       dictionary.m	\
       list.m		\
       main.m		\
       object.m		\
       string.m


include ../buildsys.mk
include ../extra.mk

CPPFLAGS += -I../src -I.. -DSTDOUT
LIBS := -L../src -lobjfw ${LIBS}







|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\
       dictionary.m	\
       list.m		\
       main.m		\
       object.m		\
       string.m		\
       tcpsocket.m

include ../buildsys.mk
include ../extra.mk

CPPFLAGS += -I../src -I.. -DSTDOUT
LIBS := -L../src -lobjfw ${LIBS}

Modified tests_new/main.m from [6c72294cec] to [144512e59e].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
#import "OFAutoreleasePool.h"

extern void array_tests();
extern void dictionary_tests();
extern void list_tests();
extern void object_tests();
extern void string_tests();


static int fails = 0;

static void
output(OFString *str, int color)
{
#ifdef STDOUT







>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#import "OFAutoreleasePool.h"

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)
{
#ifdef STDOUT
89
90
91
92
93
94
95

96
97
98
main()
{
	object_tests();
	string_tests();
	array_tests();
	dictionary_tests();
	list_tests();


	return fails;
}







>



90
91
92
93
94
95
96
97
98
99
100
main()
{
	object_tests();
	string_tests();
	array_tests();
	dictionary_tests();
	list_tests();
	tcpsocket_tests();

	return fails;
}

Added tests_new/tcpsocket.m version [aeddf14d19].







































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <stdlib.h>
#include <string.h>
#include <time.h>

#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];
}