diff options
Diffstat (limited to 'test/internals')
-rw-r--r-- | test/internals/printf.c | 88 | ||||
-rw-r--r-- | test/internals/refs.c | 1 | ||||
-rw-r--r-- | test/internals/syslog.c | 10 |
3 files changed, 93 insertions, 6 deletions
diff --git a/test/internals/printf.c b/test/internals/printf.c new file mode 100644 index 00000000..db151518 --- /dev/null +++ b/test/internals/printf.c @@ -0,0 +1,88 @@ +/* Regression test for _dbus_printf_string_upper_bound + * + * Author: Simon McVittie <simon.mcvittie@collabora.co.uk> + * Copyright © 2013 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include <config.h> + +#include <dbus/dbus.h> +#include <dbus/dbus-internals.h> +#include <dbus/dbus-string.h> +#include "test-utils.h" + +#include <stdio.h> +#include <stdlib.h> + +static void +do_test (int minimum, + const char *format, + ...) +{ + va_list ap; + int result; + + va_start (ap, format); + result = _dbus_printf_string_upper_bound (format, ap); + va_end (ap); + + if (result < minimum) + { + fprintf (stderr, "expected at least %d, got %d\n", minimum, result); + abort (); + } +} + +#define X_TIMES_8 "XXXXXXXX" +#define X_TIMES_16 X_TIMES_8 X_TIMES_8 +#define X_TIMES_32 X_TIMES_16 X_TIMES_16 +#define X_TIMES_64 X_TIMES_32 X_TIMES_32 +#define X_TIMES_128 X_TIMES_64 X_TIMES_64 +#define X_TIMES_256 X_TIMES_128 X_TIMES_128 +#define X_TIMES_512 X_TIMES_256 X_TIMES_256 +#define X_TIMES_1024 X_TIMES_512 X_TIMES_512 + +int +main (int argc, + char **argv) +{ + char buf[] = X_TIMES_1024 X_TIMES_1024 X_TIMES_1024 X_TIMES_1024; + int i; + + do_test (1, "%d", 0); + do_test (7, "%d", 1234567); + do_test (3, "%f", 3.5); + + do_test (0, "%s", ""); + do_test (1024, "%s", X_TIMES_1024); + do_test (1025, "%s", X_TIMES_1024 "Y"); + + for (i = 4096; i > 0; i--) + { + buf[i] = '\0'; + do_test (i, "%s", buf); + do_test (i + 3, "%s:%d", buf, 42); + } + + return 0; +} diff --git a/test/internals/refs.c b/test/internals/refs.c index db43a4da..202dc043 100644 --- a/test/internals/refs.c +++ b/test/internals/refs.c @@ -29,7 +29,6 @@ #include <glib.h> #include <glib-object.h> -#define DBUS_COMPILATION /* this test uses libdbus-internal */ #include <dbus/dbus.h> #include <dbus/dbus-connection-internal.h> #include <dbus/dbus-mainloop.h> diff --git a/test/internals/syslog.c b/test/internals/syslog.c index 4f6b7c22..7e0eae79 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -30,7 +30,6 @@ #include <glib.h> -#define DBUS_COMPILATION /* this test uses libdbus-internal */ #include <dbus/dbus.h> #include <dbus/dbus-sysdeps.h> @@ -52,9 +51,10 @@ static void test_syslog (Fixture *f, gconstpointer data) { +#ifndef G_OS_WIN32 if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_FATAL, MESSAGE "%d", 23); /* should not be reached: exit 0 so the assertion in the main process * will fail */ @@ -66,7 +66,7 @@ test_syslog (Fixture *f, if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666); exit (0); @@ -74,9 +74,9 @@ test_syslog (Fixture *f, g_test_trap_assert_passed (); g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*"); - +#endif /* manual test (this is the best we can do on Windows) */ - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666); } |