Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/stdio add positional argument tests
details: https://anonhg.NetBSD.org/src/rev/2b35e3c33f2c
branches: trunk
changeset: 777414:2b35e3c33f2c
user: christos <christos%NetBSD.org@localhost>
date: Fri Feb 17 20:17:38 2012 +0000
description:
add positional argument tests
diffstat:
tests/lib/libc/stdio/Makefile | 3 +-
tests/lib/libc/stdio/t_printf.c | 54 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 2 deletions(-)
diffs (98 lines):
diff -r da17397e05d0 -r 2b35e3c33f2c tests/lib/libc/stdio/Makefile
--- a/tests/lib/libc/stdio/Makefile Fri Feb 17 19:57:53 2012 +0000
+++ b/tests/lib/libc/stdio/Makefile Fri Feb 17 20:17:38 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2011/09/11 09:02:46 jruoho Exp $
+# $NetBSD: Makefile,v 1.9 2012/02/17 20:17:38 christos Exp $
.include <bsd.own.mk>
@@ -12,5 +12,6 @@
TESTS_C+= t_popen
TESTS_C+= t_printf
TESTS_C+= t_scanf
+COPTS.t_printf.c += -Wno-format-nonliteral
.include <bsd.test.mk>
diff -r da17397e05d0 -r 2b35e3c33f2c tests/lib/libc/stdio/t_printf.c
--- a/tests/lib/libc/stdio/t_printf.c Fri Feb 17 19:57:53 2012 +0000
+++ b/tests/lib/libc/stdio/t_printf.c Fri Feb 17 20:17:38 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_printf.c,v 1.2 2011/07/13 11:17:03 jruoho Exp $ */
+/* $NetBSD: t_printf.c,v 1.3 2012/02/17 20:17:38 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,6 +29,7 @@
#include <atf-c.h>
#include <math.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
ATF_TC(snprintf_dotzero);
@@ -47,6 +48,54 @@
ATF_REQUIRE_STREQ(s, "0");
}
+ATF_TC(snprintf_posarg);
+ATF_TC_HEAD(snprintf_posarg, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "test for positional arguments");
+}
+
+ATF_TC_BODY(snprintf_posarg, tc)
+{
+ char s[16];
+
+ ATF_CHECK(snprintf(s, sizeof(s), "%1$d", -23) == 3);
+ ATF_REQUIRE_STREQ(s, "-23");
+}
+
+ATF_TC(snprintf_posarg_width);
+ATF_TC_HEAD(snprintf_posarg_width, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "test for positional arguments with "
+ "field width");
+}
+
+ATF_TC_BODY(snprintf_posarg_width, tc)
+{
+ char s[16];
+
+ ATF_CHECK(snprintf(s, sizeof(s), "%1$*2$d", -23, 4) == 4);
+ ATF_REQUIRE_STREQ(s, " -23");
+}
+
+ATF_TC(snprintf_posarg_error);
+ATF_TC_HEAD(snprintf_posarg_error, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "test for positional arguments out "
+ "of bounds");
+}
+
+ATF_TC_BODY(snprintf_posarg_error, tc)
+{
+ char s[16], fmt[32];
+
+ snprintf(fmt, sizeof(fmt), "%%%zu$d", SIZE_MAX / sizeof(size_t));
+
+ ATF_CHECK(snprintf(s, sizeof(s), fmt, -23) == -1);
+}
+
ATF_TC(sprintf_zeropad);
ATF_TC_HEAD(sprintf_zeropad, tc)
{
@@ -75,6 +124,9 @@
{
ATF_TP_ADD_TC(tp, snprintf_dotzero);
+ ATF_TP_ADD_TC(tp, snprintf_posarg);
+ ATF_TP_ADD_TC(tp, snprintf_posarg_width);
+ ATF_TP_ADD_TC(tp, snprintf_posarg_error);
ATF_TP_ADD_TC(tp, sprintf_zeropad);
return atf_no_error();
Home |
Main Index |
Thread Index |
Old Index