Chromium Code Reviews

Side by Side Diff: third_party/sqlite/src/test/fuzzer1.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, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 # 2011 March 25 1 # 2011 March 25
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 TCL interface to the 11 # This file implements regression tests for TCL interface to the
12 # SQLite library. 12 # SQLite library.
13 # 13 #
14 # The focus of the tests is the word-fuzzer virtual table. 14 # The focus of the tests is the word-fuzzer virtual table.
15 # 15 #
16 16
17 set testdir [file dirname $argv0] 17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl 18 source $testdir/tester.tcl
19 19
20 ifcapable !vtab { 20 ifcapable !vtab {
21 finish_test 21 finish_test
22 return 22 return
23 } 23 }
24 24
25 register_fuzzer_module db 25 set ::testprefix fuzzer1
26 do_test fuzzer1-1.0 { 26
27 catchsql {CREATE VIRTUAL TABLE fault1 USING fuzzer;} 27 load_static_extension db fuzzer
28 } {1 {fuzzer virtual tables must be TEMP}} 28
29 do_test fuzzer1-1.1 { 29 # Check configuration errors.
30 db eval {CREATE VIRTUAL TABLE temp.f1 USING fuzzer;} 30 #
31 do_catchsql_test fuzzer1-1.1 {
32 CREATE VIRTUAL TABLE f USING fuzzer;
33 } {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}}
34
35 do_catchsql_test fuzzer1-1.2 {
36 CREATE VIRTUAL TABLE f USING fuzzer(one, two);
37 } {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}}
38
39 do_catchsql_test fuzzer1-1.3 {
40 CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable);
41 } {1 {fuzzer: no such table: main.nosuchtable}}
42
43 do_catchsql_test fuzzer1-1.4 {
44 CREATE TEMP TABLE nosuchtable(a, b, c, d);
45 CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable);
46 } {1 {fuzzer: no such table: main.nosuchtable}}
47
48 do_catchsql_test fuzzer1-1.5 {
49 DROP TABLE temp.nosuchtable;
50 CREATE TABLE nosuchtable(a, b, c, d);
51 CREATE VIRTUAL TABLE temp.f USING fuzzer(nosuchtable);
52 } {1 {fuzzer: no such table: temp.nosuchtable}}
53
54 do_catchsql_test fuzzer1-1.6 {
55 DROP TABLE IF EXISTS f_rules;
56 CREATE TABLE f_rules(a, b, c);
57 CREATE VIRTUAL TABLE f USING fuzzer(f_rules);
58 } {1 {fuzzer: f_rules has 3 columns, expected 4}}
59
60 do_catchsql_test fuzzer1-1.7 {
61 DROP TABLE IF EXISTS f_rules;
62 CREATE TABLE f_rules(a, b, c, d, e);
63 CREATE VIRTUAL TABLE f USING fuzzer(f_rules);
64 } {1 {fuzzer: f_rules has 5 columns, expected 4}}
65
66
67 do_execsql_test fuzzer1-2.1 {
68 CREATE TABLE f1_rules(ruleset DEFAULT 0, cfrom, cto, cost);
69 INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','a',1);
70 INSERT INTO f1_rules(cfrom, cto, cost) VALUES('a','e',10);
71 INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','o',100);
72
73 CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules);
31 } {} 74 } {}
32 do_test fuzzer1-1.2 { 75
33 db eval { 76 do_execsql_test fuzzer1-2.1 {
34 INSERT INTO f1(cfrom, cto, cost) VALUES('e','a',1); 77 SELECT word, distance FROM f1 WHERE word MATCH 'abcde'
35 INSERT INTO f1(cfrom, cto, cost) VALUES('a','e',10); 78 } {
36 INSERT INTO f1(cfrom, cto, cost) VALUES('e','o',100); 79 abcde 0 abcda 1 ebcde 10
37 } 80 ebcda 11 abcdo 100 ebcdo 110
81 obcde 110 obcda 111 obcdo 210
82 }
83
84 do_execsql_test fuzzer1-2.4 {
85 INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'b','x',1);
86 INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'d','y',10);
87 INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'y','z',100);
88
89 DROP TABLE f1;
90 CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules);
38 } {} 91 } {}
39 92
40 do_test fuzzer1-1.3 { 93 do_execsql_test fuzzer1-2.5 {
41 db eval { 94 SELECT word, distance FROM f1 WHERE word MATCH 'abcde'
42 SELECT word, distance FROM f1 WHERE word MATCH 'abcde' 95 } {
43 } 96 abcde 0 abcda 1 ebcde 10
44 } {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100 ebcdo 110 obcde 110 obcda 111 obc do 210} 97 ebcda 11 abcdo 100 ebcdo 110
98 obcde 110 obcda 111 obcdo 210
99 }
100
101 do_execsql_test fuzzer1-2.6 {
102 SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0
103 } {
104 abcde 0 abcda 1 ebcde 10
105 ebcda 11 abcdo 100 ebcdo 110
106 obcde 110 obcda 111 obcdo 210
107 }
108
109 do_execsql_test fuzzer1-2.7 {
110 SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1
111 } {
112 abcde 0 axcde 1 abcye 10
113 axcye 11 abcze 110 axcze 111
114 }
115
116 do_test fuzzer1-1.8 {
117 db eval {
118 SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100
119 }
120 } {abcde 0 abcda 1 ebcde 10 ebcda 11}
121 do_test fuzzer1-1.9 {
122 db eval {
123 SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<=100
124 }
125 } {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100}
126 do_test fuzzer1-1.10 {
127 db eval {
128 SELECT word, distance FROM f1
129 WHERE word MATCH 'abcde' AND distance<100 AND ruleset=0
130 }
131 } {abcde 0 abcda 1 ebcde 10 ebcda 11}
132 do_test fuzzer1-1.11 {
133 db eval {
134 SELECT word, distance FROM f1
135 WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0
136 }
137 } {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100}
138 do_test fuzzer1-1.12 {
139 db eval {
140 SELECT word, distance FROM f1
141 WHERE word MATCH 'abcde' AND distance<11 AND ruleset=1
142 }
143 } {abcde 0 axcde 1 abcye 10}
144 do_test fuzzer1-1.13 {
145 db eval {
146 SELECT word, distance FROM f1
147 WHERE word MATCH 'abcde' AND distance<=11 AND ruleset=1
148 }
149 } {abcde 0 axcde 1 abcye 10 axcye 11}
150 do_test fuzzer1-1.14 {
151 catchsql {INSERT INTO f1 VALUES(1)}
152 } {1 {table f1 may not be modified}}
153 do_test fuzzer1-1.15 {
154 catchsql {DELETE FROM f1}
155 } {1 {table f1 may not be modified}}
156 do_test fuzzer1-1.16 {
157 catchsql {UPDATE f1 SET rowid=rowid+10000}
158 } {1 {table f1 may not be modified}}
159
45 160
46 do_test fuzzer1-2.0 { 161 do_test fuzzer1-2.0 {
47 execsql { 162 execsql {
48 CREATE VIRTUAL TABLE temp.f2 USING fuzzer;
49 -- costs based on English letter frequencies 163 -- costs based on English letter frequencies
50 INSERT INTO f2(cFrom,cTo,cost) VALUES('a','e',24); 164 CREATE TEMP TABLE f2_rules(ruleset DEFAULT 0, cFrom, cTo, cost);
51 INSERT INTO f2(cFrom,cTo,cost) VALUES('a','o',47); 165 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','e',24);
52 INSERT INTO f2(cFrom,cTo,cost) VALUES('a','u',50); 166 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','o',47);
53 INSERT INTO f2(cFrom,cTo,cost) VALUES('e','a',23); 167 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','u',50);
54 INSERT INTO f2(cFrom,cTo,cost) VALUES('e','i',33); 168 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','a',23);
55 INSERT INTO f2(cFrom,cTo,cost) VALUES('e','o',37); 169 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','i',33);
56 INSERT INTO f2(cFrom,cTo,cost) VALUES('i','e',33); 170 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','o',37);
57 INSERT INTO f2(cFrom,cTo,cost) VALUES('i','y',33); 171 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','e',33);
58 INSERT INTO f2(cFrom,cTo,cost) VALUES('o','a',41); 172 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','y',33);
59 INSERT INTO f2(cFrom,cTo,cost) VALUES('o','e',46); 173 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','a',41);
60 INSERT INTO f2(cFrom,cTo,cost) VALUES('o','u',57); 174 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','e',46);
61 INSERT INTO f2(cFrom,cTo,cost) VALUES('u','o',58); 175 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','u',57);
62 INSERT INTO f2(cFrom,cTo,cost) VALUES('y','i',33); 176 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','o',58);
63 177 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','i',33);
64 INSERT INTO f2(cFrom,cTo,cost) VALUES('t','th',70); 178
65 INSERT INTO f2(cFrom,cTo,cost) VALUES('th','t',66); 179 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','th',70);
66 180 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('th','t',66);
67 181
68 INSERT INTO f2(cFrom,cTo,cost) VALUES('a','',84); 182 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','',84);
69 INSERT INTO f2(cFrom,cTo,cost) VALUES('','b',106); 183 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','b',106);
70 INSERT INTO f2(cFrom,cTo,cost) VALUES('b','',106); 184 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('b','',106);
71 INSERT INTO f2(cFrom,cTo,cost) VALUES('','c',94); 185 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','c',94);
72 INSERT INTO f2(cFrom,cTo,cost) VALUES('c','',94); 186 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('c','',94);
73 INSERT INTO f2(cFrom,cTo,cost) VALUES('','d',89); 187 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','d',89);
74 INSERT INTO f2(cFrom,cTo,cost) VALUES('d','',89); 188 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('d','',89);
75 INSERT INTO f2(cFrom,cTo,cost) VALUES('','e',83); 189 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','e',83);
76 INSERT INTO f2(cFrom,cTo,cost) VALUES('e','',83); 190 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','',83);
77 INSERT INTO f2(cFrom,cTo,cost) VALUES('','f',97); 191 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','f',97);
78 INSERT INTO f2(cFrom,cTo,cost) VALUES('f','',97); 192 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('f','',97);
79 INSERT INTO f2(cFrom,cTo,cost) VALUES('','g',99); 193 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','g',99);
80 INSERT INTO f2(cFrom,cTo,cost) VALUES('g','',99); 194 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('g','',99);
81 INSERT INTO f2(cFrom,cTo,cost) VALUES('','h',86); 195 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','h',86);
82 INSERT INTO f2(cFrom,cTo,cost) VALUES('h','',86); 196 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('h','',86);
83 INSERT INTO f2(cFrom,cTo,cost) VALUES('','i',85); 197 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','i',85);
84 INSERT INTO f2(cFrom,cTo,cost) VALUES('i','',85); 198 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','',85);
85 INSERT INTO f2(cFrom,cTo,cost) VALUES('','j',120); 199 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','j',120);
86 INSERT INTO f2(cFrom,cTo,cost) VALUES('j','',120); 200 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('j','',120);
87 INSERT INTO f2(cFrom,cTo,cost) VALUES('','k',120); 201 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','k',120);
88 INSERT INTO f2(cFrom,cTo,cost) VALUES('k','',120); 202 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('k','',120);
89 INSERT INTO f2(cFrom,cTo,cost) VALUES('','l',89); 203 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','l',89);
90 INSERT INTO f2(cFrom,cTo,cost) VALUES('l','',89); 204 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('l','',89);
91 INSERT INTO f2(cFrom,cTo,cost) VALUES('','m',96); 205 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','m',96);
92 INSERT INTO f2(cFrom,cTo,cost) VALUES('m','',96); 206 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('m','',96);
93 INSERT INTO f2(cFrom,cTo,cost) VALUES('','n',85); 207 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','n',85);
94 INSERT INTO f2(cFrom,cTo,cost) VALUES('n','',85); 208 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('n','',85);
95 INSERT INTO f2(cFrom,cTo,cost) VALUES('','o',85); 209 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','o',85);
96 INSERT INTO f2(cFrom,cTo,cost) VALUES('o','',85); 210 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','',85);
97 INSERT INTO f2(cFrom,cTo,cost) VALUES('','p',100); 211 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','p',100);
98 INSERT INTO f2(cFrom,cTo,cost) VALUES('p','',100); 212 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('p','',100);
99 INSERT INTO f2(cFrom,cTo,cost) VALUES('','q',120); 213 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','q',120);
100 INSERT INTO f2(cFrom,cTo,cost) VALUES('q','',120); 214 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('q','',120);
101 INSERT INTO f2(cFrom,cTo,cost) VALUES('','r',86); 215 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','r',86);
102 INSERT INTO f2(cFrom,cTo,cost) VALUES('r','',86); 216 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('r','',86);
103 INSERT INTO f2(cFrom,cTo,cost) VALUES('','s',86); 217 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','s',86);
104 INSERT INTO f2(cFrom,cTo,cost) VALUES('s','',86); 218 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('s','',86);
105 INSERT INTO f2(cFrom,cTo,cost) VALUES('','t',84); 219 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','t',84);
106 INSERT INTO f2(cFrom,cTo,cost) VALUES('t','',84); 220 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','',84);
107 INSERT INTO f2(cFrom,cTo,cost) VALUES('','u',94); 221 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','u',94);
108 INSERT INTO f2(cFrom,cTo,cost) VALUES('u','',94); 222 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','',94);
109 INSERT INTO f2(cFrom,cTo,cost) VALUES('','v',120); 223 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','v',120);
110 INSERT INTO f2(cFrom,cTo,cost) VALUES('v','',120); 224 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('v','',120);
111 INSERT INTO f2(cFrom,cTo,cost) VALUES('','w',96); 225 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','w',96);
112 INSERT INTO f2(cFrom,cTo,cost) VALUES('w','',96); 226 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('w','',96);
113 INSERT INTO f2(cFrom,cTo,cost) VALUES('','x',120); 227 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','x',120);
114 INSERT INTO f2(cFrom,cTo,cost) VALUES('x','',120); 228 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('x','',120);
115 INSERT INTO f2(cFrom,cTo,cost) VALUES('','y',100); 229 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','y',100);
116 INSERT INTO f2(cFrom,cTo,cost) VALUES('y','',100); 230 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','',100);
117 INSERT INTO f2(cFrom,cTo,cost) VALUES('','z',120); 231 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','z',120);
118 INSERT INTO f2(cFrom,cTo,cost) VALUES('z','',120); 232 INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('z','',120);
233 INSERT INTO f2_rules(ruleset,cFrom,cTo,cost)
234 SELECT 1, cFrom, cTo, 100 FROM f2_rules WHERE ruleset=0;
235 INSERT INTO f2_rules(ruleset,cFrom,cTo,cost)
236 SELECT 2, cFrom, cTo, 200-cost FROM f2_rules WHERE ruleset=0;
237 INSERT INTO f2_rules(ruleset,cFrom,cTo,cost)
238 SELECT 3, cFrom, cTo, cost FROM f2_rules WHERE ruleset=0;
239 INSERT INTO f2_rules(ruleset,cFrom,cTo,cost)
240 VALUES(3, 'mallard','duck',50),
241 (3, 'duck', 'mallard', 50),
242 (3, 'rock', 'stone', 50),
243 (3, 'stone', 'rock', 50);
244
245
246 CREATE VIRTUAL TABLE temp.f2 USING fuzzer(f2_rules);
119 247
120 -- Street names for the 28269 ZIPCODE. 248 -- Street names for the 28269 ZIPCODE.
121 -- 249 --
122 CREATE TEMP TABLE streetname(n TEXT UNIQUE); 250 CREATE TEMP TABLE streetname(n TEXT UNIQUE);
123 INSERT INTO streetname VALUES('abbotsinch'); 251 INSERT INTO streetname VALUES('abbotsinch');
124 INSERT INTO streetname VALUES('abbottsgate'); 252 INSERT INTO streetname VALUES('abbottsgate');
125 INSERT INTO streetname VALUES('abbywood'); 253 INSERT INTO streetname VALUES('abbywood');
126 INSERT INTO streetname VALUES('abner'); 254 INSERT INTO streetname VALUES('abner');
127 INSERT INTO streetname VALUES('acacia ridge'); 255 INSERT INTO streetname VALUES('acacia ridge');
128 INSERT INTO streetname VALUES('acorn creek'); 256 INSERT INTO streetname VALUES('acorn creek');
(...skipping 1240 matching lines...)
1369 AND f2.word=streetname.n 1497 AND f2.word=streetname.n
1370 } 1498 }
1371 } {thistledown 103} 1499 } {thistledown 103}
1372 do_test fuzzer1-2.3 { 1500 do_test fuzzer1-2.3 {
1373 execsql { 1501 execsql {
1374 SELECT DISTINCT streetname.n FROM f2, streetname 1502 SELECT DISTINCT streetname.n FROM f2, streetname
1375 WHERE f2.word MATCH 'tayle' 1503 WHERE f2.word MATCH 'tayle'
1376 AND f2.distance<=200 1504 AND f2.distance<=200
1377 AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF') 1505 AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF')
1378 } 1506 }
1379 } {steelewood tallia tallu talwyn taymouth thelema trailer {tyler finley}} 1507 } {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema}
1380 1508 do_test fuzzer1-2.4 {
1509 execsql {
1510 SELECT DISTINCT streetname.n
1511 FROM f2 JOIN streetname
1512 ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz'))
1513 WHERE f2.word MATCH 'duck'
1514 AND f2.distance<150
1515 AND f2.ruleset=3
1516 ORDER BY 1
1517 }
1518 } {mallard {mallard cove} {mallard forest} {mallard grove} {mallard hill} {malla rd park} {mallard ridge} {mallard view}}
1519 do_test fuzzer1-2.5 {
1520 execsql {
1521 SELECT DISTINCT streetname.n
1522 FROM f2 JOIN streetname
1523 ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz'))
1524 WHERE f2.word MATCH 'duck'
1525 AND f2.distance<150
1526 AND f2.ruleset=2
1527 ORDER BY 1
1528 }
1529 } {}
1530
1531 forcedelete test.db2
1532 do_execsql_test fuzzer1-4.1 {
1533 ATTACH 'test.db2' AS aux;
1534 CREATE TABLE aux.f3_rules(ruleset, cfrom, cto, cost);
1535 INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(0, 'x','y', 10);
1536 INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(1, 'a','b', 10);
1537 CREATE VIRTUAL TABLE aux.f3 USING fuzzer(f3_rules);
1538 SELECT word FROM f3 WHERE word MATCH 'ax'
1539 } {ax ay}
1540
1541 #-------------------------------------------------------------------------
1542 #
1543 # 1.5.1 - Check things work with a fuzzer data table name that requires
1544 # quoting. Also that NULL entries in the "from" column of the
1545 # data table are treated as zero length strings ('').
1546 #
1547 # 1.5.2 - Check that no-op rules (i.e. C->C) are ignored. Test NULL in
1548 # the "to" column of a fuzzer data table.
1549 #
1550 # 1.5.3 - Test out-of-range values for the cost field of the data table.
1551 #
1552 # 1.5.4 - Test out-of-range values for the string fields of the data table.
1553 #
1554 # 1.5.5 - Test out-of-range values for the ruleset field of the data table.
1555 #
1556 do_execsql_test 5.1 {
1557 CREATE TABLE "fuzzer [x] rules table"(a, b, c, d);
1558 INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, 'abc', 10);
1559 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1560 SELECT word, distance FROM x WHERE word MATCH '123' LIMIT 4;
1561 } {123 0 abc123 10 1abc23 10 12abc3 10}
1562
1563 do_execsql_test 5.2 {
1564 DELETE FROM "fuzzer [x] rules table";
1565 INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', NULL, 20);
1566 INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, NULL, 10);
1567 INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', 'x', 10);
1568
1569 DROP TABLE x;
1570 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1571
1572 SELECT word, distance FROM x WHERE word MATCH 'xx';
1573 } {xx 0 x 20 {} 40}
1574
1575 do_execsql_test 5.3.1 {
1576 DROP TABLE IF EXISTS x;
1577 INSERT INTO "fuzzer [x] rules table" VALUES(0, 'c', 'd', 1001);
1578 }
1579 do_catchsql_test 5.3.2 {
1580 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1581 } {1 {fuzzer: cost must be between 1 and 1000}}
1582
1583 do_execsql_test 5.3.3 {
1584 DROP TABLE IF EXISTS x;
1585 DELETE FROM "fuzzer [x] rules table";
1586 INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', 0);
1587 }
1588 do_catchsql_test 5.3.4 {
1589 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1590 } {1 {fuzzer: cost must be between 1 and 1000}}
1591
1592 do_execsql_test 5.3.5 {
1593 DROP TABLE IF EXISTS x;
1594 DELETE FROM "fuzzer [x] rules table";
1595 INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', -20);
1596 }
1597 do_catchsql_test 5.3.6 {
1598 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1599 } {1 {fuzzer: cost must be between 1 and 1000}}
1600
1601 do_execsql_test 5.4.1 {
1602 DROP TABLE IF EXISTS x;
1603 DELETE FROM "fuzzer [x] rules table";
1604 INSERT INTO "fuzzer [x] rules table" VALUES(
1605 0, 'x', '12345678901234567890123456789012345678901234567890', 2
1606 );
1607 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1608 SELECT word FROM x WHERE word MATCH 'x';
1609 } {x 12345678901234567890123456789012345678901234567890}
1610
1611 do_execsql_test 5.4.2 {
1612 DROP TABLE IF EXISTS x;
1613 DELETE FROM "fuzzer [x] rules table";
1614 INSERT INTO "fuzzer [x] rules table" VALUES(
1615 0, 'x', '123456789012345678901234567890123456789012345678901', 2
1616 );
1617 }
1618 do_catchsql_test 5.4.3 {
1619 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1620 } {1 {fuzzer: maximum string length is 50}}
1621
1622 do_execsql_test 5.4.4 {
1623 DROP TABLE IF EXISTS x;
1624 DELETE FROM "fuzzer [x] rules table";
1625 INSERT INTO "fuzzer [x] rules table" VALUES(
1626 0, '123456789012345678901234567890123456789012345678901', 'x', 2
1627 );
1628 }
1629 do_catchsql_test 5.4.5 {
1630 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1631 } {1 {fuzzer: maximum string length is 50}}
1632
1633 do_execsql_test 5.5.1 {
1634 DROP TABLE IF EXISTS x;
1635 DELETE FROM "fuzzer [x] rules table";
1636 INSERT INTO "fuzzer [x] rules table" VALUES(-1, 'x', 'y', 2);
1637 }
1638 do_catchsql_test 5.5.2 {
1639 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1640 } {1 {fuzzer: ruleset must be between 0 and 2147483647}}
1641
1642 do_execsql_test 5.5.3 {
1643 DROP TABLE IF EXISTS x;
1644 DELETE FROM "fuzzer [x] rules table";
1645 INSERT INTO "fuzzer [x] rules table" VALUES((1<<32)+100, 'x', 'y', 2);
1646 }
1647 do_catchsql_test 5.5.4 {
1648 CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table');
1649 } {1 {fuzzer: ruleset must be between 0 and 2147483647}}
1650
1651 #-------------------------------------------------------------------------
1652 # This test uses a fuzzer table with many rules. There is one rule to
1653 # map each possible two character string, where characters are lower-case
1654 # letters used in the English language, to all other possible two character
1655 # strings. In total, (26^4)-(26^2) mappings (the subtracted term represents
1656 # the no-op mappings discarded automatically by the fuzzer).
1657 #
1658 #
1659 do_execsql_test 6.1.1 {
1660 DROP TABLE IF EXISTS x1;
1661 DROP TABLE IF EXISTS x1_rules;
1662 CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost);
1663 }
1664 puts "This test is slow - perhaps around 7 seconds on an average pc"
1665 do_test 6.1.2 {
1666 set LETTERS {a b c d e f g h i j k l m n o p q r s t u v w x y z}
1667 set cost 1
1668 db transaction {
1669 foreach c1 $LETTERS {
1670 foreach c2 $LETTERS {
1671 foreach c3 $LETTERS {
1672 foreach c4 $LETTERS {
1673 db eval {INSERT INTO x1_rules VALUES(0, $c1||$c2, $c3||$c4, $cost)}
1674 set cost [expr ($cost%1000) + 1]
1675 }
1676 }
1677 }
1678 }
1679 db eval {UPDATE x1_rules SET cost = 20 WHERE cost<20 AND cFrom!='xx'}
1680 }
1681 } {}
1682
1683 do_execsql_test 6.2 {
1684 SELECT count(*) FROM x1_rules WHERE cTo!=cFrom;
1685 } [expr 26*26*26*26 - 26*26]
1686
1687 do_execsql_test 6.2.1 {
1688 CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules);
1689 SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10;
1690 } {xx hw hx hy hz ia ib ic id ie}
1691 do_execsql_test 6.2.2 {
1692 SELECT cTo FROM x1_rules WHERE cFrom='xx'
1693 ORDER BY cost asc, rowid asc LIMIT 9;
1694 } {hw hx hy hz ia ib ic id ie}
1695
1696 #-------------------------------------------------------------------------
1697 # Test using different types of quotes with CREATE VIRTUAL TABLE
1698 # arguments.
1699 #
1700 do_execsql_test 7.1 {
1701 CREATE TABLE [x2 "rules] (a, b, c, d);
1702 INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5);
1703 }
1704 foreach {tn sql} {
1705 1 { CREATE VIRTUAL TABLE x2 USING fuzzer( [x2 "rules] ) }
1706 2 { CREATE VIRTUAL TABLE x2 USING fuzzer( "x2 ""rules" ) }
1707 3 { CREATE VIRTUAL TABLE x2 USING fuzzer( 'x2 "rules' ) }
1708 4 { CREATE VIRTUAL TABLE x2 USING fuzzer( `x2 "rules` ) }
1709 } {
1710 do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 }
1711 do_execsql_test 7.2.$tn.2 $sql
1712 do_execsql_test 7.2.$tn.3 {
1713 SELECT word FROM x2 WHERE word MATCH 'aaa'
1714 } {aaa baa aba aab bab abb bba bbb}
1715 }
1716
1717 #-------------------------------------------------------------------------
1718 # Test using a fuzzer table in different contexts.
1719 #
1720 do_execsql_test 8.1 {
1721 CREATE TABLE x3_rules(rule_set, cFrom, cTo, cost);
1722 INSERT INTO x3_rules VALUES(2, 'a', 'x', 10);
1723 INSERT INTO x3_rules VALUES(2, 'a', 'y', 9);
1724 INSERT INTO x3_rules VALUES(2, 'a', 'z', 8);
1725 CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
1726 }
1727
1728 do_execsql_test 8.2.1 {
1729 SELECT cFrom, cTo, word
1730 FROM x3_rules CROSS JOIN x3
1731 WHERE word MATCH 'a' AND cost=distance AND ruleset=2
1732 ORDER BY +cTo;
1733 } {a x x a y y a z z}
1734
1735 do_execsql_test 8.2.2 {
1736 SELECT cFrom, cTo, word
1737 FROM x3 CROSS JOIN x3_rules
1738 WHERE word MATCH 'a' AND cost=distance AND ruleset=2
1739 ORDER BY +cTo DESC
1740 } {a z z a y y a x x}
1741
1742 do_execsql_test 8.2.3 {
1743 SELECT cFrom, cTo, word
1744 FROM x3_rules, x3
1745 WHERE word MATCH 'a' AND cost=distance AND ruleset=2
1746 ORDER BY +cTo DESC;
1747 } {a z z a y y a x x}
1748
1749 do_execsql_test 8.2.4 {
1750 SELECT cFrom, cTo, word
1751 FROM x3, x3_rules
1752 WHERE word MATCH 'a' AND cost=distance AND ruleset=2
1753 ORDER BY +cTo DESC;
1754 } {a z z a y y a x x}
1755
1756 do_execsql_test 8.2.5 {
1757 CREATE INDEX i1 ON x3_rules(cost);
1758 SELECT cFrom, cTo, word
1759 FROM x3_rules, x3
1760 WHERE word MATCH 'a' AND cost=distance AND ruleset=2
1761 ORDER BY +cTo DESC;
1762 } {a z z a y y a x x}
1763
1764 do_execsql_test 8.2.5 {
1765 SELECT word FROM x3_rules, x3 WHERE word MATCH x3_rules.cFrom AND ruleset=2
1766 } {a z y x a z y x a z y x}
1767
1768 do_execsql_test 8.2.6 {
1769 SELECT word FROM x3_rules, x3
1770 WHERE word MATCH x3_rules.cFrom
1771 AND ruleset=2
1772 AND x3_rules.cost=8;
1773 } {a z y x}
1774
1775 do_execsql_test 8.2.7 {
1776 CREATE TABLE t1(a, b);
1777 CREATE INDEX i2 ON t1(b);
1778 SELECT word, distance FROM x3, t1
1779 WHERE x3.word MATCH t1.a AND ruleset=2 AND distance=t1.b;
1780 } {}
1781
1782 do_execsql_test 8.2.8 {
1783 INSERT INTO x3_rules VALUES(1, 'a', 't', 5);
1784 INSERT INTO x3_rules VALUES(1, 'a', 'u', 4);
1785 INSERT INTO x3_rules VALUES(1, 'a', 'v', 3);
1786 DROP TABLE x3;
1787 CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules);
1788 SELECT * FROM x3_rules;
1789 } {
1790 2 a x 10
1791 2 a y 9
1792 2 a z 8
1793 1 a t 5
1794 1 a u 4
1795 1 a v 3
1796 }
1797
1798 do_catchsql_test 8.2.9 {
1799 SELECT word FROM x3 WHERE ruleset=2 AND word MATCH 'a' AND WORD MATCH 'b';
1800 } {1 {unable to use function MATCH in the requested context}}
1801
1802 do_execsql_test 8.2.10 {
1803 SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a'
1804 } {a v u t}
1805
1806 # The term "ruleset<=1" is not handled by the fuzzer module. Instead, it
1807 # is handled by SQLite, which assumes that all rows have a NULL value in
1808 # the ruleset column. Since NULL<=1 is never true, this query returns
1809 # no rows.
1810 do_execsql_test 8.2.11 {
1811 SELECT word FROM x3 WHERE ruleset<=1 AND word MATCH 'a'
1812 } {}
1813
1814 do_execsql_test 8.2.12 {
1815 SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance ASC;
1816 } {a v u t}
1817
1818 do_execsql_test 8.2.13 {
1819 SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance DESC;
1820 } {t u v a}
1821
1822 do_execsql_test 8.2.13 {
1823 SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word ASC;
1824 } {a t u v}
1825
1826 do_execsql_test 8.2.14 {
1827 SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word DESC;
1828 } {v u t a}
1829
1830 #-------------------------------------------------------------------------
1831 #
1832 do_execsql_test 9.1 {
1833 CREATE TABLE x4_rules(a, b, c, d);
1834 INSERT INTO x4_rules VALUES(0, 'a', 'b', 10);
1835 INSERT INTO x4_rules VALUES(0, 'a', 'c', 11);
1836 INSERT INTO x4_rules VALUES(0, 'bx', 'zz', 20);
1837 INSERT INTO x4_rules VALUES(0, 'cx', 'yy', 15);
1838 INSERT INTO x4_rules VALUES(0, 'zz', '!!', 50);
1839 CREATE VIRTUAL TABLE x4 USING fuzzer(x4_rules);
1840 }
1841
1842 do_execsql_test 9.2 {
1843 SELECT word, distance FROM x4 WHERE word MATCH 'ax';
1844 } {ax 0 bx 10 cx 11 yy 26 zz 30 !! 80}
1845
1846
1847 do_execsql_test 10.1 {
1848 CREATE TABLE x5_rules(a, b, c, d);
1849 CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules);
1850 }
1851
1852 do_execsql_test 10.2 {
1853 SELECT word, distance FROM x5 WHERE word MATCH
1854 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' ||
1855 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' ||
1856 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa'
1857 } {}
1858
1859 do_execsql_test 10.3 {
1860 INSERT INTO x5_rules VALUES(0, 'a', '0.1.2.3.4.5.6.7.8.9.a', 1);
1861 DROP TABLE x5;
1862 CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules);
1863 SELECT length(word) FROM x5 WHERE word MATCH 'a' LIMIT 50;
1864 } {1 21 41 61 81}
1381 1865
1382 finish_test 1866 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/fuzz_malloc.test ('k') | third_party/sqlite/src/test/fuzzerfault.test » ('j') | no next file with comments »

Powered by Google App Engine