No empty .Rs/.Re
[netbsd-mini2440.git] / regress / lib / libc / gen / tfmtcheck / tfmtcheck.c
blob2320e014000dbfbc6d5baad8ca06334b6acaedcb
1 /* $NetBSD: tfmtcheck.c,v 1.2 2005/02/06 06:05:19 perry Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
11 * are met:
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 <stdio.h>
32 #include <stdlib.h>
34 const char *fmtcheck(const char *f1, const char *f2)
35 __attribute__((__format_arg__(2)));
37 #include <err.h>
39 struct test_fmt {
40 char *fmt1;
41 char *fmt2;
42 int correct;
43 } test_fmts[] = {
44 { "%d", "%d", 1 },
45 { "%2d", "%2.2d", 1 },
46 { "%x", "%d", 1 },
47 { "%u", "%d", 1 },
48 { "%03d", "%d", 1 },
49 { "%-2d", "%d", 1 },
50 { "%d", "%-12.1d", 1 },
51 { "%d", "%-01.3d", 1 },
52 { "%X", "%-01.3d", 1 },
53 { "%D", "%ld", 1 },
54 { "%s", "%s", 1 },
55 { "%s", "This is a %s test", 1 },
56 { "Hi, there. This is a %s test", "%s", 1 },
57 { "%d", "%s", 2 },
58 { "%e", "%s", 2 },
59 { "%r", "%d", 2 },
60 { "%*.2d", "%*d", 1 },
61 { "%2.*d", "%*d", 2 },
62 { "%*d", "%*d", 1 },
63 { "%-3", "%d", 2 },
64 { "%d %s", "%d", 2 },
65 { "%*.*.*d", "%*.*.*d", 2 },
66 { "%d", "%d %s", 1 },
67 { "%40s", "%20s", 1 },
68 { "%x %x %x", "%o %u %d", 1 },
69 { "%o %u %d", "%x %x %X", 1 },
70 { "%#o %u %#-d", "%x %#x %X", 1 },
71 { "%qd", "%llx", 1 },
72 { "%%", "%llx", 1 },
73 { "%p %30s %#llx %-10.*e", "This number %lu%% and string %s has %qd numbers and %.*g floats", 1 },
76 int
77 main(int argc, char *argv[])
79 int i, n, r;
80 const char *f, *cf, *f1, *f2;
82 r = 0;
83 n = sizeof(test_fmts) / sizeof(test_fmts[0]);
84 for (i=0 ; i<n ; i++) {
85 f1 = test_fmts[i].fmt1;
86 f2 = test_fmts[i].fmt2;
87 f = fmtcheck(f1, f2);
88 if (test_fmts[i].correct == 1) {
89 cf = f1;
90 } else {
91 cf = f2;
93 if (f != cf) {
94 r++;
95 errx(1, "Test %d: (%s) vs. (%s) failed "
96 "(should have returned %s)", i, f1, f2,
97 (test_fmts[i].correct == 1) ? "1st" : "2nd");
100 exit(0);