]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Add test for _dbus_string_skip_blank()
authorRalf Habacker <ralf.habacker@freenet.de>
Thu, 19 Jan 2023 15:18:56 +0000 (16:18 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 8 Feb 2023 12:04:09 +0000 (12:04 +0000)
[smcv: Fix a memory leak]

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421

test/CMakeLists.txt
test/Makefile.am
test/internals/strings.c [new file with mode: 0644]

index 494ca4aed67129d9e0d8519852f688a6df0ada08..1a21e711cae57fe8635c3d9c9f3b870e42dc0c73 100644 (file)
@@ -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)
index 5c4d2d0efb00da69d20f922b94612ed442d64470..b6cd093aa32ea39b10eb420321514e65ea8e1cb1 100644 (file)
@@ -90,6 +90,7 @@ uninstallable_test_programs += \
        test-bus-dispatch-sha1 \
        test-marshal-recursive \
        test-message-internals \
+       test-strings \
        $(NULL)
 
 if DBUS_UNIX
@@ -131,6 +132,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 (file)
index 0000000..6027e6a
--- /dev/null
@@ -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);
+}