diff options
author | ngie <ngie@FreeBSD.org> | 2015-12-05 04:17:40 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-12-05 04:17:40 +0000 |
commit | fde15bf9a66c2d1600fc39cc4f6c9616516a8743 (patch) | |
tree | db28c4c2a0cb15c8423039892892e5756178c96d /lib/libc/tests/stdio/print_positional_test.c | |
parent | 233987c6df823b923e5622392372c4a05c615b6f (diff) | |
download | FreeBSD-src-fde15bf9a66c2d1600fc39cc4f6c9616516a8743.zip FreeBSD-src-fde15bf9a66c2d1600fc39cc4f6c9616516a8743.tar.gz |
MFC r290537,r290540,r290560,r290856,r290871,r291839:
r290537:
Integrate tools/regression/lib/libc/stdio into the FreeBSD test suite
as lib/libc/tests/stdio
- Fix some whitespace
- Convert the testcases to ATF
- Convert "/dev/null" to _PATH_DEVNULL
Sponsored by: EMC / Isilon Storage Division
r290540:
printfloat_test and scanfloat_test need symbols from msun; these are automatically
provided on amd64, but not i386. Add libm to DPADD/LDADD to unbreak the i386
tinderbox
Pointyhat to: ngie
Sponsored by: EMC / Isilon Storage Division
r290560:
Convert print_positional_test over to ATF
Somehow missed in r290537
Sponsored by: EMC / Isilon Storage Division
r290856 (by bapt):
also skip the definition of ':fopen_regular' to avoid the build to fail due to
unused variables defined by ATF macros
r290871:
Disable -Wformat with scanfloat_test when compiling with gcc to avoid a
"use of assignment suppression and length modifier together in scanf format"
warning on line 90 (it's intentional)
Sponsored by: EMC / Isilon Storage Division
r291839:
Initialize errno to 0 in the nul testcase before testing it
For some odd reason stable/10 requires this, otherwise it always fails
the errno == 0 check on line 196.
Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'lib/libc/tests/stdio/print_positional_test.c')
-rw-r--r-- | lib/libc/tests/stdio/print_positional_test.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/lib/libc/tests/stdio/print_positional_test.c b/lib/libc/tests/stdio/print_positional_test.c new file mode 100644 index 0000000..1de43a1 --- /dev/null +++ b/lib/libc/tests/stdio/print_positional_test.c @@ -0,0 +1,156 @@ +/* $OpenBSD: sprintf_test.c,v 1.3 2004/09/16 20:22:26 otto Exp $ */ + +/* + * Copyright (c) 2003 Theo de Raadt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> + +#include <atf-c.h> + +const char correct[] = + "|xx 01 02 03 04\n" + "|xx 05 06 07 08\n" + "|xx 09 10 11 12\n" + "|xx 13 14 15 16\n" + "|xx 17 18 19 20\n" + "|xx 21 22 23 24\n" + "|xx 25 26 27 28\n" + "|xx 29 30 31 32\n" + "|xx 33 34 35 36\n" + "|xx 37 38 39 40\n" + "|xx 41 42 43 44\n" + "|xx 45 -1 1 -1 1\n"; + +const char correct2[] = + "b bs BSD"; +static char buf[1024]; +static wchar_t wbuf1[1024], wbuf2[1024]; +static const char *temp; + +ATF_TC_WITHOUT_HEAD(positional_normal); +ATF_TC_BODY(positional_normal, tc) +{ + + /* Test positional arguments */ + snprintf(buf, sizeof buf, + "|xx %1$s %2$s %3$s %4$s\n" + "|xx %5$s %6$s %7$s %8$s\n" + "|xx %9$s %10$s %11$s %12$s\n" + "|xx %13$s %14$s %15$s %16$s\n" + "|xx %17$s %18$s %19$s %20$s\n" + "|xx %21$s %22$s %23$s %24$s\n" + "|xx %25$s %26$s %27$s %28$s\n" + "|xx %29$s %30$s %31$s %32$s\n" + "|xx %33$s %34$s %35$s %36$s\n" + "|xx %37$s %38$s %39$s %40$s\n" + "|xx %41$s %42$s %43$s %44$s\n" + "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", + "01", "02", "03", "04", "05", "06", + "07", "08", "09", "10", "11", "12", + "13", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", + "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", + "37", "38", "39", "40", "41", "42", + "43", "44", 45, -1L, 1LL, -1, 1LL + ); + ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0, + "buffers didn't match"); +} + +ATF_TC_WITHOUT_HEAD(positional_wide); +ATF_TC_BODY(positional_wide, tc) +{ + + swprintf(wbuf1, sizeof wbuf1, + L"|xx %1$s %2$s %3$s %4$s\n" + "|xx %5$s %6$s %7$s %8$s\n" + "|xx %9$s %10$s %11$s %12$s\n" + "|xx %13$s %14$s %15$s %16$s\n" + "|xx %17$s %18$s %19$s %20$s\n" + "|xx %21$s %22$s %23$s %24$s\n" + "|xx %25$s %26$s %27$s %28$s\n" + "|xx %29$s %30$s %31$s %32$s\n" + "|xx %33$s %34$s %35$s %36$s\n" + "|xx %37$s %38$s %39$s %40$s\n" + "|xx %41$s %42$s %43$s %44$s\n" + "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", + "01", "02", "03", "04", "05", "06", + "07", "08", "09", "10", "11", "12", + "13", "14", "15", "16", "17", "18", + "19", "20", "21", "22", "23", "24", + "25", "26", "27", "28", "29", "30", + "31", "32", "33", "34", "35", "36", + "37", "38", "39", "40", "41", "42", + "43", "44", 45, -1L, 1LL, -1, 1LL + ); + temp = correct; + mbsrtowcs(wbuf2, &temp, sizeof wbuf2, NULL); + ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0, + "buffers didn't match"); +} + +ATF_TC_WITHOUT_HEAD(positional_precision); +ATF_TC_BODY(positional_precision, tc) +{ + + snprintf(buf, sizeof buf, "%2$.*4$s %2$.*3$s %1$s", + "BSD", "bsd", 2, 1); + ATF_REQUIRE_MSG(strcmp(buf, correct2) == 0, + "buffers didn't match"); +} + +ATF_TC_WITHOUT_HEAD(positional_precision_wide); +ATF_TC_BODY(positional_precision_wide, tc) +{ + + swprintf(wbuf1, sizeof buf, L"%2$.*4$s %2$.*3$s %1$s", + "BSD", "bsd", 2, 1); + temp = correct2; + mbsrtowcs(wbuf2, &temp, sizeof wbuf2, NULL); + ATF_REQUIRE_MSG(wcscmp(wbuf1, wbuf2) == 0, + "buffers didn't match"); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, positional_normal); + ATF_TP_ADD_TC(tp, positional_wide); + ATF_TP_ADD_TC(tp, positional_precision); + ATF_TP_ADD_TC(tp, positional_precision_wide); + + return (atf_no_error()); +} |