drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this file is testing the sqlite_*_printf() interface. |
| 13 | # |
danielk1977 | 369ff42 | 2007-09-03 07:31:09 +0000 | [diff] [blame^] | 14 | # $Id: printf.test,v 1.27 2007/09/03 07:31:10 danielk1977 Exp $ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | set n 1 |
| 20 | foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} { |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 21 | set v32 [expr {$v&0xffffffff}] |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 22 | do_test printf-1.$n.1 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 23 | sqlite3_mprintf_int {Three integers: %d %x %o} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 24 | }] [format {Three integers: %d %x %o} $v $v32 $v32] |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 25 | do_test printf-1.$n.2 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 26 | sqlite3_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 27 | }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v32 $v32] |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 28 | do_test printf-1.$n.3 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 29 | sqlite3_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 30 | }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v32 $v32] |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 31 | do_test printf-1.$n.4 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 32 | sqlite3_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 33 | }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v32 $v32] |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 34 | do_test printf-1.$n.5 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 35 | sqlite3_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 36 | }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v32 $v32] |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 37 | do_test printf-1.$n.6 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 38 | sqlite3_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 39 | }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v32 $v32] |
drh | 779c6a0 | 2004-06-29 13:04:32 +0000 | [diff] [blame] | 40 | do_test printf-1.$n.7 [subst { |
| 41 | sqlite3_mprintf_int {Three integers: (%#6d) (%#6x) (%#6o)} $v $v $v |
drh | 6aff507 | 2004-09-09 00:35:29 +0000 | [diff] [blame] | 42 | }] [format {Three integers: (%#6d) (%#6x) (%#6o)} $v $v32 $v32] |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 43 | incr n |
| 44 | } |
| 45 | |
drh | 254cba2 | 2001-09-20 01:44:42 +0000 | [diff] [blame] | 46 | |
| 47 | if {$::tcl_platform(platform)!="windows"} { |
| 48 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 49 | set m 1 |
| 50 | foreach {a b} {1 1 5 5 10 10 10 5} { |
| 51 | set n 1 |
| 52 | foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} { |
| 53 | do_test printf-2.$m.$n.1 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 54 | sqlite3_mprintf_double {A double: %*.*f} $a $b $x |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 55 | }] [format {A double: %*.*f} $a $b $x] |
| 56 | do_test printf-2.$m.$n.2 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 57 | sqlite3_mprintf_double {A double: %*.*e} $a $b $x |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 58 | }] [format {A double: %*.*e} $a $b $x] |
| 59 | do_test printf-2.$m.$n.3 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 60 | sqlite3_mprintf_double {A double: %*.*g} $a $b $x |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 61 | }] [format {A double: %*.*g} $a $b $x] |
| 62 | do_test printf-2.$m.$n.4 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 63 | sqlite3_mprintf_double {A double: %d %d %g} $a $b $x |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 64 | }] [format {A double: %d %d %g} $a $b $x] |
| 65 | do_test printf-2.$m.$n.5 [subst { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 66 | sqlite3_mprintf_double {A double: %d %d %#g} $a $b $x |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 67 | }] [format {A double: %d %d %#g} $a $b $x] |
drh | 779c6a0 | 2004-06-29 13:04:32 +0000 | [diff] [blame] | 68 | do_test printf-2.$m.$n.6 [subst { |
| 69 | sqlite3_mprintf_double {A double: %d %d %010g} $a $b $x |
| 70 | }] [format {A double: %d %d %010g} $a $b $x] |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 71 | incr n |
| 72 | } |
| 73 | incr m |
| 74 | } |
| 75 | |
drh | 592ac8c | 2005-08-13 03:07:47 +0000 | [diff] [blame] | 76 | } ;# endif not windows |
drh | 254cba2 | 2001-09-20 01:44:42 +0000 | [diff] [blame] | 77 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 78 | do_test printf-3.1 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 79 | sqlite3_mprintf_str {A String: (%*.*s)} 10 10 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 80 | } [format {A String: (%*.*s)} 10 10 {This is the string}] |
| 81 | do_test printf-3.2 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 82 | sqlite3_mprintf_str {A String: (%*.*s)} 10 5 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 83 | } [format {A String: (%*.*s)} 10 5 {This is the string}] |
| 84 | do_test printf-3.3 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 85 | sqlite3_mprintf_str {A String: (%*.*s)} -10 5 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 86 | } [format {A String: (%*.*s)} -10 5 {This is the string}] |
| 87 | do_test printf-3.4 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 88 | sqlite3_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 89 | } [format {%d %d A String: (%s)} 1 2 {This is the string}] |
| 90 | do_test printf-3.5 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 91 | sqlite3_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 92 | } [format {%d %d A String: (%30s)} 1 2 {This is the string}] |
| 93 | do_test printf-3.6 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 94 | sqlite3_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 95 | } [format {%d %d A String: (%-30s)} 1 2 {This is the string}] |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 96 | do_test snprintf-3.11 { |
| 97 | sqlite3_snprintf_str 2 {x%d %d %s} 10 10 {This is the string} |
| 98 | } {x} |
| 99 | do_test snprintf-3.12 { |
| 100 | sqlite3_snprintf_str 3 {x%d %d %s} 10 10 {This is the string} |
| 101 | } {x1} |
| 102 | do_test snprintf-3.13 { |
| 103 | sqlite3_snprintf_str 4 {x%d %d %s} 10 10 {This is the string} |
| 104 | } {x10} |
| 105 | do_test snprintf-3.14 { |
| 106 | sqlite3_snprintf_str 5 {x%d %d %s} 10 10 {This is the string} |
| 107 | } {x10 } |
| 108 | do_test snprintf-3.15 { |
| 109 | sqlite3_snprintf_str 6 {x%d %d %s} 10 10 {This is the string} |
| 110 | } {x10 1} |
| 111 | do_test snprintf-3.16 { |
| 112 | sqlite3_snprintf_str 7 {x%d %d %s} 10 10 {This is the string} |
| 113 | } {x10 10} |
| 114 | do_test snprintf-3.17 { |
| 115 | sqlite3_snprintf_str 8 {x%d %d %s} 10 10 {This is the string} |
| 116 | } {x10 10 } |
| 117 | do_test snprintf-3.18 { |
| 118 | sqlite3_snprintf_str 9 {x%d %d %s} 10 10 {This is the string} |
| 119 | } {x10 10 T} |
| 120 | do_test snprintf-3.19 { |
| 121 | sqlite3_snprintf_str 100 {x%d %d %s} 10 10 {This is the string} |
| 122 | } {x10 10 This is the string} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 123 | |
| 124 | do_test printf-4.1 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 125 | sqlite3_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 126 | } {1 2 A quoted string: 'Hi Y''all'} |
chw | b22f1b5 | 2002-06-16 04:56:36 +0000 | [diff] [blame] | 127 | do_test printf-4.2 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 128 | sqlite3_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2 |
chw | b22f1b5 | 2002-06-16 04:56:36 +0000 | [diff] [blame] | 129 | } {1 2 A NULL pointer in %q: '(NULL)'} |
| 130 | do_test printf-4.3 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 131 | sqlite3_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all} |
chw | b22f1b5 | 2002-06-16 04:56:36 +0000 | [diff] [blame] | 132 | } {1 2 A quoted string: 'Hi Y''all'} |
| 133 | do_test printf-4.4 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 134 | sqlite3_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2 |
chw | b22f1b5 | 2002-06-16 04:56:36 +0000 | [diff] [blame] | 135 | } {1 2 A NULL pointer in %Q: NULL} |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 136 | |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 137 | do_test printf-5.1 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 138 | set x [sqlite3_mprintf_str {%d %d %100000s} 0 0 {Hello}] |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 139 | string length $x |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 140 | } {344} |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 141 | do_test printf-5.2 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 142 | sqlite3_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello} |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 143 | } {-9 -10 (HelloHello) %} |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 144 | |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 145 | do_test printf-6.1 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 146 | sqlite3_mprintf_z_test , one two three four five six |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 147 | } {,one,two,three,four,five,six} |
| 148 | |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 149 | |
| 150 | do_test printf-7.1 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 151 | sqlite3_mprintf_scaled {A double: %g} 1.0e307 1.0 |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 152 | } {A double: 1e+307} |
| 153 | do_test printf-7.2 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 154 | sqlite3_mprintf_scaled {A double: %g} 1.0e307 10.0 |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 155 | } {A double: 1e+308} |
| 156 | do_test printf-7.3 { |
danielk1977 | 2dd5936 | 2004-06-14 23:46:47 +0000 | [diff] [blame] | 157 | sqlite3_mprintf_scaled {A double: %g} 1.0e307 100.0 |
drh | 53c1402 | 2007-05-10 17:23:11 +0000 | [diff] [blame] | 158 | } {A double: Inf} |
| 159 | do_test printf-7.4 { |
| 160 | sqlite3_mprintf_scaled {A double: %g} -1.0e307 100.0 |
| 161 | } {A double: -Inf} |
| 162 | do_test printf-7.5 { |
| 163 | sqlite3_mprintf_scaled {A double: %+g} 1.0e307 100.0 |
| 164 | } {A double: +Inf} |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 165 | |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 166 | do_test printf-8.1 { |
| 167 | sqlite3_mprintf_int {%u %u %u} 0x7fffffff 0x80000000 0xffffffff |
| 168 | } {2147483647 2147483648 4294967295} |
| 169 | do_test printf-8.2 { |
| 170 | sqlite3_mprintf_int {%lu %lu %lu} 0x7fffffff 0x80000000 0xffffffff |
| 171 | } {2147483647 2147483648 4294967295} |
| 172 | do_test printf-8.3 { |
| 173 | sqlite3_mprintf_int64 {%llu %llu %llu} 2147483647 2147483648 4294967296 |
| 174 | } {2147483647 2147483648 4294967296} |
| 175 | do_test printf-8.4 { |
| 176 | sqlite3_mprintf_int64 {%lld %lld %lld} 2147483647 2147483648 4294967296 |
| 177 | } {2147483647 2147483648 4294967296} |
| 178 | do_test printf-8.5 { |
| 179 | sqlite3_mprintf_int64 {%llx %llx %llx} 2147483647 2147483648 4294967296 |
| 180 | } {7fffffff 80000000 100000000} |
| 181 | do_test printf-8.6 { |
| 182 | sqlite3_mprintf_int64 {%llx %llo %lld} -1 -1 -1 |
| 183 | } {ffffffffffffffff 1777777777777777777777 -1} |
danielk1977 | b8cdbec | 2007-09-01 10:01:12 +0000 | [diff] [blame] | 184 | do_test printf-8.7 { |
| 185 | sqlite3_mprintf_int64 {%llx %llx %llx} +2147483647 +2147483648 +4294967296 |
| 186 | } {7fffffff 80000000 100000000} |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 187 | |
drh | 779c6a0 | 2004-06-29 13:04:32 +0000 | [diff] [blame] | 188 | do_test printf-9.1 { |
| 189 | sqlite3_mprintf_int {%*.*c} 4 4 65 |
| 190 | } {AAAA} |
| 191 | do_test printf-9.2 { |
| 192 | sqlite3_mprintf_int {%*.*c} -4 1 66 |
| 193 | } {B } |
| 194 | do_test printf-9.3 { |
| 195 | sqlite3_mprintf_int {%*.*c} 4 1 67 |
| 196 | } { C} |
| 197 | do_test printf-9.4 { |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 198 | sqlite3_mprintf_int {%d %d %c} 4 1 67 |
| 199 | } {4 1 C} |
| 200 | set ten { } |
| 201 | set fifty $ten$ten$ten$ten$ten |
| 202 | do_test printf-9.5 { |
| 203 | sqlite3_mprintf_int {%d %*c} 1 -201 67 |
| 204 | } "1 C$fifty$fifty$fifty$fifty" |
| 205 | do_test printf-9.6 { |
drh | 43617e9 | 2006-03-06 20:55:46 +0000 | [diff] [blame] | 206 | sqlite3_mprintf_int {hi%12345.12346yhello} 0 0 0 |
| 207 | } {hi} |
drh | 779c6a0 | 2004-06-29 13:04:32 +0000 | [diff] [blame] | 208 | |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 209 | # Ticket #812 |
| 210 | # |
| 211 | do_test printf-10.1 { |
| 212 | sqlite3_mprintf_stronly %s {} |
| 213 | } {} |
| 214 | |
drh | 9796ef5 | 2004-07-27 13:38:47 +0000 | [diff] [blame] | 215 | # Ticket #831 |
| 216 | # |
| 217 | do_test printf-10.2 { |
| 218 | sqlite3_mprintf_stronly %q {} |
| 219 | } {} |
| 220 | |
drh | 592ac8c | 2005-08-13 03:07:47 +0000 | [diff] [blame] | 221 | # Ticket #1340: Test for loss of precision on large positive exponents |
| 222 | # |
| 223 | do_test printf-10.3 { |
| 224 | sqlite3_mprintf_double {%d %d %f} 1 1 1e300 |
| 225 | } {1 1 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000} |
| 226 | |
drh | 557cc60 | 2005-08-13 12:59:14 +0000 | [diff] [blame] | 227 | # The non-standard '!' flag on a 'g' conversion forces a decimal point |
| 228 | # and at least one digit on either side of the decimal point. |
| 229 | # |
| 230 | do_test printf-11.1 { |
| 231 | sqlite3_mprintf_double {%d %d %!g} 1 1 1 |
| 232 | } {1 1 1.0} |
| 233 | do_test printf-11.2 { |
| 234 | sqlite3_mprintf_double {%d %d %!g} 1 1 123 |
| 235 | } {1 1 123.0} |
| 236 | do_test printf-11.3 { |
| 237 | sqlite3_mprintf_double {%d %d %!g} 1 1 12.3 |
| 238 | } {1 1 12.3} |
| 239 | do_test printf-11.4 { |
| 240 | sqlite3_mprintf_double {%d %d %!g} 1 1 0.123 |
| 241 | } {1 1 0.123} |
| 242 | do_test printf-11.5 { |
| 243 | sqlite3_mprintf_double {%d %d %!.15g} 1 1 1 |
| 244 | } {1 1 1.0} |
| 245 | do_test printf-11.6 { |
| 246 | sqlite3_mprintf_double {%d %d %!.15g} 1 1 1e10 |
| 247 | } {1 1 10000000000.0} |
| 248 | do_test printf-11.7 { |
| 249 | sqlite3_mprintf_double {%d %d %!.15g} 1 1 1e300 |
| 250 | } {1 1 1.0e+300} |
| 251 | |
drh | 5eba8c0 | 2005-08-19 02:26:27 +0000 | [diff] [blame] | 252 | # Additional tests for coverage |
| 253 | # |
| 254 | do_test printf-12.1 { |
| 255 | sqlite3_mprintf_double {%d %d %.2000g} 1 1 1.0 |
| 256 | } {1 1 1} |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 257 | |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 258 | # Floating point boundary cases |
| 259 | # |
| 260 | do_test printf-13.1 { |
| 261 | sqlite3_mprintf_hexdouble %.20f 4024000000000000 |
| 262 | } {10.00000000000000000000} |
| 263 | do_test printf-13.2 { |
| 264 | sqlite3_mprintf_hexdouble %.20f 4197d78400000000 |
| 265 | } {100000000.00000000000000000000} |
| 266 | do_test printf-13.3 { |
| 267 | sqlite3_mprintf_hexdouble %.20f 4693b8b5b5056e17 |
| 268 | } {100000000000000000000000000000000.00000000000000000000} |
drh | 53c1402 | 2007-05-10 17:23:11 +0000 | [diff] [blame] | 269 | do_test printf-13.4 { |
| 270 | sqlite3_mprintf_hexdouble %.20f 7ff0000000000000 |
| 271 | } {Inf} |
| 272 | do_test printf-13.5 { |
| 273 | sqlite3_mprintf_hexdouble %.20f fff0000000000000 |
| 274 | } {-Inf} |
| 275 | do_test printf-13.6 { |
| 276 | sqlite3_mprintf_hexdouble %.20f fff8000000000000 |
| 277 | } {NaN} |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 278 | |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 279 | do_test printf-14.1 { |
| 280 | sqlite3_mprintf_str {abc-%y-123} 0 0 {not used} |
| 281 | } {abc-} |
| 282 | do_test printf-14.2 { |
| 283 | sqlite3_mprintf_n_test {xyzzy} |
| 284 | } 5 |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 285 | do_test printf-14.3 { |
| 286 | sqlite3_mprintf_str {abc-%T-123} 0 0 {not used} |
| 287 | } {abc-} |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 288 | |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 289 | do_test printf-15.1 { |
| 290 | sqlite3_snprintf_int 5 {12345} 0 |
| 291 | } {1234} |
| 292 | do_test printf-15.2 { |
| 293 | sqlite3_snprintf_int 5 {} 0 |
| 294 | } {} |
| 295 | do_test printf-15.3 { |
| 296 | sqlite3_snprintf_int 0 {} 0 |
| 297 | } {abcdefghijklmnopqrstuvwxyz} |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 298 | |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 299 | # Now test malloc() failure within a sqlite3_mprintf(): |
| 300 | # |
danielk1977 | 369ff42 | 2007-09-03 07:31:09 +0000 | [diff] [blame^] | 301 | ifcapable memdebug { |
| 302 | foreach var {a b c d} { |
| 303 | set $var [string repeat $var 400] |
| 304 | } |
| 305 | set str1 "[string repeat A 360]%d%d%s" |
| 306 | set str2 [string repeat B 5000] |
| 307 | set zSuccess "[string repeat A 360]11[string repeat B 5000]" |
| 308 | foreach ::iRepeat {0 1} { |
| 309 | set nTestNum 1 |
| 310 | while {1} { |
| 311 | sqlite3_memdebug_fail $nTestNum -repeat $::iRepeat |
| 312 | set z [sqlite3_mprintf_str $str1 1 1 $str2] |
| 313 | set nFail [sqlite3_memdebug_fail -1 -benign nBenign] |
| 314 | do_test printf-malloc-$::iRepeat.$nTestNum { |
| 315 | expr {($nFail>0 && $z eq "") || ($nFail==$nBenign && $z eq $zSuccess)} |
| 316 | } {1} |
| 317 | if {$nFail == 0} break |
| 318 | incr nTestNum |
| 319 | } |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 323 | finish_test |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 324 | |