File: integer-test

package info (click to toggle)
autogen 5.3.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,216 kB
  • ctags: 2,706
  • sloc: ansic: 17,527; sh: 11,794; awk: 629; makefile: 556; lisp: 164; yacc: 50
file content (237 lines) | stat: -rwxr-xr-x 6,864 bytes parent folder | download
1
2
3
4
5
6
7
8
9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#! /bin/sh
#  -*- Mode: Sh -*- 
# ----------------------------------------------------------------------
# integer-test--- %i specifier
#
# Author:	      Gary V. Vaughan <gvv@techie.com>
# Maintainer:	      Gary V. Vaughan <gvv@techie.com>
# Created:	      Thu Nov 26 15:50:31 1998
# Last Modified:      Thu Sep 23 23:16:53 1999
#            by:      Gary V. Vaughan <gvv@techie.com>
# ----------------------------------------------------------------------
# @(#) $Id: integer-test,v 1.2 2000/07/27 15:46:01 bkorb Exp $
# ----------------------------------------------------------------------
# Copyright (C) 1998, 1999 Gary V. Vaughan
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that also links with and
# uses the libopts library from AutoGen, you may include it under
# the same distribution terms used by the libopts library.

# Code:

# Common definitions
if test -z "$srcdir"; then
    srcdir=`echo "$0" | sed 's,[^/]*$,,'`
    test "$srcdir" = "$0" && srcdir=.
    test -z "$srcdir" && srcdir=.
    test "${VERBOSE+set}" != set && VERBOSE=1
fi
. $srcdir/defs


# this is the output we should expect to see
cat <<\EOF >ok
1 10
*** printfv returned 4 chars.
2 -11
*** printfv returned 5 chars.
3 >20<
*** printfv returned 6 chars.
4 >-22<
*** printfv returned 7 chars.
5 333
*** printfv returned 5 chars.
6 -300
*** printfv returned 6 chars.
7         40
*** printfv returned 12 chars.
8        -44
*** printfv returned 12 chars.
9 55555
*** printfv returned 7 chars.
10 -50000
*** printfv returned 9 chars.
11 66666
*** printfv returned 8 chars.
12 -60000
*** printfv returned 9 chars.
13 0000077777
*** printfv returned 13 chars.
14 -0000077777
*** printfv returned 14 chars.
15 8888
*** printfv returned 7 chars.
16 -8000
*** printfv returned 8 chars.
17 9999
*** printfv returned 7 chars.
18 -9000
*** printfv returned 8 chars.
19 1010
*** printfv returned 7 chars.
20 -1000
*** printfv returned 8 chars.
21 1111
*** printfv returned 7 chars.
22 -01100
*** printfv returned 9 chars.
23 01212
*** printfv returned 8 chars.
24 -01200
*** printfv returned 9 chars.
25 01313
*** printfv returned 8 chars.
26 -001300
*** printfv returned 10 chars.
27 1414.
*** printfv returned 8 chars.
28 -1400.
*** printfv returned 9 chars.
29 1515.
*** printfv returned 8 chars.
30 -1500.
*** printfv returned 9 chars.
31 1616 .
*** printfv returned 9 chars.
32 -1600 .
*** printfv returned 10 chars.
33 +1717
*** printfv returned 8 chars.
34 -1700
*** printfv returned 8 chars.
35  1818
*** printfv returned 8 chars.
36 -1800
*** printfv returned 8 chars.
37  1819
*** printfv returned 8 chars.
38  -1820
*** printfv returned 9 chars.
39 +1821
*** printfv returned 8 chars.
40 +1822
*** printfv returned 8 chars.
41 1919
*** printfv returned 7 chars.
42 2147483647
*** printfv returned 13 chars.
43 -2147483648
*** printfv returned 14 chars.
44 +000001234
*** printfv returned 13 chars.
45 -00234   .
*** printfv returned 13 chars.
EOF

cat <<\EOF >errok
EOF

# straight forward integer output
$SNPRINTFV '1 %i' 10 2> err | tee -ai out >&2
$SNPRINTFV '2 %i' -11 2> err | tee -ai out >&2
$SNPRINTFV '3 >%i<' 20 2> err | tee -ai out >&2
$SNPRINTFV '4 >%i<' -22 2> err | tee -ai out >&2

