shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 1 | # 2009 February 24 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 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. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. |
| 12 | # |
| 13 | # This file implements tests for the compile time diagnostic |
| 14 | # functions. |
| 15 | # |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
| 20 | # Test organization: |
| 21 | # |
| 22 | # ctime-1.*: Test pragma support. |
| 23 | # ctime-2.*: Test function support. |
| 24 | # |
| 25 | |
| 26 | ifcapable !pragma||!compileoption_diags { |
| 27 | finish_test |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | ##################### |
| 32 | # ctime-1.*: Test pragma support. |
| 33 | |
| 34 | do_test ctime-1.1.1 { |
| 35 | catchsql { |
| 36 | PRAGMA compile_options(); |
| 37 | } |
| 38 | } {1 {near ")": syntax error}} |
| 39 | do_test ctime-1.1.2 { |
| 40 | catchsql { |
| 41 | PRAGMA compile_options(NULL); |
| 42 | } |
| 43 | } {1 {near "NULL": syntax error}} |
| 44 | do_test ctime-1.1.3 { |
| 45 | catchsql { |
| 46 | PRAGMA compile_options *; |
| 47 | } |
| 48 | } {1 {near "*": syntax error}} |
| 49 | |
| 50 | do_test ctime-1.2.1 { |
| 51 | set ans [ catchsql { |
| 52 | PRAGMA compile_options; |
| 53 | } ] |
| 54 | list [ lindex $ans 0 ] |
| 55 | } {0} |
| 56 | # the results should be in sorted order already |
| 57 | do_test ctime-1.2.2 { |
| 58 | set ans [ catchsql { |
| 59 | PRAGMA compile_options; |
| 60 | } ] |
| 61 | list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ] |
| 62 | } {0 1} |
| 63 | |
dan | da1f49b | 2017-06-16 19:51:47 +0000 | [diff] [blame] | 64 | # Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are |
| 65 | # a couple of these configurations in releasetest.tcl). |
| 66 | # |
| 67 | ifcapable threadsafe2 { |
| 68 | foreach {tn opt res} { |
| 69 | 1 SQLITE_THREADSAFE 1 |
| 70 | 2 THREADSAFE 1 |
| 71 | 3 THREADSAFE=0 0 |
| 72 | 4 THREADSAFE=1 0 |
| 73 | 5 THREADSAFE=2 1 |
| 74 | 6 THREADSAFE= 0 |
| 75 | } { |
| 76 | do_execsql_test ctime-1.3.$tn { |
| 77 | SELECT sqlite_compileoption_used($opt) |
| 78 | } $res |
| 79 | } |
| 80 | } |
| 81 | |
dan | 814aad6 | 2017-06-17 17:29:24 +0000 | [diff] [blame] | 82 | # SQLITE_THREADSAFE should pretty much always be defined |
| 83 | # one way or the other, and it must have a value of 0 or 1. |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 84 | do_test ctime-1.4.1 { |
dan | 814aad6 | 2017-06-17 17:29:24 +0000 | [diff] [blame] | 85 | catchsql { |
| 86 | SELECT sqlite_compileoption_used('SQLITE_THREADSAFE'); |
| 87 | } |
| 88 | } {0 1} |
| 89 | do_test ctime-1.4.2 { |
| 90 | catchsql { |
| 91 | SELECT sqlite_compileoption_used('THREADSAFE'); |
| 92 | } |
| 93 | } {0 1} |
| 94 | do_test ctime-1.4.3 { |
| 95 | catchsql { |
| 96 | SELECT sqlite_compileoption_used("THREADSAFE"); |
| 97 | } |
| 98 | } {0 1} |
| 99 | |
| 100 | do_test ctime-1.5 { |
| 101 | set ans1 [ catchsql { |
| 102 | SELECT sqlite_compileoption_used('THREADSAFE=0'); |
| 103 | } ] |
| 104 | set ans2 [ catchsql { |
| 105 | SELECT sqlite_compileoption_used('THREADSAFE=1'); |
| 106 | } ] |
| 107 | set ans3 [ catchsql { |
| 108 | SELECT sqlite_compileoption_used('THREADSAFE=2'); |
| 109 | } ] |
| 110 | lsort [ list $ans1 $ans2 $ans3 ] |
| 111 | } {{0 0} {0 0} {0 1}} |
| 112 | |
| 113 | do_test ctime-1.6 { |
| 114 | execsql { |
| 115 | SELECT sqlite_compileoption_used('THREADSAFE='); |
| 116 | } |
| 117 | } {0} |
| 118 | |
| 119 | do_test ctime-1.7.1 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 120 | execsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 121 | SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 122 | } |
| 123 | } {0} |
dan | 814aad6 | 2017-06-17 17:29:24 +0000 | [diff] [blame] | 124 | do_test ctime-1.7.2 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 125 | execsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 126 | SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 127 | } |
| 128 | } {0} |
| 129 | |
| 130 | ##################### |
| 131 | # ctime-2.*: Test function support. |
| 132 | |
| 133 | do_test ctime-2.1.1 { |
| 134 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 135 | SELECT sqlite_compileoption_used(); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 136 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 137 | } {1 {wrong number of arguments to function sqlite_compileoption_used()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 138 | do_test ctime-2.1.2 { |
| 139 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 140 | SELECT sqlite_compileoption_used(NULL); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 141 | } |
| 142 | } {0 {{}}} |
| 143 | do_test ctime-2.1.3 { |
| 144 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 145 | SELECT sqlite_compileoption_used(""); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 146 | } |
| 147 | } {0 0} |
| 148 | do_test ctime-2.1.4 { |
| 149 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 150 | SELECT sqlite_compileoption_used(''); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 151 | } |
| 152 | } {0 0} |
| 153 | do_test ctime-2.1.5 { |
| 154 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 155 | SELECT sqlite_compileoption_used(foo); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 156 | } |
| 157 | } {1 {no such column: foo}} |
| 158 | do_test ctime-2.1.6 { |
| 159 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 160 | SELECT sqlite_compileoption_used('THREADSAFE', 0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 161 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 162 | } {1 {wrong number of arguments to function sqlite_compileoption_used()}} |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 163 | do_test ctime-2.1.7 { |
| 164 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 165 | SELECT sqlite_compileoption_used(0); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 166 | } |
| 167 | } {0 0} |
| 168 | do_test ctime-2.1.8 { |
| 169 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 170 | SELECT sqlite_compileoption_used('0'); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 171 | } |
| 172 | } {0 0} |
| 173 | do_test ctime-2.1.9 { |
| 174 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 175 | SELECT sqlite_compileoption_used(1.0); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 176 | } |
| 177 | } {0 0} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 178 | |
| 179 | do_test ctime-2.2.1 { |
| 180 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 181 | SELECT sqlite_compileoption_get(); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 182 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 183 | } {1 {wrong number of arguments to function sqlite_compileoption_get()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 184 | do_test ctime-2.2.2 { |
| 185 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 186 | SELECT sqlite_compileoption_get(0, 0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 187 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 188 | } {1 {wrong number of arguments to function sqlite_compileoption_get()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 189 | |
| 190 | # This assumes there is at least 1 compile time option |
| 191 | # (see SQLITE_THREADSAFE above). |
| 192 | do_test ctime-2.3 { |
| 193 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 194 | SELECT sqlite_compileoption_used(sqlite_compileoption_get(0)); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 195 | } |
| 196 | } {0 1} |
| 197 | |
| 198 | # This assumes there is at least 1 compile time option |
| 199 | # (see SQLITE_THREADSAFE above). |
| 200 | do_test ctime-2.4 { |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 201 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 202 | SELECT sqlite_compileoption_get(0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 203 | } ] |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 204 | list [lindex $ans 0] |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 205 | } {0} |
| 206 | |
| 207 | # Get the list of defines using the pragma, |
| 208 | # then try querying each one with the functions. |
| 209 | set ans [ catchsql { |
| 210 | PRAGMA compile_options; |
| 211 | } ] |
| 212 | set opts [ lindex $ans 1 ] |
| 213 | set tc 1 |
| 214 | foreach opt $opts { |
| 215 | do_test ctime-2.5.$tc { |
| 216 | set N [ expr {$tc-1} ] |
drh | f5fe003 | 2016-06-24 06:23:13 +0000 | [diff] [blame] | 217 | set ans1 [catch {db one { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 218 | SELECT sqlite_compileoption_get($N); |
drh | f5fe003 | 2016-06-24 06:23:13 +0000 | [diff] [blame] | 219 | }} msg] |
| 220 | lappend ans1 $msg |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 221 | set ans2 [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 222 | SELECT sqlite_compileoption_used($opt); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 223 | } ] |
| 224 | list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \ |
| 225 | [ expr { $ans2 } ] |
| 226 | } {0 1 {0 1}} |
| 227 | incr tc 1 |
| 228 | } |
| 229 | # test 1 past array bounds |
| 230 | do_test ctime-2.5.$tc { |
| 231 | set N [ expr {$tc-1} ] |
| 232 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 233 | SELECT sqlite_compileoption_get($N); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 234 | } ] |
| 235 | } {0 {{}}} |
| 236 | incr tc 1 |
| 237 | # test 1 before array bounds (N=-1) |
| 238 | do_test ctime-2.5.$tc { |
| 239 | set N -1 |
| 240 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 241 | SELECT sqlite_compileoption_get($N); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 242 | } ] |
| 243 | } {0 {{}}} |
| 244 | |
dan | ceb97c1 | 2016-10-21 10:09:22 +0000 | [diff] [blame] | 245 | #-------------------------------------------------------------------------- |
| 246 | # Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of |
| 247 | # "PRAGMA compile_options". |
| 248 | # |
| 249 | ifcapable direct_read { |
| 250 | set res 1 |
| 251 | } else { |
| 252 | set res 0 |
| 253 | } |
| 254 | do_test ctime-3.0.1 { |
| 255 | expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0 |
| 256 | } $res |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 257 | |
| 258 | finish_test |