summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2023-01-19 16:18:56 +0100
committerSimon McVittie <smcv@collabora.com>2023-02-08 12:03:19 +0000
commit8189a74c6cc40c0ce10b91eb999ab26f7ceef82b (patch)
treee4e87a81455f8b4125c58735b5fd438121f53689
parent7a30ab94e698f3f641ff1576f6310fa099956e87 (diff)
downloaddbus-8189a74c6cc40c0ce10b91eb999ab26f7ceef82b.tar.gz
Add test for _dbus_string_skip_blank()
[smcv: Fix a memory leak] Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/Makefile.am3
-rw-r--r--test/internals/strings.c45
-rw-r--r--test/meson.build5
4 files changed, 54 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a4259ae4..22a80404 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -78,6 +78,7 @@ add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL
add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_test_executable(test-string internals/strings.c dbus-testutils)
add_test_executable(test-printf internals/printf.c dbus-testutils)
add_helper_executable(test-privserver test-privserver.c dbus-testutils)
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
diff --git a/test/Makefile.am b/test/Makefile.am
index 000984cf..63cb7578 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -90,6 +90,7 @@ uninstallable_test_programs += \
test-bus-dispatch-sha1 \
test-marshal-recursive \
test-message-internals \
+ test-strings \
$(NULL)
if ENABLE_TRADITIONAL_ACTIVATION
@@ -137,6 +138,8 @@ test_privserver_LDADD = libdbus-testutils.la
test_shell_service_LDADD = libdbus-testutils.la
test_shell_SOURCES = shell-test.c
test_shell_LDADD = libdbus-testutils.la
+test_strings_SOURCES = internals/strings.c
+test_strings_LDADD = libdbus-testutils.la
if ENABLE_TRADITIONAL_ACTIVATION
test_spawn_SOURCES = spawn-test.c
diff --git a/test/internals/strings.c b/test/internals/strings.c
new file mode 100644
index 00000000..6027e6a2
--- /dev/null
+++ b/test/internals/strings.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2023 Ralf Habacker
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <config.h>
+
+#include "dbus/dbus-string.h"
+#include "dbus/dbus-test.h"
+#include "dbus/dbus-test-tap.h"
+#include "test/test-utils.h"
+
+static dbus_bool_t
+_dbus_string_skip_blank_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
+{
+ int end;
+ DBusString s = _DBUS_STRING_INIT_INVALID;
+ const char *p = " \rT\r\n";
+
+ _dbus_string_init (&s);
+ if (!_dbus_string_append (&s, p))
+ {
+ _dbus_string_free (&s);
+ return FALSE;
+ }
+
+ _dbus_string_skip_blank (&s, 0, &end);
+ _dbus_string_free (&s);
+ return TRUE;
+}
+
+static const DBusTestCase test[] =
+{
+ { "skip_blank", _dbus_string_skip_blank_test },
+};
+
+
+int
+main (int argc,
+ char **argv)
+{
+ return _dbus_test_main (argc, argv, sizeof(test) / sizeof (DBusTestCase), test,
+ DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS,
+ NULL, NULL);
+}
diff --git a/test/meson.build b/test/meson.build
index 23ad6b0a..dd3855cc 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -398,6 +398,11 @@ tests += [
'link': [ libdbus_testutils, ],
},
{
+ 'name': 'strings',
+ 'srcs': [ 'internals/strings.c' ],
+ 'link': [ libdbus_testutils, ],
+ },
+ {
'name': 'printf',
'srcs': [ 'internals/printf.c' ],
'link': [ libdbus_testutils, ],