blob: 2fffeb2159059f93d6a575bfcd305428b9682b68 [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#
26# $Id: printf.test,v 1.1 2001/04/07 15:24:33 drh Exp $
27
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]
42 incr n
43}
44
45set m 1
46foreach {a b} {1 1 5 5 10 10 10 5} {
47 set n 1
48 foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
49 do_test printf-2.$m.$n.1 [subst {
50 sqlite_mprintf_double {A double: %*.*f} $a $b $x
51 }] [format {A double: %*.*f} $a $b $x]
52 do_test printf-2.$m.$n.2 [subst {
53 sqlite_mprintf_double {A double: %*.*e} $a $b $x
54 }] [format {A double: %*.*e} $a $b $x]
55 do_test printf-2.$m.$n.3 [subst {
56 sqlite_mprintf_double {A double: %*.*g} $a $b $x
57 }] [format {A double: %*.*g} $a $b $x]
58 do_test printf-2.$m.$n.4 [subst {
59 sqlite_mprintf_double {A double: %d %d %g} $a $b $x
60 }] [format {A double: %d %d %g} $a $b $x]
61 do_test printf-2.$m.$n.5 [subst {
62 sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
63 }] [format {A double: %d %d %#g} $a $b $x]
64 incr n
65 }
66 incr m
67}
68
69do_test printf-3.1 {
70 sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
71} [format {A String: (%*.*s)} 10 10 {This is the string}]
72do_test printf-3.2 {
73 sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
74} [format {A String: (%*.*s)} 10 5 {This is the string}]
75do_test printf-3.3 {
76 sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
77} [format {A String: (%*.*s)} -10 5 {This is the string}]
78do_test printf-3.4 {
79 sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
80} [format {%d %d A String: (%s)} 1 2 {This is the string}]
81do_test printf-3.5 {
82 sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
83} [format {%d %d A String: (%30s)} 1 2 {This is the string}]
84do_test printf-3.6 {
85 sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
86} [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
87
88do_test printf-4.1 {
89 sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
90} {1 2 A quoted string: 'Hi Y''all'}
91
92finish_test