3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
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
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
23 proc destroy {} { set ::destroyed 1 }
24 sqlite3_create_function_v2 db f2 -1 any -func f2 -destroy destroy
28 sqlite3_create_function_v2 db f2 -1 utf8 -func f2
32 sqlite3_create_function_v2 db f2 -1 utf16le -func f2
36 sqlite3_create_function_v2 db f2 -1 utf16be -func f2
43 proc destroy {} { set ::destroyed 1 }
44 sqlite3_create_function_v2 db f3 -1 utf8 -func f3 -destroy destroy
48 sqlite3_create_function_v2 db f3 -1 utf8 -func f3
54 proc destroy {} { set ::destroyed 1 }
55 sqlite3_create_function_v2 db f3 -1 any -func f3 -destroy destroy
67 sqlite3_create_function_v2 db f3 -1 any -func f3 -step f3 -destroy destroy
71 do_test func3-4.2 { set destroyed } 1
73 # EVIDENCE-OF: R-41921-05214 The likelihood(X,Y) function returns
74 # argument X unchanged.
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);
85 do_execsql_test func3-5.4 {
86 SELECT likelihood(NULL, 0.5);
88 do_execsql_test func3-5.5 {
89 SELECT likelihood('test-string', 0.5);
91 do_execsql_test func3-5.6 {
92 SELECT quote(likelihood(x'010203000405', 0.5));
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.
98 do_execsql_test func3-5.7 {
99 SELECT likelihood(123, 1.0), likelihood(456, 0.0);
103 SELECT likelihood(123, 1.000001);
105 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
108 SELECT likelihood(123, -0.000001);
110 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
113 SELECT likelihood(123, 0.5+0.3);
115 } {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
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()).
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)}]
126 # EVIDENCE-OF: R-11152-23456 The unlikely(X) function returns the
127 # argument X unchanged.
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);
138 do_execsql_test func3-5.33 {
139 SELECT unlikely(NULL);
141 do_execsql_test func3-5.34 {
142 SELECT unlikely('test-string');
144 do_execsql_test func3-5.35 {
145 SELECT quote(unlikely(x'010203000405'));
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()).
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)}]
156 # Unlikely() does not preserve the affinity of X.
157 # ticket https://www.sqlite.org/src/tktview/0c620df60b
159 do_execsql_test func3-5.40 {
160 SELECT likely(CAST(1 AS INT))=='1';
162 do_execsql_test func3-5.41 {
163 SELECT unlikely(CAST(1 AS INT))=='1';
165 do_execsql_test func3-5.41 {
166 SELECT likelihood(CAST(1 AS INT),0.5)=='1';
170 # EVIDENCE-OF: R-23735-03107 The likely(X) function returns the argument
173 do_execsql_test func3-5.50 {
174 SELECT likely(9223372036854775807);
175 } {9223372036854775807}
176 do_execsql_test func3-5.51 {
177 SELECT likely(-9223372036854775808);
178 } {-9223372036854775808}
179 do_execsql_test func3-5.52 {
180 SELECT likely(14.125);
182 do_execsql_test func3-5.53 {
185 do_execsql_test func3-5.54 {
186 SELECT likely('test-string');
188 do_execsql_test func3-5.55 {
189 SELECT quote(likely(x'010203000405'));
192 # EVIDENCE-OF: R-43464-09689 The likely(X) function is a no-op that the
193 # code generator optimizes away so that it consumes no CPU cycles at
194 # run-time (that is, during calls to sqlite3_step()).
197 db eval {EXPLAIN SELECT likely(min(1.0+'2.0',4*11))}
198 } [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}]