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