xref: /titanic_50/usr/src/lib/libsqlite/test/printf.test (revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9)
1
2#pragma ident	"%Z%%M%	%I%	%E% SMI"
3
4# 2001 September 15
5#
6# The author disclaims copyright to this source code.  In place of
7# a legal notice, here is a blessing:
8#
9#    May you do good and not evil.
10#    May you find forgiveness for yourself and forgive others.
11#    May you share freely, never taking more than you give.
12#
13#***********************************************************************
14# This file implements regression tests for SQLite library.  The
15# focus of this file is testing the sqlite_*_printf() interface.
16#
17# $Id: printf.test,v 1.8 2004/02/21 19:41:05 drh Exp $
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21
22set n 1
23foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
24  do_test printf-1.$n.1 [subst {
25    sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
26  }] [format {Three integers: %d %x %o} $v $v $v]
27  do_test printf-1.$n.2 [subst {
28    sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
29  }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
30  do_test printf-1.$n.3 [subst {
31    sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
32  }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
33  do_test printf-1.$n.4 [subst {
34    sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
35  }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
36  do_test printf-1.$n.5 [subst {
37    sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
38  }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
39  do_test printf-1.$n.6 [subst {
40    sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
41  }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
42  incr n
43}
44
45
46if {$::tcl_platform(platform)!="windows"} {
47
48set m 1
49foreach {a b} {1 1 5 5 10 10 10 5} {
50  set n 1
51  foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
52    do_test printf-2.$m.$n.1 [subst {
53      sqlite_mprintf_double {A double: %*.*f} $a $b $x
54    }] [format {A double: %*.*f} $a $b $x]
55    do_test printf-2.$m.$n.2 [subst {
56      sqlite_mprintf_double {A double: %*.*e} $a $b $x
57    }] [format {A double: %*.*e} $a $b $x]
58    do_test printf-2.$m.$n.3 [subst {
59      sqlite_mprintf_double {A double: %*.*g} $a $b $x
60    }] [format {A double: %*.*g} $a $b $x]
61    do_test printf-2.$m.$n.4 [subst {
62      sqlite_mprintf_double {A double: %d %d %g} $a $b $x
63    }] [format {A double: %d %d %g} $a $b $x]
64    do_test printf-2.$m.$n.5 [subst {
65      sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
66    }] [format {A double: %d %d %#g} $a $b $x]
67    incr n
68  }
69  incr m
70}
71
72}
73
74do_test printf-3.1 {
75  sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
76} [format {A String: (%*.*s)} 10 10 {This is the string}]
77do_test printf-3.2 {
78  sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
79} [format {A String: (%*.*s)} 10 5 {This is the string}]
80do_test printf-3.3 {
81  sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
82} [format {A String: (%*.*s)} -10 5 {This is the string}]
83do_test printf-3.4 {
84  sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
85} [format {%d %d A String: (%s)} 1 2 {This is the string}]
86do_test printf-3.5 {
87  sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
88} [format {%d %d A String: (%30s)} 1 2 {This is the string}]
89do_test printf-3.6 {
90  sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
91} [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
92
93do_test printf-4.1 {
94  sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
95} {1 2 A quoted string: 'Hi Y''all'}
96do_test printf-4.2 {
97  sqlite_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2
98} {1 2 A NULL pointer in %q: '(NULL)'}
99do_test printf-4.3 {
100  sqlite_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all}
101} {1 2 A quoted string: 'Hi Y''all'}
102do_test printf-4.4 {
103  sqlite_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2
104} {1 2 A NULL pointer in %Q: NULL}
105
106do_test printf-5.1 {
107  set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
108  string length $x
109} {994}
110do_test printf-5.2 {
111  sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
112} {-9 -10 (HelloHello) %}
113
114do_test printf-6.1 {
115  sqlite_mprintf_z_test , one two three four five six
116} {,one,two,three,four,five,six}
117
118
119do_test printf-7.1 {
120  sqlite_mprintf_scaled {A double: %g} 1.0e307 1.0
121} {A double: 1e+307}
122do_test printf-7.2 {
123  sqlite_mprintf_scaled {A double: %g} 1.0e307 10.0
124} {A double: 1e+308}
125do_test printf-7.3 {
126  sqlite_mprintf_scaled {A double: %g} 1.0e307 100.0
127} {A double: NaN}
128
129finish_test
130