1 /* $NetBSD: tfmtcheck.c,v 1.3 2008/04/28 20:23:04 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code was contributed to The NetBSD Foundation by Allen Briggs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
47 { "%2d", "%2.2d", 1 },
52 { "%d", "%-12.1d", 1 },
53 { "%d", "%-01.3d", 1 },
54 { "%X", "%-01.3d", 1 },
57 { "%s", "This is a %s test", 1 },
58 { "Hi, there. This is a %s test", "%s", 1 },
62 { "%*.2d", "%*d", 1 },
63 { "%2.*d", "%*d", 2 },
67 { "%*.*.*d", "%*.*.*d", 2 },
69 { "%40s", "%20s", 1 },
70 { "%x %x %x", "%o %u %d", 1 },
71 { "%o %u %d", "%x %x %X", 1 },
72 { "%#o %u %#-d", "%x %#x %X", 1 },
75 { "%p %30s %#llx %-10.*e", "This number %lu%% and string %s has %qd numbers and %.*g floats", 1 },
78 ATF_TC_WITHOUT_HEAD(fmtcheck_test);
79 ATF_TC_BODY(fmtcheck_test, tc)
82 const char *f, *cf, *f1, *f2;
84 for (i = 0; i < nitems(test_fmts); i++) {
85 f1 = test_fmts[i].fmt1;
86 f2 = test_fmts[i].fmt2;
88 if (test_fmts[i].correct == 1)
92 ATF_CHECK_MSG(f == cf,
93 "Test %d: (%s) vs. (%s) failed "
94 "(should have returned %s)", i + 1, f1, f2,
95 (test_fmts[i].correct == 1) ? "1st" : "2nd");
102 ATF_TP_ADD_TC(tp, fmtcheck_test);
104 return (atf_no_error());