blob: 7941ab4c30b14d5ec381fc50c99c5da2e5d4f97c [file] [log] [blame]
drhd1bf3512001-04-07 15:24:33 +00001# Copyright (c) 2001 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 02111-1307, USA.
17#
18# Author contact information:
19# drh@hwaci.com
20# http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library. The
24# focus of this file is testing the sqlite_*_printf() interface.
25#
drhdaffd0e2001-04-11 14:28:42 +000026# $Id: printf.test,v 1.2 2001/04/11 14:28:43 drh Exp $
drhd1bf3512001-04-07 15:24:33 +000027
28set testdir [file dirname $argv0]
29source $testdir/tester.tcl
30
31set n 1
32foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
33 do_test printf-1.$n.1 [subst {
34 sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
35 }] [format {Three integers: %d %x %o} $v $v $v]
36 do_test printf-1.$n.2 [subst {
37 sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
38 }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
39 do_test printf-1.$n.3 [subst {
40 sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
41 }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
drhdaffd0e2001-04-11 14:28:42 +000042 do_test printf-1.$n.4 [subst {
43 sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
44 }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
45 do_test printf-1.$n.5 [subst {
46 sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
47 }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
48 do_test printf-1.$n.6 [subst {
49 sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
50 }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
drhd1bf3512001-04-07 15:24:33 +000051 incr n
52}
53
54set m 1
55foreach {a b} {1 1 5 5 10 10 10 5} {
56 set n 1
57 foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
58 do_test printf-2.$m.$n.1 [subst {
59 sqlite_mprintf_double {A double: %*.*f} $a $b $x
60 }] [format {A double: %*.*f} $a $b $x]
61 do_test printf-2.$m.$n.2 [subst {
62 sqlite_mprintf_double {A double: %*.*e} $a $b $x
63 }] [format {A double: %*.*e} $a $b $x]
64 do_test printf-2.$m.$n.3 [subst {
65 sqlite_mprintf_double {A double: %*.*g} $a $b $x
66 }] [format {A double: %*.*g} $a $b $x]
67 do_test printf-2.$m.$n.4 [subst {
68 sqlite_mprintf_double {A double: %d %d %g} $a $b $x
69 }] [format {A double: %d %d %g} $a $b $x]
70 do_test printf-2.$m.$n.5 [subst {
71 sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
72 }] [format {A double: %d %d %#g} $a $b $x]
73 incr n
74 }
75 incr m
76}
77
78do_test printf-3.1 {
79 sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
80} [format {A String: (%*.*s)} 10 10 {This is the string}]
81do_test printf-3.2 {
82 sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
83} [format {A String: (%*.*s)} 10 5 {This is the string}]
84do_test printf-3.3 {
85 sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
86} [format {A String: (%*.*s)} -10 5 {This is the string}]
87do_test printf-3.4 {
88 sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
89} [format {%d %d A String: (%s)} 1 2 {This is the string}]
90do_test printf-3.5 {
91 sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
92} [format {%d %d A String: (%30s)} 1 2 {This is the string}]
93do_test printf-3.6 {
94 sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
95} [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
96
97do_test printf-4.1 {
98 sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
99} {1 2 A quoted string: 'Hi Y''all'}
100
drhdaffd0e2001-04-11 14:28:42 +0000101do_test printf-5.1 {
102 set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
103 string length $x
104} {994}
105do_test printf-5.2 {
106 sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
107} {-9 -10 (HelloHello) %}
108do_test printf-5.3 {
109 sqlite_mprintf_str {%% %d %d (%=10s)} 5 6 Hello
110} {% 5 6 ( Hello )}
111
drhd1bf3512001-04-07 15:24:33 +0000112finish_test