2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the sqlite_*_printf() interface.
2N/Aset testdir [file dirname $argv0]
2N/Aforeach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
2N/A do_test printf-1.$n.1 [subst {
2N/A sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
2N/A }] [format {Three integers: %d %x %o} $v $v $v]
2N/A do_test printf-1.$n.2 [subst {
2N/A sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
2N/A }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
2N/A do_test printf-1.$n.3 [subst {
2N/A sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
2N/A }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
2N/A do_test printf-1.$n.4 [subst {
2N/A sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
2N/A }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
2N/A do_test printf-1.$n.5 [subst {
2N/A sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
2N/A }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
2N/A do_test printf-1.$n.6 [subst {
2N/A sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
2N/A }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
2N/Aif {$::tcl_platform(platform)!="windows"} {
2N/Aforeach {a b} {1 1 5 5 10 10 10 5} {
2N/A foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
2N/A do_test printf-2.$m.$n.1 [subst {
2N/A sqlite_mprintf_double {A double: %*.*f} $a $b $x
2N/A }] [format {A double: %*.*f} $a $b $x]
2N/A do_test printf-2.$m.$n.2 [subst {
2N/A sqlite_mprintf_double {A double: %*.*e} $a $b $x
2N/A }] [format {A double: %*.*e} $a $b $x]
2N/A do_test printf-2.$m.$n.3 [subst {
2N/A sqlite_mprintf_double {A double: %*.*g} $a $b $x
2N/A }] [format {A double: %*.*g} $a $b $x]
2N/A do_test printf-2.$m.$n.4 [subst {
2N/A sqlite_mprintf_double {A double: %d %d %g} $a $b $x
2N/A }] [format {A double: %d %d %g} $a $b $x]
2N/A do_test printf-2.$m.$n.5 [subst {
2N/A sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
2N/A }] [format {A double: %d %d %#g} $a $b $x]
2N/A sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
2N/A} [format {A String: (%*.*s)} 10 10 {This is the string}]
2N/A sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
2N/A} [format {A String: (%*.*s)} 10 5 {This is the string}]
2N/A sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
2N/A} [format {A String: (%*.*s)} -10 5 {This is the string}]
2N/A sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
2N/A} [format {%d %d A String: (%s)} 1 2 {This is the string}]
2N/A sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
2N/A} [format {%d %d A String: (%30s)} 1 2 {This is the string}]
2N/A sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
2N/A} [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
2N/A sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
2N/A} {1 2 A quoted string: 'Hi Y''all'}
2N/A sqlite_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2
2N/A} {1 2 A NULL pointer in %q: '(NULL)'}
2N/A sqlite_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all}
2N/A} {1 2 A quoted string: 'Hi Y''all'}
2N/A sqlite_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2
2N/A} {1 2 A NULL pointer in %Q: NULL}
2N/A set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
2N/A sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
2N/A} {-9 -10 (HelloHello) %}
2N/A sqlite_mprintf_z_test , one two three four five six
2N/A} {,one,two,three,four,five,six}
2N/A sqlite_mprintf_scaled {A double: %g} 1.0e307 1.0
2N/A sqlite_mprintf_scaled {A double: %g} 1.0e307 10.0
2N/A sqlite_mprintf_scaled {A double: %g} 1.0e307 100.0