From fb08b875e8da105d7bf704853fb7d5818c82ac3a Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 19 Jan 2023 16:18:56 +0100 Subject: [PATCH] Add test for _dbus_string_skip_blank() [smcv: Fix a memory leak] Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421 --- test/CMakeLists.txt | 1 + test/Makefile.am | 3 +++ test/internals/strings.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 test/internals/strings.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 494ca4ae..1a21e711 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 5c4d2d0e..b6cd093a 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 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 index 00000000..6027e6a2 --- /dev/null +++ b/test/internals/strings.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Ralf Habacker + * SPDX-License-Identifier: MIT + */ + +#include + +#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); +}