OLD | NEW |
| (Empty) |
1 # 2010 August 27 | |
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. The | |
12 # focus of this file is testing that destructor functions associated | |
13 # with functions created using sqlite3_create_function_v2() is | |
14 # correctly invoked. | |
15 # | |
16 set testdir [file dirname $argv0] | |
17 source $testdir/tester.tcl | |
18 | |
19 | |
20 ifcapable utf16 { | |
21 do_test func3-1.1 { | |
22 set destroyed 0 | |
23 proc destroy {} { set ::destroyed 1 } | |
24 sqlite3_create_function_v2 db f2 -1 any -func f2 -destroy destroy | |
25 set destroyed | |
26 } 0 | |
27 do_test func3-1.2 { | |
28 sqlite3_create_function_v2 db f2 -1 utf8 -func f2 | |
29 set destroyed | |
30 } 0 | |
31 do_test func3-1.3 { | |
32 sqlite3_create_function_v2 db f2 -1 utf16le -func f2 | |
33 set destroyed | |
34 } 0 | |
35 do_test func3-1.4 { | |
36 sqlite3_create_function_v2 db f2 -1 utf16be -func f2 | |
37 set destroyed | |
38 } 1 | |
39 } | |
40 | |
41 do_test func3-2.1 { | |
42 set destroyed 0 | |
43 proc destroy {} { set ::destroyed 1 } | |
44 sqlite3_create_function_v2 db f3 -1 utf8 -func f3 -destroy destroy | |
45 set destroyed | |
46 } 0 | |
47 do_test func3-2.2 { | |
48 sqlite3_create_function_v2 db f3 -1 utf8 -func f3 | |
49 set destroyed | |
50 } 1 | |
51 | |
52 do_test func3-3.1 { | |
53 set destroyed 0 | |
54 proc destroy {} { set ::destroyed 1 } | |
55 sqlite3_create_function_v2 db f3 -1 any -func f3 -destroy destroy | |
56 set destroyed | |
57 } 0 | |
58 do_test func3-3.2 { | |
59 db close | |
60 set destroyed | |
61 } 1 | |
62 | |
63 sqlite3 db test.db | |
64 do_test func3-4.1 { | |
65 set destroyed 0 | |
66 set rc [catch { | |
67 sqlite3_create_function_v2 db f3 -1 any -func f3 -step f3 -destroy destroy | |
68 } msg] | |
69 list $rc $msg | |
70 } {1 SQLITE_MISUSE} | |
71 do_test func3-4.2 { set destroyed } 1 | |
72 | |
73 # EVIDENCE-OF: R-41921-05214 The likelihood(X,Y) function returns | |
74 # argument X unchanged. | |
75 # | |
76 do_execsql_test func3-5.1 { | |
77 SELECT likelihood(9223372036854775807, 0.5); | |
78 } {9223372036854775807} | |
79 do_execsql_test func3-5.2 { | |
80 SELECT likelihood(-9223372036854775808, 0.5); | |
81 } {-9223372036854775808} | |
82 do_execsql_test func3-5.3 { | |
83 SELECT likelihood(14.125, 0.5); | |
84 } {14.125} | |
85 do_execsql_test func3-5.4 { | |
86 SELECT likelihood(NULL, 0.5); | |
87 } {{}} | |
88 do_execsql_test func3-5.5 { | |
89 SELECT likelihood('test-string', 0.5); | |
90 } {test-string} | |
91 do_execsql_test func3-5.6 { | |
92 SELECT quote(likelihood(x'010203000405', 0.5)); | |
93 } {X'010203000405'} | |
94 | |
95 # EVIDENCE-OF: R-44133-61651 The value Y in likelihood(X,Y) must be a | |
96 # floating point constant between 0.0 and 1.0, inclusive. | |
97 # | |
98 do_execsql_test func3-5.7 { | |
99 SELECT likelihood(123, 1.0), likelihood(456, 0.0); | |
100 } {123 456} | |
101 do_test func3-5.8 { | |
102 catchsql { | |
103 SELECT likelihood(123, 1.000001); | |
104 } | |
105 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} | |
106 do_test func3-5.9 { | |
107 catchsql { | |
108 SELECT likelihood(123, -0.000001); | |
109 } | |
110 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} | |
111 do_test func3-5.10 { | |
112 catchsql { | |
113 SELECT likelihood(123, 0.5+0.3); | |
114 } | |
115 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} | |
116 | |
117 # EVIDENCE-OF: R-28535-44631 The likelihood(X) function is a no-op that | |
118 # the code generator optimizes away so that it consumes no CPU cycles | |
119 # during run-time (that is, during calls to sqlite3_step()). | |
120 # | |
121 do_test func3-5.20 { | |
122 db eval {EXPLAIN SELECT likelihood(min(1.0+'2.0',4*11), 0.5)} | |
123 } [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] | |
124 | |
125 | |
126 # EVIDENCE-OF: R-11152-23456 The unlikely(X) function returns the | |
127 # argument X unchanged. | |
128 # | |
129 do_execsql_test func3-5.30 { | |
130 SELECT unlikely(9223372036854775807); | |
131 } {9223372036854775807} | |
132 do_execsql_test func3-5.31 { | |
133 SELECT unlikely(-9223372036854775808); | |
134 } {-9223372036854775808} | |
135 do_execsql_test func3-5.32 { | |
136 SELECT unlikely(14.125); | |
137 } {14.125} | |
138 do_execsql_test func3-5.33 { | |
139 SELECT unlikely(NULL); | |
140 } {{}} | |
141 do_execsql_test func3-5.34 { | |
142 SELECT unlikely('test-string'); | |
143 } {test-string} | |
144 do_execsql_test func3-5.35 { | |
145 SELECT quote(unlikely(x'010203000405')); | |
146 } {X'010203000405'} | |
147 | |
148 # EVIDENCE-OF: R-22887-63324 The unlikely(X) function is a no-op that | |
149 # the code generator optimizes away so that it consumes no CPU cycles at | |
150 # run-time (that is, during calls to sqlite3_step()). | |
151 # | |
152 do_test func3-5.39 { | |
153 db eval {EXPLAIN SELECT unlikely(min(1.0+'2.0',4*11))} | |
154 } [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] | |
155 | |
156 | |
157 # EVIDENCE-OF: R-23735-03107 The likely(X) function returns the argument | |
158 # X unchanged. | |
159 # | |
160 do_execsql_test func3-5.50 { | |
161 SELECT likely(9223372036854775807); | |
162 } {9223372036854775807} | |
163 do_execsql_test func3-5.51 { | |
164 SELECT likely(-9223372036854775808); | |
165 } {-9223372036854775808} | |
166 do_execsql_test func3-5.52 { | |
167 SELECT likely(14.125); | |
168 } {14.125} | |
169 do_execsql_test func3-5.53 { | |
170 SELECT likely(NULL); | |
171 } {{}} | |
172 do_execsql_test func3-5.54 { | |
173 SELECT likely('test-string'); | |
174 } {test-string} | |
175 do_execsql_test func3-5.55 { | |
176 SELECT quote(likely(x'010203000405')); | |
177 } {X'010203000405'} | |
178 | |
179 # EVIDENCE-OF: R-43464-09689 The likely(X) function is a no-op that the | |
180 # code generator optimizes away so that it consumes no CPU cycles at | |
181 # run-time (that is, during calls to sqlite3_step()). | |
182 # | |
183 do_test func3-5.59 { | |
184 db eval {EXPLAIN SELECT likely(min(1.0+'2.0',4*11))} | |
185 } [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}] | |
186 | |
187 | |
188 | |
189 | |
190 finish_test | |
OLD | NEW |