# test width flag
$SNPRINTFV '5 %2i' 333 2> err | tee -ai out >&2
$SNPRINTFV '6 %1i' -300 2> err | tee -ai out >&2
$SNPRINTFV '7 %10i' 40 2> err | tee -ai out >&2
$SNPRINTFV '8 %10i' -44 2> err | tee -ai out >&2

# test precision flag
$SNPRINTFV '9 %.3i' 55555 2> err | tee -ai out >&2
$SNPRINTFV '10 %.3i' -50000 2> err | tee -ai out >&2
$SNPRINTFV '11 %.5i' 66666 2> err | tee -ai out >&2
$SNPRINTFV '12 %.5i' -60000 2> err | tee -ai out >&2
$SNPRINTFV '13 %.10i' 77777 2> err | tee -ai out >&2
$SNPRINTFV '14 %.10i' -77777 2> err | tee -ai out >&2

# test zero padding
$SNPRINTFV '15 %03i' 8888 2> err | tee -ai out >&2
$SNPRINTFV '16 %04i' -8000 2> err | tee -ai out >&2
$SNPRINTFV '17 %0.3i' 9999 2> err | tee -ai out >&2
$SNPRINTFV '18 %0.4i' -9000 2> err | tee -ai out >&2

$SNPRINTFV '19 %04i' 1010 2> err | tee -ai out >&2
$SNPRINTFV '20 %05i' -1000 2> err | tee -ai out >&2
$SNPRINTFV '21 %0.4i' 1111 2> err | tee -ai out >&2
$SNPRINTFV '22 %0.5i' -1100 2> err | tee -ai out >&2

$SNPRINTFV '23 %05i' 1212 2> err | tee -ai out >&2
$SNPRINTFV '24 %06i' -1200 2> err | tee -ai out >&2
$SNPRINTFV '25 %0.5i' 1313 2> err | tee -ai out >&2
$SNPRINTFV '26 %0.6i' -1300 2> err | tee -ai out >&2

# test grouping flag
# TODO!

# test left justfy flag
$SNPRINTFV '27 %-3i.' 1414 2> err | tee -ai out >&2
$SNPRINTFV '28 %-4i.' -1400 2> err | tee -ai out >&2
$SNPRINTFV '29 %-4i.' 1515 2> err | tee -ai out >&2
$SNPRINTFV '30 %-5i.' -1500 2> err | tee -ai out >&2
$SNPRINTFV '31 %-5i.' 1616 2> err | tee -ai out >&2
$SNPRINTFV '32 %-6i.' -1600 2> err | tee -ai out >&2

# test sign flag
$SNPRINTFV '33 %+i' 1717 2> err | tee -ai out >&2
$SNPRINTFV '34 %+i' -1700 2> err | tee -ai out >&2

# test blank flag
$SNPRINTFV '35 % i' 1818 2> err | tee -ai out >&2
$SNPRINTFV '36 % i' -1800 2> err | tee -ai out >&2
$SNPRINTFV '37 % 5i' 1819 2> err | tee -ai out >&2
$SNPRINTFV '38 % 6i' -1820 2> err | tee -ai out >&2
$SNPRINTFV '39 %+ i' 1821 2> err | tee -ai out >&2
$SNPRINTFV '40 % +i' 1822 2> err | tee -ai out >&2

# test long modifier  (these tests fail if sizeof(long) < 4)
$SNPRINTFV '41 %li' 1919L 2> err | tee -ai out >&2
$SNPRINTFV '42 %li' 2147483647L 2> err | tee -ai out >&2
$SNPRINTFV '43 %li' -2147483648L 2> err | tee -ai out >&2

# try a bizarre combination
$SNPRINTFV '44 %+09.3i' 1234 2> err | tee -ai out >&2
$SNPRINTFV '45 %-09.5i.' -234 2> err | tee -ai out >&2

# Test against expected output
if ${CMP} -s out ok; then
    :
else
    echo "ok:" >&2
    cat ok >&2
    exit 1
fi

# Munge error output to remove leading directories, `lt-' or trailing `.exe'
sed -e "s,^[^:]*[lt-]*snprintfv-test[.ex]*:,snprintfv-test:," err >sederr \
    && mv sederr err

# Show stderr if doesn't match expected output if VERBOSE == 1
if "$CMP" -s err errok; then
    :
else
    echo "err:" >&2
    cat err >&2
    echo "errok:" >&2
    cat errok >&2
    exit 1
fi

# integer-test ends here