1915c8bdbSshaneh# 2009 February 24 2915c8bdbSshaneh# 3915c8bdbSshaneh# The author disclaims copyright to this source code. In place of 4915c8bdbSshaneh# a legal notice, here is a blessing: 5915c8bdbSshaneh# 6915c8bdbSshaneh# May you do good and not evil. 7915c8bdbSshaneh# May you find forgiveness for yourself and forgive others. 8915c8bdbSshaneh# May you share freely, never taking more than you give. 9915c8bdbSshaneh# 10915c8bdbSshaneh#*********************************************************************** 11915c8bdbSshaneh# This file implements regression tests for SQLite library. 12915c8bdbSshaneh# 13915c8bdbSshaneh# This file implements tests for the compile time diagnostic 14915c8bdbSshaneh# functions. 15915c8bdbSshaneh# 16915c8bdbSshaneh 17915c8bdbSshanehset testdir [file dirname $argv0] 18915c8bdbSshanehsource $testdir/tester.tcl 19915c8bdbSshaneh 20915c8bdbSshaneh# Test organization: 21915c8bdbSshaneh# 22915c8bdbSshaneh# ctime-1.*: Test pragma support. 23915c8bdbSshaneh# ctime-2.*: Test function support. 24915c8bdbSshaneh# 25915c8bdbSshaneh 26915c8bdbSshanehifcapable !pragma||!compileoption_diags { 27915c8bdbSshaneh finish_test 28915c8bdbSshaneh return 29915c8bdbSshaneh} 30915c8bdbSshaneh 31915c8bdbSshaneh##################### 32915c8bdbSshaneh# ctime-1.*: Test pragma support. 33915c8bdbSshaneh 34915c8bdbSshanehdo_test ctime-1.1.1 { 35915c8bdbSshaneh catchsql { 36915c8bdbSshaneh PRAGMA compile_options(); 37915c8bdbSshaneh } 38915c8bdbSshaneh} {1 {near ")": syntax error}} 39915c8bdbSshanehdo_test ctime-1.1.2 { 40915c8bdbSshaneh catchsql { 41915c8bdbSshaneh PRAGMA compile_options(NULL); 42915c8bdbSshaneh } 43915c8bdbSshaneh} {1 {near "NULL": syntax error}} 44915c8bdbSshanehdo_test ctime-1.1.3 { 45915c8bdbSshaneh catchsql { 46915c8bdbSshaneh PRAGMA compile_options *; 47915c8bdbSshaneh } 48915c8bdbSshaneh} {1 {near "*": syntax error}} 49915c8bdbSshaneh 50915c8bdbSshanehdo_test ctime-1.2.1 { 51915c8bdbSshaneh set ans [ catchsql { 52915c8bdbSshaneh PRAGMA compile_options; 53915c8bdbSshaneh } ] 54915c8bdbSshaneh list [ lindex $ans 0 ] 55915c8bdbSshaneh} {0} 56915c8bdbSshaneh# the results should be in sorted order already 57915c8bdbSshanehdo_test ctime-1.2.2 { 58915c8bdbSshaneh set ans [ catchsql { 59915c8bdbSshaneh PRAGMA compile_options; 60915c8bdbSshaneh } ] 61915c8bdbSshaneh list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ] 62915c8bdbSshaneh} {0 1} 63915c8bdbSshaneh 64da1f49b8Sdan# Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are 65da1f49b8Sdan# a couple of these configurations in releasetest.tcl). 66da1f49b8Sdan# 67da1f49b8Sdanifcapable threadsafe2 { 68da1f49b8Sdan foreach {tn opt res} { 69da1f49b8Sdan 1 SQLITE_THREADSAFE 1 70da1f49b8Sdan 2 THREADSAFE 1 71da1f49b8Sdan 3 THREADSAFE=0 0 72da1f49b8Sdan 4 THREADSAFE=1 0 73da1f49b8Sdan 5 THREADSAFE=2 1 74da1f49b8Sdan 6 THREADSAFE= 0 75da1f49b8Sdan } { 76da1f49b8Sdan do_execsql_test ctime-1.3.$tn { 77da1f49b8Sdan SELECT sqlite_compileoption_used($opt) 78da1f49b8Sdan } $res 79da1f49b8Sdan } 80da1f49b8Sdan} 81da1f49b8Sdan 82814aad61Sdan# SQLITE_THREADSAFE should pretty much always be defined 83814aad61Sdan# one way or the other, and it must have a value of 0 or 1. 84*7d44b22dSdrhsqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 85915c8bdbSshanehdo_test ctime-1.4.1 { 86814aad61Sdan catchsql { 87814aad61Sdan SELECT sqlite_compileoption_used('SQLITE_THREADSAFE'); 88814aad61Sdan } 89814aad61Sdan} {0 1} 90814aad61Sdando_test ctime-1.4.2 { 91814aad61Sdan catchsql { 92814aad61Sdan SELECT sqlite_compileoption_used('THREADSAFE'); 93814aad61Sdan } 94814aad61Sdan} {0 1} 95814aad61Sdando_test ctime-1.4.3 { 96814aad61Sdan catchsql { 97814aad61Sdan SELECT sqlite_compileoption_used("THREADSAFE"); 98814aad61Sdan } 99814aad61Sdan} {0 1} 100814aad61Sdan 101814aad61Sdando_test ctime-1.5 { 102814aad61Sdan set ans1 [ catchsql { 103814aad61Sdan SELECT sqlite_compileoption_used('THREADSAFE=0'); 104814aad61Sdan } ] 105814aad61Sdan set ans2 [ catchsql { 106814aad61Sdan SELECT sqlite_compileoption_used('THREADSAFE=1'); 107814aad61Sdan } ] 108814aad61Sdan set ans3 [ catchsql { 109814aad61Sdan SELECT sqlite_compileoption_used('THREADSAFE=2'); 110814aad61Sdan } ] 111814aad61Sdan lsort [ list $ans1 $ans2 $ans3 ] 112814aad61Sdan} {{0 0} {0 0} {0 1}} 113814aad61Sdan 114814aad61Sdando_test ctime-1.6 { 115814aad61Sdan execsql { 116814aad61Sdan SELECT sqlite_compileoption_used('THREADSAFE='); 117814aad61Sdan } 118814aad61Sdan} {0} 119814aad61Sdan 120814aad61Sdando_test ctime-1.7.1 { 121915c8bdbSshaneh execsql { 1228bb76d39Sdrh SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS'); 123915c8bdbSshaneh } 124915c8bdbSshaneh} {0} 125814aad61Sdando_test ctime-1.7.2 { 126915c8bdbSshaneh execsql { 1278bb76d39Sdrh SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS'); 128915c8bdbSshaneh } 129915c8bdbSshaneh} {0} 130915c8bdbSshaneh 131915c8bdbSshaneh##################### 132915c8bdbSshaneh# ctime-2.*: Test function support. 133915c8bdbSshaneh 134915c8bdbSshanehdo_test ctime-2.1.1 { 135915c8bdbSshaneh catchsql { 1368bb76d39Sdrh SELECT sqlite_compileoption_used(); 137915c8bdbSshaneh } 1388bb76d39Sdrh} {1 {wrong number of arguments to function sqlite_compileoption_used()}} 139915c8bdbSshanehdo_test ctime-2.1.2 { 140915c8bdbSshaneh catchsql { 1418bb76d39Sdrh SELECT sqlite_compileoption_used(NULL); 142915c8bdbSshaneh } 143915c8bdbSshaneh} {0 {{}}} 144915c8bdbSshanehdo_test ctime-2.1.3 { 145915c8bdbSshaneh catchsql { 1468bb76d39Sdrh SELECT sqlite_compileoption_used(""); 147915c8bdbSshaneh } 148915c8bdbSshaneh} {0 0} 149915c8bdbSshanehdo_test ctime-2.1.4 { 150915c8bdbSshaneh catchsql { 1518bb76d39Sdrh SELECT sqlite_compileoption_used(''); 152915c8bdbSshaneh } 153915c8bdbSshaneh} {0 0} 154915c8bdbSshanehdo_test ctime-2.1.5 { 155915c8bdbSshaneh catchsql { 1568bb76d39Sdrh SELECT sqlite_compileoption_used(foo); 157915c8bdbSshaneh } 158915c8bdbSshaneh} {1 {no such column: foo}} 159915c8bdbSshanehdo_test ctime-2.1.6 { 160915c8bdbSshaneh catchsql { 1618bb76d39Sdrh SELECT sqlite_compileoption_used('THREADSAFE', 0); 162915c8bdbSshaneh } 1638bb76d39Sdrh} {1 {wrong number of arguments to function sqlite_compileoption_used()}} 16488ba618eSshanehdo_test ctime-2.1.7 { 16588ba618eSshaneh catchsql { 1668bb76d39Sdrh SELECT sqlite_compileoption_used(0); 16788ba618eSshaneh } 16888ba618eSshaneh} {0 0} 16988ba618eSshanehdo_test ctime-2.1.8 { 17088ba618eSshaneh catchsql { 1718bb76d39Sdrh SELECT sqlite_compileoption_used('0'); 17288ba618eSshaneh } 17388ba618eSshaneh} {0 0} 17488ba618eSshanehdo_test ctime-2.1.9 { 17588ba618eSshaneh catchsql { 1768bb76d39Sdrh SELECT sqlite_compileoption_used(1.0); 17788ba618eSshaneh } 17888ba618eSshaneh} {0 0} 179915c8bdbSshaneh 180915c8bdbSshanehdo_test ctime-2.2.1 { 181915c8bdbSshaneh catchsql { 1828bb76d39Sdrh SELECT sqlite_compileoption_get(); 183915c8bdbSshaneh } 1848bb76d39Sdrh} {1 {wrong number of arguments to function sqlite_compileoption_get()}} 185915c8bdbSshanehdo_test ctime-2.2.2 { 186915c8bdbSshaneh catchsql { 1878bb76d39Sdrh SELECT sqlite_compileoption_get(0, 0); 188915c8bdbSshaneh } 1898bb76d39Sdrh} {1 {wrong number of arguments to function sqlite_compileoption_get()}} 190915c8bdbSshaneh 191915c8bdbSshaneh# This assumes there is at least 1 compile time option 192915c8bdbSshaneh# (see SQLITE_THREADSAFE above). 193915c8bdbSshanehdo_test ctime-2.3 { 194915c8bdbSshaneh catchsql { 1958bb76d39Sdrh SELECT sqlite_compileoption_used(sqlite_compileoption_get(0)); 196915c8bdbSshaneh } 197915c8bdbSshaneh} {0 1} 198915c8bdbSshaneh 199915c8bdbSshaneh# This assumes there is at least 1 compile time option 200915c8bdbSshaneh# (see SQLITE_THREADSAFE above). 201915c8bdbSshanehdo_test ctime-2.4 { 20288ba618eSshaneh set ans [ catchsql { 2038bb76d39Sdrh SELECT sqlite_compileoption_get(0); 204915c8bdbSshaneh } ] 20588ba618eSshaneh list [lindex $ans 0] 206915c8bdbSshaneh} {0} 207915c8bdbSshaneh 208915c8bdbSshaneh# Get the list of defines using the pragma, 209915c8bdbSshaneh# then try querying each one with the functions. 210915c8bdbSshanehset ans [ catchsql { 211915c8bdbSshaneh PRAGMA compile_options; 212915c8bdbSshaneh} ] 213915c8bdbSshanehset opts [ lindex $ans 1 ] 214915c8bdbSshanehset tc 1 215915c8bdbSshanehforeach opt $opts { 216915c8bdbSshaneh do_test ctime-2.5.$tc { 217915c8bdbSshaneh set N [ expr {$tc-1} ] 218f5fe0039Sdrh set ans1 [catch {db one { 2198bb76d39Sdrh SELECT sqlite_compileoption_get($N); 220f5fe0039Sdrh }} msg] 221f5fe0039Sdrh lappend ans1 $msg 222915c8bdbSshaneh set ans2 [ catchsql { 2238bb76d39Sdrh SELECT sqlite_compileoption_used($opt); 224915c8bdbSshaneh } ] 225915c8bdbSshaneh list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \ 226915c8bdbSshaneh [ expr { $ans2 } ] 227915c8bdbSshaneh } {0 1 {0 1}} 228915c8bdbSshaneh incr tc 1 229915c8bdbSshaneh} 230915c8bdbSshaneh# test 1 past array bounds 231915c8bdbSshanehdo_test ctime-2.5.$tc { 232915c8bdbSshaneh set N [ expr {$tc-1} ] 233915c8bdbSshaneh set ans [ catchsql { 2348bb76d39Sdrh SELECT sqlite_compileoption_get($N); 235915c8bdbSshaneh } ] 236915c8bdbSshaneh} {0 {{}}} 237915c8bdbSshanehincr tc 1 238915c8bdbSshaneh# test 1 before array bounds (N=-1) 239915c8bdbSshanehdo_test ctime-2.5.$tc { 240915c8bdbSshaneh set N -1 241915c8bdbSshaneh set ans [ catchsql { 2428bb76d39Sdrh SELECT sqlite_compileoption_get($N); 243915c8bdbSshaneh } ] 244915c8bdbSshaneh} {0 {{}}} 245915c8bdbSshaneh 246ceb97c11Sdan#-------------------------------------------------------------------------- 247ceb97c11Sdan# Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of 248ceb97c11Sdan# "PRAGMA compile_options". 249ceb97c11Sdan# 250ceb97c11Sdanifcapable direct_read { 251ceb97c11Sdan set res 1 252ceb97c11Sdan} else { 253ceb97c11Sdan set res 0 254ceb97c11Sdan} 255ceb97c11Sdando_test ctime-3.0.1 { 256ceb97c11Sdan expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0 257ceb97c11Sdan} $res 258915c8bdbSshaneh 259915c8bdbSshanehfinish_test 260