summaryrefslogtreecommitdiffstats
path: root/test/ctime.test
blob: 26b2fa2ee2ded74a5830d656df29720dcb6ffe1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# 2009 February 24
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the compile time diagnostic 
# functions.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test organization:
#
# ctime-1.*: Test pragma support.
# ctime-2.*: Test function support.
#

ifcapable !pragma||!compileoption_diags {
  finish_test
  return
}

#####################
# ctime-1.*: Test pragma support.

do_test ctime-1.1.1 {
  catchsql {
    PRAGMA compile_options();
  }
} {1 {near ")": syntax error}}
do_test ctime-1.1.2 {
  catchsql {
    PRAGMA compile_options(NULL);
  }
} {1 {near "NULL": syntax error}}
do_test ctime-1.1.3 {
  catchsql {
    PRAGMA compile_options *;
  }
} {1 {near "*": syntax error}}

do_test ctime-1.2.1 {
  set ans [ catchsql {
    PRAGMA compile_options;
  } ]
  list [ lindex $ans 0 ]
} {0}
# the results should be in sorted order already
do_test ctime-1.2.2 {
  set ans [ catchsql {
    PRAGMA compile_options;
  } ]
  list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ]
} {0 1}

# Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are
# a couple of these configurations in releasetest.tcl).
#
ifcapable threadsafe2 {
  foreach {tn opt res} {
    1 SQLITE_THREADSAFE     1
    2 THREADSAFE            1
    3 THREADSAFE=0          0
    4 THREADSAFE=1          0
    5 THREADSAFE=2          1
    6 THREADSAFE=           0
  } {
    do_execsql_test ctime-1.3.$tn {
      SELECT sqlite_compileoption_used($opt)
    } $res
  }
}

# SQLITE_THREADSAFE should pretty much always be defined
# one way or the other, and it must have a value of 0 or 1.
sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
do_test ctime-1.4.1 {
  catchsql {
    SELECT sqlite_compileoption_used('SQLITE_THREADSAFE');
  }
} {0 1}
do_test ctime-1.4.2 {
  catchsql {
    SELECT sqlite_compileoption_used('THREADSAFE');
  }
} {0 1}
do_test ctime-1.4.3 {
  catchsql {
    SELECT sqlite_compileoption_used("THREADSAFE");
  }
} {0 1}

do_test ctime-1.5 {
  set ans1 [ catchsql {
    SELECT sqlite_compileoption_used('THREADSAFE=0');
  } ]
  set ans2 [ catchsql {
    SELECT sqlite_compileoption_used('THREADSAFE=1');
  } ]
  set ans3 [ catchsql {
    SELECT sqlite_compileoption_used('THREADSAFE=2');
  } ]
  lsort [ list $ans1 $ans2 $ans3 ]
} {{0 0} {0 0} {0 1}}

do_test ctime-1.6 {
  execsql {
    SELECT sqlite_compileoption_used('THREADSAFE=');
  }
} {0}

do_test ctime-1.7.1 {
  execsql {
    SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS');
  }
} {0}
do_test ctime-1.7.2 {
  execsql {
    SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS');
  }
} {0}

#####################
# ctime-2.*: Test function support.

do_test ctime-2.1.1 {
  catchsql {
    SELECT sqlite_compileoption_used();
  }
} {1 {wrong number of arguments to function sqlite_compileoption_used()}}
do_test ctime-2.1.2 {
  catchsql {
    SELECT sqlite_compileoption_used(NULL);
  }
} {0 {{}}}
do_test ctime-2.1.3 {
  catchsql {
    SELECT sqlite_compileoption_used("");
  }
} {0 0}
do_test ctime-2.1.4 {
  catchsql {
    SELECT sqlite_compileoption_used('');
  }
} {0 0}
do_test ctime-2.1.5 {
  catchsql {
    SELECT sqlite_compileoption_used(foo);
  }
} {1 {no such column: foo}}
do_test ctime-2.1.6 {
  catchsql {
    SELECT sqlite_compileoption_used('THREADSAFE', 0);
  }
} {1 {wrong number of arguments to function sqlite_compileoption_used()}}
do_test ctime-2.1.7 {
  catchsql {
    SELECT sqlite_compileoption_used(0);
  }
} {0 0}
do_test ctime-2.1.8 {
  catchsql {
    SELECT sqlite_compileoption_used('0');
  }
} {0 0}
do_test ctime-2.1.9 {
  catchsql {
    SELECT sqlite_compileoption_used(1.0);
  }
} {0 0}

do_test ctime-2.2.1 {
  catchsql {
    SELECT sqlite_compileoption_get();
  }
} {1 {wrong number of arguments to function sqlite_compileoption_get()}}
do_test ctime-2.2.2 {
  catchsql {
    SELECT sqlite_compileoption_get(0, 0);
  }
} {1 {wrong number of arguments to function sqlite_compileoption_get()}}

# This assumes there is at least 1 compile time option
# (see SQLITE_THREADSAFE above).
do_test ctime-2.3 {
  catchsql {
    SELECT sqlite_compileoption_used(sqlite_compileoption_get(0));
  }
} {0 1}

# This assumes there is at least 1 compile time option
# (see SQLITE_THREADSAFE above).
do_test ctime-2.4 {
  set ans [ catchsql {
    SELECT sqlite_compileoption_get(0);
  } ]
  list [lindex $ans 0]
} {0}

# Get the list of defines using the pragma,
# then try querying each one with the functions.
set ans [ catchsql {
  PRAGMA compile_options;
} ]
set opts [ lindex $ans 1 ]
set tc 1
foreach opt $opts {
  do_test ctime-2.5.$tc {
    set N [ expr {$tc-1} ]
    set ans1 [catch {db one {
      SELECT sqlite_compileoption_get($N);
    }} msg]
    lappend ans1 $msg
    set ans2 [ catchsql {
      SELECT sqlite_compileoption_used($opt);
    } ]
    list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \
         [ expr { $ans2 } ]
  } {0 1 {0 1}}
  incr tc 1
}
# test 1 past array bounds
do_test ctime-2.5.$tc {
  set N [ expr {$tc-1} ]
  set ans [ catchsql {
    SELECT sqlite_compileoption_get($N);
  } ]
} {0 {{}}}
incr tc 1
# test 1 before array bounds (N=-1)
do_test ctime-2.5.$tc {
  set N -1
  set ans [ catchsql {
    SELECT sqlite_compileoption_get($N);
  } ]
} {0 {{}}}

#--------------------------------------------------------------------------
# Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of
# "PRAGMA compile_options".
#
ifcapable direct_read {
  set res 1
} else {
  set res 0
}
do_test ctime-3.0.1 {
  expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0
} $res

finish_test