Add manual tcp test case.
authorRalf Habacker <ralf.habacker@freenet.de>
Wed, 28 Jan 2015 21:44:16 +0000 (22:44 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Fri, 30 Jan 2015 08:33:40 +0000 (09:33 +0100)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=87999
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
cmake/test/CMakeLists.txt
test/Makefile.am
test/manual-tcp.c [new file with mode: 0644]

index 54a920f800cec656ee5823d0f1aa73c12e8ded19..7676586e13ab17b50e3c84bf01cc02e53fa71de0 100644 (file)
@@ -54,6 +54,10 @@ set (test-sleep-forever_SOURCES
     ${CMAKE_SOURCE_DIR}/../test/test-sleep-forever.c
 )
 
+set (manual-tcp_SOURCES
+    ${CMAKE_SOURCE_DIR}/../test/manual-tcp.c
+)
+
 add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
 add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
 add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
@@ -64,6 +68,7 @@ add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES
 add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
 add_helper_executable(test-segfault ${test-segfault_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
 add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_test_executable(manual-tcp ${manual-tcp_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
 
 if(DBUS_WITH_GLIB)
     message(STATUS "with glib test apps")
index 173df74bd58521e83a7d6c89ae2f47716c62e120..c0c7a69ffd52e47bc018ce5558b5345ee7bfddb2 100644 (file)
@@ -123,6 +123,10 @@ manual_dir_iter_SOURCES = manual-dir-iter.c
 manual_dir_iter_CPPFLAGS = $(static_cppflags)
 manual_dir_iter_LDADD = $(top_builddir)/dbus/libdbus-internal.la
 
+manual_tcp_SOURCES = manual-tcp.c
+manual_tcp_CPPFLAGS = $(static_cppflags)
+manual_tcp_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+
 EXTRA_DIST = dbus-test-runner
 
 testexecdir = $(libdir)/dbus-1.0/test
@@ -135,7 +139,8 @@ installable_tests = \
        $(NULL)
 installable_manual_tests = \
        manual-dir-iter \
-       $(NULL)
+        manual-tcp \
+        $(NULL)
 
 if DBUS_WITH_GLIB
 installable_tests += \
diff --git a/test/manual-tcp.c b/test/manual-tcp.c
new file mode 100644 (file)
index 0000000..64691c9
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Simple manual tcp check
+ *
+ * supports:
+ * - server listening check
+ *
+ * syntax:  manual-tcp [<ipv4>|<ipv6>]
+ *
+*/
+
+#include "config.h"
+#include "dbus/dbus-server-socket.h"
+
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+    DBusServer      *server;
+    DBusError       error;
+    int result = 0;
+    int i;
+
+    char *family = NULL;
+
+    if (argc == 2)
+        family = argv[1];
+
+    for (i = 0; i < 1000; i++)
+    {
+        dbus_error_init (&error);
+        server = _dbus_server_new_for_tcp_socket ("localhost", "localhost", "0", family, &error, FALSE);
+        if (server == NULL)
+          {
+            printf("%d: %s %s\n",i, error.name, error.message);
+            dbus_error_free(&error);
+            result = -1;
+          }
+        else {
+            printf("%d: %s \n",i, dbus_server_get_address(server));
+            dbus_server_disconnect(server);
+            dbus_server_unref(server);
+        }
+    }
+    return result;
+}