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 | |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 64 | # SQLITE_THREADSAFE should pretty much always be defined |
| 65 | # one way or the other, and it must have a value of 0 or 1. |
| 66 | do_test ctime-1.4.1 { |
| 67 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 68 | SELECT sqlite_compileoption_used('SQLITE_THREADSAFE'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 69 | } |
| 70 | } {0 1} |
| 71 | do_test ctime-1.4.2 { |
| 72 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 73 | SELECT sqlite_compileoption_used('THREADSAFE'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 74 | } |
| 75 | } {0 1} |
| 76 | do_test ctime-1.4.3 { |
| 77 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 78 | SELECT sqlite_compileoption_used("THREADSAFE"); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 79 | } |
| 80 | } {0 1} |
| 81 | |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 82 | do_test ctime-1.5 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 83 | set ans1 [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 84 | SELECT sqlite_compileoption_used('THREADSAFE=0'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 85 | } ] |
| 86 | set ans2 [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 87 | SELECT sqlite_compileoption_used('THREADSAFE=1'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 88 | } ] |
dan | cfa800c | 2010-06-24 17:37:57 +0000 | [diff] [blame] | 89 | set ans3 [ catchsql { |
| 90 | SELECT sqlite_compileoption_used('THREADSAFE=2'); |
| 91 | } ] |
| 92 | lsort [ list $ans1 $ans2 $ans3 ] |
| 93 | } {{0 0} {0 0} {0 1}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 94 | |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 95 | do_test ctime-1.6 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 96 | execsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 97 | SELECT sqlite_compileoption_used('THREADSAFE='); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 98 | } |
| 99 | } {0} |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 100 | |
| 101 | do_test ctime-1.7.1 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 102 | execsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 103 | SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 104 | } |
| 105 | } {0} |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 106 | do_test ctime-1.7.2 { |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 107 | execsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 108 | SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS'); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 109 | } |
| 110 | } {0} |
| 111 | |
| 112 | ##################### |
| 113 | # ctime-2.*: Test function support. |
| 114 | |
| 115 | do_test ctime-2.1.1 { |
| 116 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 117 | SELECT sqlite_compileoption_used(); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 118 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 119 | } {1 {wrong number of arguments to function sqlite_compileoption_used()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 120 | do_test ctime-2.1.2 { |
| 121 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 122 | SELECT sqlite_compileoption_used(NULL); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 123 | } |
| 124 | } {0 {{}}} |
| 125 | do_test ctime-2.1.3 { |
| 126 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 127 | SELECT sqlite_compileoption_used(""); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 128 | } |
| 129 | } {0 0} |
| 130 | do_test ctime-2.1.4 { |
| 131 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 132 | SELECT sqlite_compileoption_used(''); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 133 | } |
| 134 | } {0 0} |
| 135 | do_test ctime-2.1.5 { |
| 136 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 137 | SELECT sqlite_compileoption_used(foo); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 138 | } |
| 139 | } {1 {no such column: foo}} |
| 140 | do_test ctime-2.1.6 { |
| 141 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 142 | SELECT sqlite_compileoption_used('THREADSAFE', 0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 143 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 144 | } {1 {wrong number of arguments to function sqlite_compileoption_used()}} |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 145 | do_test ctime-2.1.7 { |
| 146 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 147 | SELECT sqlite_compileoption_used(0); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 148 | } |
| 149 | } {0 0} |
| 150 | do_test ctime-2.1.8 { |
| 151 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 152 | SELECT sqlite_compileoption_used('0'); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 153 | } |
| 154 | } {0 0} |
| 155 | do_test ctime-2.1.9 { |
| 156 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 157 | SELECT sqlite_compileoption_used(1.0); |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 158 | } |
| 159 | } {0 0} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 160 | |
| 161 | do_test ctime-2.2.1 { |
| 162 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 163 | SELECT sqlite_compileoption_get(); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 164 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 165 | } {1 {wrong number of arguments to function sqlite_compileoption_get()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 166 | do_test ctime-2.2.2 { |
| 167 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 168 | SELECT sqlite_compileoption_get(0, 0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 169 | } |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 170 | } {1 {wrong number of arguments to function sqlite_compileoption_get()}} |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 171 | |
| 172 | # This assumes there is at least 1 compile time option |
| 173 | # (see SQLITE_THREADSAFE above). |
| 174 | do_test ctime-2.3 { |
| 175 | catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 176 | SELECT sqlite_compileoption_used(sqlite_compileoption_get(0)); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 177 | } |
| 178 | } {0 1} |
| 179 | |
| 180 | # This assumes there is at least 1 compile time option |
| 181 | # (see SQLITE_THREADSAFE above). |
| 182 | do_test ctime-2.4 { |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 183 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 184 | SELECT sqlite_compileoption_get(0); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 185 | } ] |
shaneh | 88ba618 | 2010-02-25 18:07:59 +0000 | [diff] [blame] | 186 | list [lindex $ans 0] |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 187 | } {0} |
| 188 | |
| 189 | # Get the list of defines using the pragma, |
| 190 | # then try querying each one with the functions. |
| 191 | set ans [ catchsql { |
| 192 | PRAGMA compile_options; |
| 193 | } ] |
| 194 | set opts [ lindex $ans 1 ] |
| 195 | set tc 1 |
| 196 | foreach opt $opts { |
| 197 | do_test ctime-2.5.$tc { |
| 198 | set N [ expr {$tc-1} ] |
| 199 | set ans1 [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 200 | SELECT sqlite_compileoption_get($N); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 201 | } ] |
| 202 | set ans2 [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 203 | SELECT sqlite_compileoption_used($opt); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 204 | } ] |
| 205 | list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \ |
| 206 | [ expr { $ans2 } ] |
| 207 | } {0 1 {0 1}} |
| 208 | incr tc 1 |
| 209 | } |
| 210 | # test 1 past array bounds |
| 211 | do_test ctime-2.5.$tc { |
| 212 | set N [ expr {$tc-1} ] |
| 213 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 214 | SELECT sqlite_compileoption_get($N); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 215 | } ] |
| 216 | } {0 {{}}} |
| 217 | incr tc 1 |
| 218 | # test 1 before array bounds (N=-1) |
| 219 | do_test ctime-2.5.$tc { |
| 220 | set N -1 |
| 221 | set ans [ catchsql { |
drh | 8bb76d3 | 2010-02-26 16:37:47 +0000 | [diff] [blame] | 222 | SELECT sqlite_compileoption_get($N); |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 223 | } ] |
| 224 | } {0 {{}}} |
| 225 | |
shaneh | 915c8bd | 2010-02-24 19:36:10 +0000 | [diff] [blame] | 226 | |
| 227 | finish_test |