1*1da57d55SToomas Soome# 27c478bd9Sstevel@tonic-gate# 2001 September 15 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The author disclaims copyright to this source code. In place of 57c478bd9Sstevel@tonic-gate# a legal notice, here is a blessing: 67c478bd9Sstevel@tonic-gate# 77c478bd9Sstevel@tonic-gate# May you do good and not evil. 87c478bd9Sstevel@tonic-gate# May you find forgiveness for yourself and forgive others. 97c478bd9Sstevel@tonic-gate# May you share freely, never taking more than you give. 107c478bd9Sstevel@tonic-gate# 117c478bd9Sstevel@tonic-gate#*********************************************************************** 127c478bd9Sstevel@tonic-gate# This file implements regression tests for SQLite library. The 137c478bd9Sstevel@tonic-gate# focus of this file is testing the sqlite_*_printf() interface. 147c478bd9Sstevel@tonic-gate# 157c478bd9Sstevel@tonic-gate# $Id: printf.test,v 1.8 2004/02/21 19:41:05 drh Exp $ 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gateset testdir [file dirname $argv0] 187c478bd9Sstevel@tonic-gatesource $testdir/tester.tcl 197c478bd9Sstevel@tonic-gate 207c478bd9Sstevel@tonic-gateset n 1 217c478bd9Sstevel@tonic-gateforeach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} { 227c478bd9Sstevel@tonic-gate do_test printf-1.$n.1 [subst { 237c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v 247c478bd9Sstevel@tonic-gate }] [format {Three integers: %d %x %o} $v $v $v] 257c478bd9Sstevel@tonic-gate do_test printf-1.$n.2 [subst { 267c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v 277c478bd9Sstevel@tonic-gate }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v] 287c478bd9Sstevel@tonic-gate do_test printf-1.$n.3 [subst { 297c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v 307c478bd9Sstevel@tonic-gate }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v] 317c478bd9Sstevel@tonic-gate do_test printf-1.$n.4 [subst { 327c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v 337c478bd9Sstevel@tonic-gate }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v] 347c478bd9Sstevel@tonic-gate do_test printf-1.$n.5 [subst { 357c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v 367c478bd9Sstevel@tonic-gate }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v] 377c478bd9Sstevel@tonic-gate do_test printf-1.$n.6 [subst { 387c478bd9Sstevel@tonic-gate sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v 397c478bd9Sstevel@tonic-gate }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v] 407c478bd9Sstevel@tonic-gate incr n 417c478bd9Sstevel@tonic-gate} 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gateif {$::tcl_platform(platform)!="windows"} { 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gateset m 1 477c478bd9Sstevel@tonic-gateforeach {a b} {1 1 5 5 10 10 10 5} { 487c478bd9Sstevel@tonic-gate set n 1 497c478bd9Sstevel@tonic-gate foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} { 507c478bd9Sstevel@tonic-gate do_test printf-2.$m.$n.1 [subst { 517c478bd9Sstevel@tonic-gate sqlite_mprintf_double {A double: %*.*f} $a $b $x 527c478bd9Sstevel@tonic-gate }] [format {A double: %*.*f} $a $b $x] 537c478bd9Sstevel@tonic-gate do_test printf-2.$m.$n.2 [subst { 547c478bd9Sstevel@tonic-gate sqlite_mprintf_double {A double: %*.*e} $a $b $x 557c478bd9Sstevel@tonic-gate }] [format {A double: %*.*e} $a $b $x] 567c478bd9Sstevel@tonic-gate do_test printf-2.$m.$n.3 [subst { 577c478bd9Sstevel@tonic-gate sqlite_mprintf_double {A double: %*.*g} $a $b $x 587c478bd9Sstevel@tonic-gate }] [format {A double: %*.*g} $a $b $x] 597c478bd9Sstevel@tonic-gate do_test printf-2.$m.$n.4 [subst { 607c478bd9Sstevel@tonic-gate sqlite_mprintf_double {A double: %d %d %g} $a $b $x 617c478bd9Sstevel@tonic-gate }] [format {A double: %d %d %g} $a $b $x] 627c478bd9Sstevel@tonic-gate do_test printf-2.$m.$n.5 [subst { 637c478bd9Sstevel@tonic-gate sqlite_mprintf_double {A double: %d %d %#g} $a $b $x 647c478bd9Sstevel@tonic-gate }] [format {A double: %d %d %#g} $a $b $x] 657c478bd9Sstevel@tonic-gate incr n 667c478bd9Sstevel@tonic-gate } 677c478bd9Sstevel@tonic-gate incr m 687c478bd9Sstevel@tonic-gate} 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate} 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gatedo_test printf-3.1 { 737c478bd9Sstevel@tonic-gate sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string} 747c478bd9Sstevel@tonic-gate} [format {A String: (%*.*s)} 10 10 {This is the string}] 757c478bd9Sstevel@tonic-gatedo_test printf-3.2 { 767c478bd9Sstevel@tonic-gate sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string} 777c478bd9Sstevel@tonic-gate} [format {A String: (%*.*s)} 10 5 {This is the string}] 787c478bd9Sstevel@tonic-gatedo_test printf-3.3 { 797c478bd9Sstevel@tonic-gate sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string} 807c478bd9Sstevel@tonic-gate} [format {A String: (%*.*s)} -10 5 {This is the string}] 817c478bd9Sstevel@tonic-gatedo_test printf-3.4 { 827c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string} 837c478bd9Sstevel@tonic-gate} [format {%d %d A String: (%s)} 1 2 {This is the string}] 847c478bd9Sstevel@tonic-gatedo_test printf-3.5 { 857c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string} 867c478bd9Sstevel@tonic-gate} [format {%d %d A String: (%30s)} 1 2 {This is the string}] 877c478bd9Sstevel@tonic-gatedo_test printf-3.6 { 887c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string} 897c478bd9Sstevel@tonic-gate} [format {%d %d A String: (%-30s)} 1 2 {This is the string}] 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gatedo_test printf-4.1 { 927c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all} 937c478bd9Sstevel@tonic-gate} {1 2 A quoted string: 'Hi Y''all'} 947c478bd9Sstevel@tonic-gatedo_test printf-4.2 { 957c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2 967c478bd9Sstevel@tonic-gate} {1 2 A NULL pointer in %q: '(NULL)'} 977c478bd9Sstevel@tonic-gatedo_test printf-4.3 { 987c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all} 997c478bd9Sstevel@tonic-gate} {1 2 A quoted string: 'Hi Y''all'} 1007c478bd9Sstevel@tonic-gatedo_test printf-4.4 { 1017c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2 1027c478bd9Sstevel@tonic-gate} {1 2 A NULL pointer in %Q: NULL} 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gatedo_test printf-5.1 { 1057c478bd9Sstevel@tonic-gate set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}] 1067c478bd9Sstevel@tonic-gate string length $x 1077c478bd9Sstevel@tonic-gate} {994} 1087c478bd9Sstevel@tonic-gatedo_test printf-5.2 { 1097c478bd9Sstevel@tonic-gate sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello} 1107c478bd9Sstevel@tonic-gate} {-9 -10 (HelloHello) %} 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gatedo_test printf-6.1 { 1137c478bd9Sstevel@tonic-gate sqlite_mprintf_z_test , one two three four five six 1147c478bd9Sstevel@tonic-gate} {,one,two,three,four,five,six} 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gatedo_test printf-7.1 { 1187c478bd9Sstevel@tonic-gate sqlite_mprintf_scaled {A double: %g} 1.0e307 1.0 1197c478bd9Sstevel@tonic-gate} {A double: 1e+307} 1207c478bd9Sstevel@tonic-gatedo_test printf-7.2 { 1217c478bd9Sstevel@tonic-gate sqlite_mprintf_scaled {A double: %g} 1.0e307 10.0 1227c478bd9Sstevel@tonic-gate} {A double: 1e+308} 1237c478bd9Sstevel@tonic-gatedo_test printf-7.3 { 1247c478bd9Sstevel@tonic-gate sqlite_mprintf_scaled {A double: %g} 1.0e307 100.0 1257c478bd9Sstevel@tonic-gate} {A double: NaN} 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gatefinish_test 128