Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: third_party/sqlite/src/test/func.test

Issue 949043002: Add //third_party/sqlite to dirs_to_snapshot, remove net_sql.patch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/test/full.test ('k') | third_party/sqlite/src/test/func3.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2001 September 15 1 # 2001 September 15
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The 11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing built-in functions. 12 # focus of this file is testing built-in functions.
13 # 13 #
14 14
15 set testdir [file dirname $argv0] 15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl 16 source $testdir/tester.tcl
17 set testprefix func
17 18
18 # Create a table to work with. 19 # Create a table to work with.
19 # 20 #
20 do_test func-0.0 { 21 do_test func-0.0 {
21 execsql {CREATE TABLE tbl1(t1 text)} 22 execsql {CREATE TABLE tbl1(t1 text)}
22 foreach word {this program is free software} { 23 foreach word {this program is free software} {
23 execsql "INSERT INTO tbl1 VALUES('$word')" 24 execsql "INSERT INTO tbl1 VALUES('$word')"
24 } 25 }
25 execsql {SELECT t1 FROM tbl1 ORDER BY t1} 26 execsql {SELECT t1 FROM tbl1 ORDER BY t1}
26 } {free is program software this} 27 } {free is program software this}
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 do_test func-4.35 { 306 do_test func-4.35 {
306 execsql {SELECT round(1234567890123.445,2);} 307 execsql {SELECT round(1234567890123.445,2);}
307 } {1234567890123.45} 308 } {1234567890123.45}
308 do_test func-4.36 { 309 do_test func-4.36 {
309 execsql {SELECT round(99999999999994.5);} 310 execsql {SELECT round(99999999999994.5);}
310 } {99999999999995.0} 311 } {99999999999995.0}
311 do_test func-4.37 { 312 do_test func-4.37 {
312 execsql {SELECT round(9999999999999.55,1);} 313 execsql {SELECT round(9999999999999.55,1);}
313 } {9999999999999.6} 314 } {9999999999999.6}
314 do_test func-4.38 { 315 do_test func-4.38 {
315 execsql {SELECT round(9999999999999.555,2);} 316 execsql {SELECT round(9999999999999.556,2);}
316 } {9999999999999.56} 317 } {9999999999999.56}
317 } 318 }
318 319
319 # Test the upper() and lower() functions 320 # Test the upper() and lower() functions
320 # 321 #
321 do_test func-5.1 { 322 do_test func-5.1 {
322 execsql {SELECT upper(t1) FROM tbl1} 323 execsql {SELECT upper(t1) FROM tbl1}
323 } {THIS PROGRAM IS FREE SOFTWARE} 324 } {THIS PROGRAM IS FREE SOFTWARE}
324 do_test func-5.2 { 325 do_test func-5.2 {
325 execsql {SELECT lower(upper(t1)) FROM tbl1} 326 execsql {SELECT lower(upper(t1)) FROM tbl1}
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 set sql "SELECT test_auxdata( ? , a ) FROM t4;" 676 set sql "SELECT test_auxdata( ? , a ) FROM t4;"
676 set STMT [sqlite3_prepare $DB $sql -1 TAIL] 677 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
677 sqlite3_bind_text $STMT 1 hello\000 -1 678 sqlite3_bind_text $STMT 1 hello\000 -1
678 set res [list] 679 set res [list]
679 while { "SQLITE_ROW"==[sqlite3_step $STMT] } { 680 while { "SQLITE_ROW"==[sqlite3_step $STMT] } {
680 lappend res [sqlite3_column_text $STMT 0] 681 lappend res [sqlite3_column_text $STMT 0]
681 } 682 }
682 lappend res [sqlite3_finalize $STMT] 683 lappend res [sqlite3_finalize $STMT]
683 } {{0 0} {1 0} SQLITE_OK} 684 } {{0 0} {1 0} SQLITE_OK}
684 685
686 # Test that auxiliary data is discarded when a statement is reset.
687 do_execsql_test 13.8.1 {
688 SELECT test_auxdata('constant') FROM t4;
689 } {0 1}
690 do_execsql_test 13.8.2 {
691 SELECT test_auxdata('constant') FROM t4;
692 } {0 1}
693 db cache flush
694 do_execsql_test 13.8.3 {
695 SELECT test_auxdata('constant') FROM t4;
696 } {0 1}
697 set V "one"
698 do_execsql_test 13.8.4 {
699 SELECT test_auxdata($V), $V FROM t4;
700 } {0 one 1 one}
701 set V "two"
702 do_execsql_test 13.8.5 {
703 SELECT test_auxdata($V), $V FROM t4;
704 } {0 two 1 two}
705 db cache flush
706 set V "three"
707 do_execsql_test 13.8.6 {
708 SELECT test_auxdata($V), $V FROM t4;
709 } {0 three 1 three}
710
711
685 # Make sure that a function with a very long name is rejected 712 # Make sure that a function with a very long name is rejected
686 do_test func-14.1 { 713 do_test func-14.1 {
687 catch { 714 catch {
688 db function [string repeat X 254] {return "hello"} 715 db function [string repeat X 254] {return "hello"}
689 } 716 }
690 } {0} 717 } {0}
691 do_test func-14.2 { 718 do_test func-14.2 {
692 catch { 719 catch {
693 db function [string repeat X 256] {return "hello"} 720 db function [string repeat X 256] {return "hello"}
694 } 721 }
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 execsql { 1187 execsql {
1161 SELECT group_concat(CASE WHEN t1!='software' THEN null ELSE t1 END) FROM tbl1 1188 SELECT group_concat(CASE WHEN t1!='software' THEN null ELSE t1 END) FROM tbl1
1162 } 1189 }
1163 } {software} 1190 } {software}
1164 do_test func-24.12 { 1191 do_test func-24.12 {
1165 execsql { 1192 execsql {
1166 SELECT group_concat(CASE t1 WHEN 'this' THEN '' 1193 SELECT group_concat(CASE t1 WHEN 'this' THEN ''
1167 WHEN 'program' THEN null ELSE t1 END) FROM tbl1 1194 WHEN 'program' THEN null ELSE t1 END) FROM tbl1
1168 } 1195 }
1169 } {,is,free,software} 1196 } {,is,free,software}
1197 # Tests to verify ticket http://www.sqlite.org/src/tktview/55746f9e65f8587c0
1198 do_test func-24.13 {
1199 execsql {
1200 SELECT typeof(group_concat(x)) FROM (SELECT '' AS x);
1201 }
1202 } {text}
1203 do_test func-24.14 {
1204 execsql {
1205 SELECT typeof(group_concat(x,''))
1206 FROM (SELECT '' AS x UNION ALL SELECT '');
1207 }
1208 } {text}
1170 1209
1171 1210
1172 # Use the test_isolation function to make sure that type conversions 1211 # Use the test_isolation function to make sure that type conversions
1173 # on function arguments do not effect subsequent arguments. 1212 # on function arguments do not effect subsequent arguments.
1174 # 1213 #
1175 do_test func-25.1 { 1214 do_test func-25.1 {
1176 execsql {SELECT test_isolation(t1,t1) FROM tbl1} 1215 execsql {SELECT test_isolation(t1,t1) FROM tbl1}
1177 } {this program is free software} 1216 } {this program is free software}
1178 1217
1179 # Try to misuse the sqlite3_create_function() interface. Verify that 1218 # Try to misuse the sqlite3_create_function() interface. Verify that
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 # 1279 #
1241 do_test func-28.1 { 1280 do_test func-28.1 {
1242 db eval { 1281 db eval {
1243 CREATE TABLE t28(x, y DEFAULT(nosuchfunc(1))); 1282 CREATE TABLE t28(x, y DEFAULT(nosuchfunc(1)));
1244 } 1283 }
1245 catchsql { 1284 catchsql {
1246 INSERT INTO t28(x) VALUES(1); 1285 INSERT INTO t28(x) VALUES(1);
1247 } 1286 }
1248 } {1 {unknown function: nosuchfunc()}} 1287 } {1 {unknown function: nosuchfunc()}}
1249 1288
1289 # Verify that the length() and typeof() functions do not actually load
1290 # the content of their argument.
1291 #
1292 do_test func-29.1 {
1293 db eval {
1294 CREATE TABLE t29(id INTEGER PRIMARY KEY, x, y);
1295 INSERT INTO t29 VALUES(1, 2, 3), (2, NULL, 4), (3, 4.5, 5);
1296 INSERT INTO t29 VALUES(4, randomblob(1000000), 6);
1297 INSERT INTO t29 VALUES(5, "hello", 7);
1298 }
1299 db close
1300 sqlite3 db test.db
1301 sqlite3_db_status db CACHE_MISS 1
1302 db eval {SELECT typeof(x), length(x), typeof(y) FROM t29 ORDER BY id}
1303 } {integer 1 integer null {} integer real 3 integer blob 1000000 integer text 5 integer}
1304 do_test func-29.2 {
1305 set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
1306 if {$x<5} {set x 1}
1307 set x
1308 } {1}
1309 do_test func-29.3 {
1310 db close
1311 sqlite3 db test.db
1312 sqlite3_db_status db CACHE_MISS 1
1313 db eval {SELECT typeof(+x) FROM t29 ORDER BY id}
1314 } {integer null real blob text}
1315 if {[permutation] != "mmap"} {
1316 ifcapable !direct_read {
1317 do_test func-29.4 {
1318 set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
1319 if {$x>100} {set x many}
1320 set x
1321 } {many}
1322 }
1323 }
1324 do_test func-29.5 {
1325 db close
1326 sqlite3 db test.db
1327 sqlite3_db_status db CACHE_MISS 1
1328 db eval {SELECT sum(length(x)) FROM t29}
1329 } {1000009}
1330 do_test func-29.6 {
1331 set x [lindex [sqlite3_db_status db CACHE_MISS 1] 1]
1332 if {$x<5} {set x 1}
1333 set x
1334 } {1}
1335
1336 # The OP_Column opcode has an optimization that avoids loading content
1337 # for fields with content-length=0 when the content offset is on an overflow
1338 # page. Make sure the optimization works.
1339 #
1340 do_execsql_test func-29.10 {
1341 CREATE TABLE t29b(a,b,c,d,e,f,g,h,i);
1342 INSERT INTO t29b
1343 VALUES(1, hex(randomblob(2000)), null, 0, 1, '', zeroblob(0),'x',x'01');
1344 SELECT typeof(c), typeof(d), typeof(e), typeof(f),
1345 typeof(g), typeof(h), typeof(i) FROM t29b;
1346 } {null integer integer text blob text blob}
1347 do_execsql_test func-29.11 {
1348 SELECT length(f), length(g), length(h), length(i) FROM t29b;
1349 } {0 0 1 1}
1350 do_execsql_test func-29.12 {
1351 SELECT quote(f), quote(g), quote(h), quote(i) FROM t29b;
1352 } {'' X'' 'x' X'01'}
1353
1354 # EVIDENCE-OF: R-29701-50711 The unicode(X) function returns the numeric
1355 # unicode code point corresponding to the first character of the string
1356 # X.
1357 #
1358 # EVIDENCE-OF: R-55469-62130 The char(X1,X2,...,XN) function returns a
1359 # string composed of characters having the unicode code point values of
1360 # integers X1 through XN, respectively.
1361 #
1362 do_execsql_test func-30.1 {SELECT unicode('$');} 36
1363 do_execsql_test func-30.2 [subst {SELECT unicode('\u00A2');}] 162
1364 do_execsql_test func-30.3 [subst {SELECT unicode('\u20AC');}] 8364
1365 do_execsql_test func-30.4 {SELECT char(36,162,8364);} [subst {$\u00A2\u20AC}]
1366
1367 for {set i 1} {$i<0xd800} {incr i 13} {
1368 do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i
1369 }
1370 for {set i 57344} {$i<=0xfffd} {incr i 17} {
1371 if {$i==0xfeff} continue
1372 do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i
1373 }
1374 for {set i 65536} {$i<=0x10ffff} {incr i 139} {
1375 do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i
1376 }
1377
1378 # Test char().
1379 #
1380 do_execsql_test func-31.1 {
1381 SELECT char(), length(char()), typeof(char())
1382 } {{} 0 text}
1250 finish_test 1383 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/full.test ('k') | third_party/sqlite/src/test/func3.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698