Debian Codegraph @

test/ctime.test

raw
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
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
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.
84 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
85 do_test ctime-1.4.1 {
86 catchsql {
87 SELECT sqlite_compileoption_used('SQLITE_THREADSAFE');
88 }
89 } {0 1}
90 do_test ctime-1.4.2 {
91 catchsql {
92 SELECT sqlite_compileoption_used('THREADSAFE');
93 }
94 } {0 1}
95 do_test ctime-1.4.3 {
96 catchsql {
97 SELECT sqlite_compileoption_used("THREADSAFE");
98 }
99 } {0 1}
100
101 do_test ctime-1.5 {
102 set ans1 [ catchsql {
103 SELECT sqlite_compileoption_used('THREADSAFE=0');
104 } ]
105 set ans2 [ catchsql {
106 SELECT sqlite_compileoption_used('THREADSAFE=1');
107 } ]
108 set ans3 [ catchsql {
109 SELECT sqlite_compileoption_used('THREADSAFE=2');
110 } ]
111 lsort [ list $ans1 $ans2 $ans3 ]
112 } {{0 0} {0 0} {0 1}}
113
114 do_test ctime-1.6 {
115 execsql {
116 SELECT sqlite_compileoption_used('THREADSAFE=');
117 }
118 } {0}
119
120 do_test ctime-1.7.1 {
121 execsql {
122 SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS');
123 }
124 } {0}
125 do_test ctime-1.7.2 {
126 execsql {
127 SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS');
128 }
129 } {0}
130
131 #####################
132 # ctime-2.*: Test function support.
133
134 do_test ctime-2.1.1 {
135 catchsql {
136 SELECT sqlite_compileoption_used();
137 }
138 } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
139 do_test ctime-2.1.2 {
140 catchsql {
141 SELECT sqlite_compileoption_used(NULL);
142 }
143 } {0 {{}}}
144 do_test ctime-2.1.3 {
145 catchsql {
146 SELECT sqlite_compileoption_used("");
147 }
148 } {0 0}
149 do_test ctime-2.1.4 {
150 catchsql {
151 SELECT sqlite_compileoption_used('');
152 }
153 } {0 0}
154 do_test ctime-2.1.5 {
155 catchsql {
156 SELECT sqlite_compileoption_used(foo);
157 }
158 } {1 {no such column: foo}}
159 do_test ctime-2.1.6 {
160 catchsql {
161 SELECT sqlite_compileoption_used('THREADSAFE', 0);
162 }
163 } {1 {wrong number of arguments to function sqlite_compileoption_used()}}
164 do_test ctime-2.1.7 {
165 catchsql {
166 SELECT sqlite_compileoption_used(0);
167 }
168 } {0 0}
169 do_test ctime-2.1.8 {
170 catchsql {
171 SELECT sqlite_compileoption_used('0');
172 }
173 } {0 0}
174 do_test ctime-2.1.9 {
175 catchsql {
176 SELECT sqlite_compileoption_used(1.0);
177 }
178 } {0 0}
179
180 do_test ctime-2.2.1 {
181 catchsql {
182 SELECT sqlite_compileoption_get();
183 }
184 } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
185 do_test ctime-2.2.2 {
186 catchsql {
187 SELECT sqlite_compileoption_get(0, 0);
188 }
189 } {1 {wrong number of arguments to function sqlite_compileoption_get()}}
190
191 # This assumes there is at least 1 compile time option
192 # (see SQLITE_THREADSAFE above).
193 do_test ctime-2.3 {
194 catchsql {
195 SELECT sqlite_compileoption_used(sqlite_compileoption_get(0));
196 }
197 } {0 1}
198
199 # This assumes there is at least 1 compile time option
200 # (see SQLITE_THREADSAFE above).
201 do_test ctime-2.4 {
202 set ans [ catchsql {
203 SELECT sqlite_compileoption_get(0);
204 } ]
205 list [lindex $ans 0]
206 } {0}
207
208 # Get the list of defines using the pragma,
209 # then try querying each one with the functions.
210 set ans [ catchsql {
211 PRAGMA compile_options;
212 } ]
213 set opts [ lindex $ans 1 ]
214 set tc 1
215 foreach opt $opts {
216 do_test ctime-2.5.$tc {
217 set N [ expr {$tc-1} ]
218 set ans1 [catch {db one {
219 SELECT sqlite_compileoption_get($N);
220 }} msg]
221 lappend ans1 $msg
222 set ans2 [ catchsql {
223 SELECT sqlite_compileoption_used($opt);
224 } ]
225 list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \
226 [ expr { $ans2 } ]
227 } {0 1 {0 1}}
228 incr tc 1
229 }
230 # test 1 past array bounds
231 do_test ctime-2.5.$tc {
232 set N [ expr {$tc-1} ]
233 set ans [ catchsql {
234 SELECT sqlite_compileoption_get($N);
235 } ]
236 } {0 {{}}}
237 incr tc 1
238 # test 1 before array bounds (N=-1)
239 do_test ctime-2.5.$tc {
240 set N -1
241 set ans [ catchsql {
242 SELECT sqlite_compileoption_get($N);
243 } ]
244 } {0 {{}}}
245
246 #--------------------------------------------------------------------------
247 # Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of
248 # "PRAGMA compile_options".
249 #
250 ifcapable direct_read {
251 set res 1
252 } else {
253 set res 0
254 }
255 do_test ctime-3.0.1 {
256 expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0
257 } $res
258
259 finish_test