b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * This file originated in realmd
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * Copyright 2012 Red Hat Inc
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * This program is free software: you can redistribute it and/or modify
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * it under the terms of the GNU Lesser General Public License as published
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * by the Free Software Foundation; either version 2 of the licence or (at
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * your option) any later version.
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * See the included COPYING file for more information.
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * Author: Stef Walter <stefw@redhat.com>
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y)
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltertypedef struct {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Just a bog standard string */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Empty to print */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Nothing to print */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width right aligned */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width left aligned */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width space aligned (ignored) */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width left space aligned (ignored) */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Precision 1 digit */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Precision, N digits */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop %.10s doo", { "deedle-dee-deedle-do-deedle-dum", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop deedle-dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Precision, zero digits */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Multiple simple arguments */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space man dances"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Literal percent */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "100% of space folk dance"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Multiple simple arguments */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space man dances"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Skipping an argument (not supported by standard printf) */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %2$s dances", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space man dances"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Failures start here */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Unsupported conversion */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Bad positional argument */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %55$s dances", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Zero positional argument */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %0$s dances", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Too many args used */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Too many digits used */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltercallback(void *data, const char *piece, size_t len)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter for (num_args = 0; fixture->args[num_args] != NULL; )
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string_cb(callback, &out, fixture->format,
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "%s", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "the %s %s dances away", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(NULL, 0, "the %s %s dances away", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "%5$s", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter TCase *tc_format = tcase_create("safe-format-string");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* One for each fixture */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter tcase_add_loop_test(tc_format, test_safe_format_string_cb, 0,
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter tcase_add_test(tc_format, test_safe_format_string);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */