r21671: Add initial simple tests for socket wrapper
authorJelmer Vernooij <jelmer@samba.org>
Sat, 3 Mar 2007 01:20:36 +0000 (01:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:49:07 +0000 (14:49 -0500)
(This used to be commit 872e2ad541478597191ca9e31872d5c8e2bbb832)

source4/lib/socket_wrapper/socket_wrapper.c
source4/lib/socket_wrapper/socket_wrapper.h
source4/lib/socket_wrapper/testsuite.c [new file with mode: 0644]
source4/torture/local/config.mk
source4/torture/local/local.c

index 3f2020d26629bff0abdceb26465222b31691484b..8eff6a49ac8da8ba634d00135e09cb9c9c931e18 100644 (file)
@@ -187,7 +187,7 @@ struct socket_info
 static struct socket_info *sockets;
 
 
-static const char *socket_wrapper_dir(void)
+const char *socket_wrapper_dir(void)
 {
        const char *s = getenv("SOCKET_WRAPPER_DIR");
        if (s == NULL) {
index 1d8dac17632ea411de7d788a2571cffc402d14a0..fd1e48610b7937dd5b1898958fa05797cfce5bcb 100644 (file)
@@ -36,6 +36,7 @@
 #ifndef __SOCKET_WRAPPER_H__
 #define __SOCKET_WRAPPER_H__
 
+const char *socket_wrapper_dir(void);
 int swrap_socket(int family, int type, int protocol);
 int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
 int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t addrlen);
diff --git a/source4/lib/socket_wrapper/testsuite.c b/source4/lib/socket_wrapper/testsuite.c
new file mode 100644 (file)
index 0000000..a3e6580
--- /dev/null
@@ -0,0 +1,82 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   local testing of the socket wrapper
+
+   Copyright (C) Jelmer Vernooij 2007
+   
+   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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "system/network.h"
+#include "lib/socket_wrapper/socket_wrapper.h"
+#include "torture/torture.h"
+
+static char *old_dir = NULL;
+
+static void backup_env(void)
+{
+       old_dir = getenv("SOCKET_WRAPPER_DIR");
+}
+
+static void restore_env(void)
+{
+       setenv("SOCKET_WRAPPER_DIR", old_dir, 1);
+}
+
+static bool test_socket_wrapper_dir(struct torture_context *tctx)
+{
+       backup_env();
+
+       setenv("SOCKET_WRAPPER_DIR", "foo", 1);
+       torture_assert_str_equal(tctx, socket_wrapper_dir(), "foo", "setting failed");
+       setenv("SOCKET_WRAPPER_DIR", "./foo", 1);
+       torture_assert_str_equal(tctx, socket_wrapper_dir(), "foo", "setting failed");
+       unsetenv("SOCKET_WRAPPER_DIR");
+       torture_assert_str_equal(tctx, socket_wrapper_dir(), NULL, "resetting failed");
+
+       restore_env();
+
+       return true;
+}
+
+static bool test_swrap_socket(struct torture_context *tctx)
+{
+       backup_env();
+       setenv("SOCKET_WRAPPER_DIR", "foo", 1);
+
+       torture_assert_int_equal(tctx, swrap_socket(1337, 1337, 0), -1, "unknown address family fails");
+       torture_assert_int_equal(tctx, errno, EAFNOSUPPORT, "correct errno set");
+       torture_assert_int_equal(tctx, swrap_socket(AF_INET, 1337, 0), -1, "unknown type fails");
+       torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set");
+       torture_assert_int_equal(tctx, swrap_socket(AF_INET, SOCK_DGRAM, 10), -1, "unknown protocol fails");
+       torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set");
+
+       restore_env();
+
+       return true;
+}
+
+struct torture_suite *torture_local_socket_wrapper(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite = torture_suite_create(mem_ctx, 
+                                                                                                          "SOCKET-WRAPPER");
+
+       torture_suite_add_simple_test(suite, "socket_wrapper_dir", test_socket_wrapper_dir);
+       torture_suite_add_simple_test(suite, "socket", test_swrap_socket);
+
+       return suite;
+}
index b323e996e25642b3388a8c6deaa64c9833a4c1da..c150aeda712d90751ce0b2bcd9a9b6304aced4dc 100644 (file)
@@ -19,6 +19,7 @@ OBJ_FILES = \
                ../../librpc/tests/binding_string.o \
                ../../lib/util/tests/idtree.o \
                ../../lib/socket/testsuite.o \
+               ../../lib/socket_wrapper/testsuite.o \
                irpc.o \
                ../../lib/registry/tests/generic.o \
                resolve.o \
index c2107830288d5899ee65ed4e547c8bc0e01a41cc..fbf89b6e4e4387a29d8efb88a3066f041f2f5566 100644 (file)
@@ -37,6 +37,7 @@
        torture_local_idtree, 
        torture_local_iconv,
        torture_local_socket, 
+       torture_local_socket_wrapper, 
        torture_pac, 
        torture_registry, 
        torture_local_resolve,