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