b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter/*
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * This file originated in realmd
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter *
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * Copyright 2012 Red Hat Inc
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter *
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 *
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * See the included COPYING file for more information.
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter *
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter * Author: Stef Walter <stefw@redhat.com>
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include "config.h"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include "src/util/safe-format-string.h"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include <check.h>
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include <popt.h>
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include <string.h>
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter#include <talloc.h>
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#ifndef ck_assert_int_ge
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y)
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#endif
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#ifndef ck_assert_int_lt
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y)
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik#endif
1c585a6d25e5a0f4d1627b1bf6c4e5bc7c81835eLukas Slebodnik
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltertypedef struct {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter const char *format;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter const char *args[8];
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter const char *result;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter} Fixture;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walterstatic const Fixture fixtures[] = {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Just a bog standard string */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%s", { "blah", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "blah"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Empty to print */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%s", { "", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ""
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Nothing to print */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "", { "blah", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ""
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width right aligned */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%8s", { "blah", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter " blah"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width left aligned */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop %-8s doo", { "dee", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width space aligned (ignored) */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop % 8s doo", { "dee", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Width left space aligned (ignored) */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop % -8s doo", { "dee", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Precision 1 digit */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop %.3s doo", { "deedle-dee", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop dee doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
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 },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Precision, zero digits */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop %.s doo", { "deedle", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "whoop doo"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Multiple simple arguments */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %s %s", { "man", "dances", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space man dances"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Literal percent */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "100%% of space folk dance", { NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "100% of space folk dance"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Multiple simple arguments */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %2$s %1$s", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space man dances"
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
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 },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Failures start here */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Unsupported conversion */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%x", { "blah", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter NULL
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Bad positional argument */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %55$s dances", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter NULL
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Zero positional argument */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "space %0$s dances", { "dances", "man", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter NULL
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Too many args used */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%s %s dances", { "space", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter NULL
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* Too many digits used */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "%1234567890s dances", { "space", NULL, },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter NULL
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter },
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter};
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walterstatic void
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltercallback(void *data, const char *piece, size_t len)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter{
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter char **str = data;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter *str = talloc_strndup_append(*str, piece, len);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter}
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef WalterSTART_TEST(test_safe_format_string_cb)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter{
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter const Fixture *fixture;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter char *out;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter int num_args;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter int ret;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter void *mem_ctx;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter fixture = &fixtures[_i];
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter mem_ctx = talloc_init("safe-printf");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter for (num_args = 0; fixture->args[num_args] != NULL; )
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter num_args++;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter out = talloc_strdup(mem_ctx, "");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string_cb(callback, &out, fixture->format,
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter (const char * const*)fixture->args, num_args);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter if (fixture->result) {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_ge(ret, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_str_eq(out, fixture->result);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_eq(ret, strlen(out));
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter } else {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_lt(ret, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter }
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter talloc_free(mem_ctx);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter}
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef WalterEND_TEST
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef WalterSTART_TEST(test_safe_format_string)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter{
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter char buffer[8];
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter int ret;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "%s", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_eq(ret, 5);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_str_eq(buffer, "space");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_eq(ret, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_str_eq(buffer, "");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "the %s %s dances away", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_eq(ret, 25);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_str_eq(buffer, "the spa");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(NULL, 0, "the %s %s dances away", "space", "man", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_eq(ret, 25);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ret = safe_format_string(buffer, 8, "%5$s", NULL);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter ck_assert_int_lt(ret, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter}
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef WalterEND_TEST
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walterstatic Suite *
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltercreate_safe_format_suite(void)
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter{
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter Suite *s = suite_create("safe-format");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter TCase *tc_format = tcase_create("safe-format-string");
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* One for each fixture */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter tcase_add_loop_test(tc_format, test_safe_format_string_cb, 0,
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter (sizeof (fixtures) / sizeof (fixtures[0])));
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter tcase_add_test(tc_format, test_safe_format_string);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter suite_add_tcase(s, tc_format);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter return s;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter}
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walterint
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Waltermain(int argc, const char *argv[])
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter{
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter int opt;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter poptContext pc;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter int failure_count;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter Suite *suite;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter SRunner *sr;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter struct poptOption long_options[] = {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter POPT_AUTOHELP
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter POPT_TABLEEND
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter };
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter while((opt = poptGetNextOpt(pc)) != -1) {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter switch(opt) {
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter default:
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter fprintf(stderr, "\nInvalid option %s: %s\n\n",
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter poptBadOption(pc, 0), poptStrerror(opt));
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter poptPrintUsage(pc, stderr, 0);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter return 1;
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter }
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter }
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter poptFreeContext(pc);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter suite = create_safe_format_suite();
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter sr = srunner_create(suite);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter srunner_run_all(sr, CK_ENV);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter failure_count = srunner_ntests_failed(sr);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter srunner_free(sr);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter return (failure_count==0 ? EXIT_SUCCESS : EXIT_FAILURE);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter}