summaryrefslogtreecommitdiff
path: root/source3/lib/socket_wrapper/testsuite.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-06-10 08:53:34 +0200
committerStefan Metzmacher <metze@samba.org>2008-06-10 11:36:38 +0200
commitbd793fb235cd18da8e9d779c767cac81fa3f758e (patch)
tree084190f420be5321633164b54b7d2b7593c2dee6 /source3/lib/socket_wrapper/testsuite.c
parent1410d8e7992112a4c07c6ef8e80b49be492a50c7 (diff)
downloadsamba-bd793fb235cd18da8e9d779c767cac81fa3f758e.tar.gz
samba-bd793fb235cd18da8e9d779c767cac81fa3f758e.tar.bz2
samba-bd793fb235cd18da8e9d779c767cac81fa3f758e.zip
r21671: Add initial simple tests for socket wrapper
(partly cherry picked from commit 872e2ad541478597191ca9e31872d5c8e2bbb832) metze (This used to be commit 8003f00a28bb7237ec1b1f4eb9687c542a86c2b2)
Diffstat (limited to 'source3/lib/socket_wrapper/testsuite.c')
-rw-r--r--source3/lib/socket_wrapper/testsuite.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/source3/lib/socket_wrapper/testsuite.c b/source3/lib/socket_wrapper/testsuite.c
new file mode 100644
index 0000000000..a3e6580409
--- /dev/null
+++ b/source3/lib/socket_wrapper/testsuite.c
@@ -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;
+}