summaryrefslogtreecommitdiff
path: root/gl/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-10-27 09:22:50 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-10-27 09:22:50 +0200
commitd86ab06220f5148db3a664d5659b4ec3f35d1079 (patch)
treec3cb111c1c77b773ecf13a49fb521b6a5269bdab /gl/tests
parent482635401b91171259c9a027d0bc2faefb7e8c68 (diff)
downloadgnutls-d86ab06220f5148db3a664d5659b4ec3f35d1079.tar.gz
Added recv(), send(), connect() and inet_ntop() gnulib modules.
Diffstat (limited to 'gl/tests')
-rw-r--r--gl/tests/Makefile.am36
-rw-r--r--gl/tests/connect.c56
-rw-r--r--gl/tests/test-inet_ntop.c56
-rw-r--r--gl/tests/test-recv.c49
-rw-r--r--gl/tests/test-send.c49
5 files changed, 181 insertions, 65 deletions
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index 205b736bbc..4759912e18 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -142,15 +142,6 @@ EXTRA_DIST += test-close.c signature.h macros.h
## end gnulib module close-tests
-## begin gnulib module connect
-
-
-EXTRA_DIST += connect.c w32sock.h
-
-EXTRA_libtests_a_SOURCES += connect.c
-
-## end gnulib module connect
-
## begin gnulib module connect-tests
TESTS += test-connect
@@ -500,6 +491,15 @@ EXTRA_DIST += test-ignore-value.c
## end gnulib module ignore-value-tests
+## begin gnulib module inet_ntop-tests
+
+TESTS += test-inet_ntop
+check_PROGRAMS += test-inet_ntop
+test_inet_ntop_LDADD = $(LDADD) @INET_NTOP_LIB@
+EXTRA_DIST += test-inet_ntop.c signature.h macros.h
+
+## end gnulib module inet_ntop-tests
+
## begin gnulib module inet_pton-tests
TESTS += test-inet_pton
@@ -816,6 +816,15 @@ EXTRA_DIST += test-read-file.c
## end gnulib module read-file-tests
+## begin gnulib module recv-tests
+
+TESTS += test-recv
+check_PROGRAMS += test-recv
+test_recv_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-recv.c signature.h macros.h
+
+## end gnulib module recv-tests
+
## begin gnulib module recvfrom-tests
TESTS += test-recvfrom
@@ -844,6 +853,15 @@ EXTRA_DIST += macros.h signature.h test-select.c test-select.h test-select-fd.c
## end gnulib module select-tests
+## begin gnulib module send-tests
+
+TESTS += test-send
+check_PROGRAMS += test-send
+test_send_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-send.c signature.h macros.h
+
+## end gnulib module send-tests
+
## begin gnulib module sendto-tests
TESTS += test-sendto
diff --git a/gl/tests/connect.c b/gl/tests/connect.c
deleted file mode 100644
index afd13b9f8d..0000000000
--- a/gl/tests/connect.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* connect.c --- wrappers for Windows connect function
-
- Copyright (C) 2008-2011 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paolo Bonzini */
-
-#include <config.h>
-
-#define WIN32_LEAN_AND_MEAN
-/* Get winsock2.h. */
-#include <sys/socket.h>
-
-/* Get set_winsock_errno, FD_TO_SOCKET etc. */
-#include "w32sock.h"
-
-#undef connect
-
-int
-rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
-{
- SOCKET sock = FD_TO_SOCKET (fd);
-
- if (sock == INVALID_SOCKET)
- {
- errno = EBADF;
- return -1;
- }
- else
- {
- int r = connect (sock, sockaddr, len);
- if (r < 0)
- {
- /* EINPROGRESS is not returned by WinSock 2.0; for backwards
- compatibility, connect(2) uses EWOULDBLOCK. */
- if (WSAGetLastError () == WSAEWOULDBLOCK)
- WSASetLastError (WSAEINPROGRESS);
-
- set_winsock_errno ();
- }
-
- return r;
- }
-}
diff --git a/gl/tests/test-inet_ntop.c b/gl/tests/test-inet_ntop.c
new file mode 100644
index 0000000000..ebb7c1c093
--- /dev/null
+++ b/gl/tests/test-inet_ntop.c
@@ -0,0 +1,56 @@
+/* Test of inet_ntop function.
+ Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2009. */
+
+#include <config.h>
+
+#include <arpa/inet.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (inet_ntop, char const *, (int, void const *, char *,
+ socklen_t));
+
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#if defined AF_INET /* HAVE_IPV4 */
+ {
+ struct in_addr internal;
+ char printable[16];
+ const char *result;
+
+ /* This machine was for a long time known as
+ ma2s2.mathematik.uni-karlsruhe.de. */
+# ifdef WORDS_BIGENDIAN
+ internal.s_addr = 0x810D7302;
+# else
+ internal.s_addr = 0x02730D81;
+# endif
+ result = inet_ntop (AF_INET, &internal, printable, sizeof (printable));
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "129.13.115.2") == 0);
+ }
+#endif
+
+ return 0;
+}
diff --git a/gl/tests/test-recv.c b/gl/tests/test-recv.c
new file mode 100644
index 0000000000..ae811b6658
--- /dev/null
+++ b/gl/tests/test-recv.c
@@ -0,0 +1,49 @@
+/* Test the recv() function.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (recv, ssize_t, (int, void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+ gl_sockets_startup (SOCKETS_1_1);
+
+ /* Test behaviour for invalid file descriptors. */
+ {
+ char byte;
+ errno = 0;
+ ASSERT (recv (-1, &byte, 1, 0) == -1);
+ ASSERT (errno == EBADF);
+ }
+ {
+ char byte;
+ errno = 0;
+ ASSERT (recv (99, &byte, 1, 0) == -1);
+ ASSERT (errno == EBADF);
+ }
+
+ return 0;
+}
diff --git a/gl/tests/test-send.c b/gl/tests/test-send.c
new file mode 100644
index 0000000000..9fb24d4395
--- /dev/null
+++ b/gl/tests/test-send.c
@@ -0,0 +1,49 @@
+/* Test the send() function.
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (send, ssize_t, (int, const void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+ gl_sockets_startup (SOCKETS_1_1);
+
+ /* Test behaviour for invalid file descriptors. */
+ {
+ char byte = 'x';
+ errno = 0;
+ ASSERT (send (-1, &byte, 1, 0) == -1);
+ ASSERT (errno == EBADF);
+ }
+ {
+ char byte = 'x';
+ errno = 0;
+ ASSERT (send (99, &byte, 1, 0) == -1);
+ ASSERT (errno == EBADF);
+ }
+
+ return 0;
+}