Rev 11642: Add initial simple tests for socket wrapper in
file:///home/jelmer/bzr.samba/SAMBA_4_0/
Jelmer Vernooij
jelmer at samba.org
Sat Mar 3 01:17:06 GMT 2007
At file:///home/jelmer/bzr.samba/SAMBA_4_0/
------------------------------------------------------------
revno: 11642
revision-id: jelmer at samba.org-20070303011649-elz7bumnf6tbb2t7
parent: svn-v2:21670 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: SAMBA_4_0
timestamp: Sat 2007-03-03 02:16:49 +0100
message:
Add initial simple tests for socket wrapper
added:
source/lib/socket_wrapper/testsuite.c testsuite.c-20070303011629-vut5s4d0548pc365-1
modified:
source/lib/socket_wrapper/socket_wrapper.c svn-v2:6139 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fsocket_wrapper%2fsocket_wrapper.c
source/lib/socket_wrapper/socket_wrapper.h svn-v2:6139 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2flib%2fsocket_wrapper%2fsocket_wrapper.h
source/torture/local/config.mk svn-v2:12008 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2ftorture%2flocal%2fconfig.mk
source/torture/local/local.c svn-v2:16333 at 0c0555d6-39d7-0310-84fc-f1cc0bd64818-branches%2fSAMBA_4_0-source%2ftorture%2flocal%2flocal.c
=== added file 'source/lib/socket_wrapper/testsuite.c'
--- a/source/lib/socket_wrapper/testsuite.c 1970-01-01 00:00:00 +0000
+++ b/source/lib/socket_wrapper/testsuite.c 2007-03-03 01:16:49 +0000
@@ -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;
+}
=== modified file 'source/lib/socket_wrapper/socket_wrapper.c'
--- a/source/lib/socket_wrapper/socket_wrapper.c 2006-10-19 04:56:21 +0000
+++ b/source/lib/socket_wrapper/socket_wrapper.c 2007-03-03 01:16:49 +0000
@@ -187,7 +187,7 @@
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) {
=== modified file 'source/lib/socket_wrapper/socket_wrapper.h'
--- a/source/lib/socket_wrapper/socket_wrapper.h 2006-10-08 20:48:34 +0000
+++ b/source/lib/socket_wrapper/socket_wrapper.h 2007-03-03 01:16:49 +0000
@@ -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);
=== modified file 'source/torture/local/config.mk'
--- a/source/torture/local/config.mk 2007-03-02 14:53:09 +0000
+++ b/source/torture/local/config.mk 2007-03-03 01:16:49 +0000
@@ -19,6 +19,7 @@
../../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 \
=== modified file 'source/torture/local/local.c'
--- a/source/torture/local/local.c 2007-02-16 15:13:51 +0000
+++ b/source/torture/local/local.c 2007-03-03 01:16:49 +0000
@@ -37,6 +37,7 @@
torture_local_idtree,
torture_local_iconv,
torture_local_socket,
+ torture_local_socket_wrapper,
torture_pac,
torture_registry,
torture_local_resolve,
More information about the samba-cvs
mailing list