summaryrefslogtreecommitdiffstats
path: root/tests/test_public_functions.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2021-02-24 12:45:26 +0100
committerAndreas Schneider <asn@samba.org>2021-03-15 08:04:58 +0100
commitefd2967e060a3a7ca3de589a23511bb38151ed8b (patch)
tree1d26874505b7c381f16f0f5bcf59dcd392d3742e /tests/test_public_functions.c
parent4ad5a5af0bdf94497f068f10d6c09520702fd50f (diff)
downloadsocket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.tar.gz
socket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.tar.xz
socket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.zip
swrap: introduce a socket_wrapper_noop.so and socket_wrapper.h to provide noop stubs
Applications with the need to call socket_wrapper_enabled() should link against -lsocket_wrapper_noop in order to resolve the symbol at link time. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14640 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'tests/test_public_functions.c')
-rw-r--r--tests/test_public_functions.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/test_public_functions.c b/tests/test_public_functions.c
new file mode 100644
index 0000000..11d03ef
--- /dev/null
+++ b/tests/test_public_functions.c
@@ -0,0 +1,78 @@
+#include "torture.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <cmocka.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <socket_wrapper.h>
+
+static int setup_enabled(void **state)
+{
+ torture_setup_socket_dir(state);
+
+ return 0;
+}
+
+static int teardown_enabled(void **state)
+{
+ torture_teardown_socket_dir(state);
+
+ return 0;
+}
+
+static int setup_disabled(void **state)
+{
+ (void) state; /* unused */
+
+ unsetenv("SOCKET_WRAPPER_DIR");
+ unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE");
+ unsetenv("SOCKET_WRAPPER_PCAP_FILE");
+
+ return 0;
+}
+
+static int teardown_disabled(void **state)
+{
+ (void) state; /* unused */
+
+ return 0;
+}
+
+static void test_call_enabled_true(void **state)
+{
+ char *s = getenv("SOCKET_WRAPPER_DIR");
+
+ (void) state; /* unused */
+
+ assert_true(socket_wrapper_enabled());
+ assert_true(s != NULL);
+}
+
+static void test_call_enabled_false(void **state)
+{
+ char *s = getenv("SOCKET_WRAPPER_DIR");
+
+ (void) state; /* unused */
+
+ assert_false(socket_wrapper_enabled());
+ assert_false(s != NULL);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest max_sockets_tests[] = {
+ cmocka_unit_test_setup_teardown(test_call_enabled_true,
+ setup_enabled,
+ teardown_enabled),
+ cmocka_unit_test_setup_teardown(test_call_enabled_false,
+ setup_disabled,
+ teardown_disabled),
+ };
+
+ rc = cmocka_run_group_tests(max_sockets_tests, NULL, NULL);
+
+ return rc;
+}