From 8189a74c6cc40c0ce10b91eb999ab26f7ceef82b Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 19 Jan 2023 16:18:56 +0100 Subject: 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 +++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 5 +++++ 4 files changed, 54 insertions(+) create mode 100644 test/internals/strings.c 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 + +#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 @@ -397,6 +397,11 @@ tests += [ 'srcs': [ 'shell-test.c' ], 'link': [ libdbus_testutils, ], }, + { + 'name': 'strings', + 'srcs': [ 'internals/strings.c' ], + 'link': [ libdbus_testutils, ], + }, { 'name': 'printf', 'srcs': [ 'internals/printf.c' ], -- cgit v1.2.1