Add test for _dbus_string_skip_blank()

[smcv: Fix a memory leak]

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421
This commit is contained in:
Ralf Habacker 2023-01-19 16:18:56 +01:00 committed by Simon McVittie
parent 7a30ab94e6
commit 8189a74c6c
4 changed files with 54 additions and 0 deletions

View 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)

View File

@ -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

45
test/internals/strings.c Normal file
View File

@ -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);
}

View File

@ -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' ],