1 /* Regression test for _dbus_printf_string_upper_bound
3 * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
4 * Copyright © 2013 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <dbus/dbus.h>
30 #include <dbus/dbus-internals.h>
31 #include <dbus/dbus-string.h>
32 #include "test-utils.h"
45 va_start (ap, format);
46 result = _dbus_printf_string_upper_bound (format, ap);
51 fprintf (stderr, "expected at least %d, got %d\n", minimum, result);
56 #define X_TIMES_8 "XXXXXXXX"
57 #define X_TIMES_16 X_TIMES_8 X_TIMES_8
58 #define X_TIMES_32 X_TIMES_16 X_TIMES_16
59 #define X_TIMES_64 X_TIMES_32 X_TIMES_32
60 #define X_TIMES_128 X_TIMES_64 X_TIMES_64
61 #define X_TIMES_256 X_TIMES_128 X_TIMES_128
62 #define X_TIMES_512 X_TIMES_256 X_TIMES_256
63 #define X_TIMES_1024 X_TIMES_512 X_TIMES_512
69 char buf[] = X_TIMES_1024 X_TIMES_1024 X_TIMES_1024 X_TIMES_1024;
73 do_test (7, "%d", 1234567);
74 do_test (3, "%f", 3.5);
76 do_test (0, "%s", "");
77 do_test (1024, "%s", X_TIMES_1024);
78 do_test (1025, "%s", X_TIMES_1024 "Y");
80 for (i = 4096; i > 0; i--)
83 do_test (i, "%s", buf);
84 do_test (i + 3, "%s:%d", buf, 42);