|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 // This file tests support for the fts3 (full-text index) module. |
|
6 |
|
7 // Example statements in these tests are taken from the Full Text Index page |
|
8 // on the SQLite wiki: http://www.sqlite.org/cvstrac/wiki?p=FullTextIndex |
|
9 |
|
10 function test_table_creation() |
|
11 { |
|
12 var msc = getOpenedUnsharedDatabase(); |
|
13 |
|
14 msc.executeSimpleSQL( |
|
15 "CREATE VIRTUAL TABLE recipe USING fts3(name, ingredients)"); |
|
16 |
|
17 do_check_true(msc.tableExists("recipe")); |
|
18 } |
|
19 |
|
20 function test_insertion() |
|
21 { |
|
22 var msc = getOpenedUnsharedDatabase(); |
|
23 |
|
24 msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + |
|
25 "('broccoli stew', 'broccoli peppers cheese tomatoes')"); |
|
26 msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + |
|
27 "('pumpkin stew', 'pumpkin onions garlic celery')"); |
|
28 msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + |
|
29 "('broccoli pie', 'broccoli cheese onions flour')"); |
|
30 msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + |
|
31 "('pumpkin pie', 'pumpkin sugar flour butter')"); |
|
32 |
|
33 var stmt = msc.createStatement("SELECT COUNT(*) FROM recipe"); |
|
34 stmt.executeStep(); |
|
35 |
|
36 do_check_eq(stmt.getInt32(0), 4); |
|
37 |
|
38 stmt.reset(); |
|
39 stmt.finalize(); |
|
40 } |
|
41 |
|
42 function test_selection() |
|
43 { |
|
44 var msc = getOpenedUnsharedDatabase(); |
|
45 |
|
46 var stmt = msc.createStatement( |
|
47 "SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'"); |
|
48 |
|
49 do_check_true(stmt.executeStep()); |
|
50 do_check_eq(stmt.getInt32(0), 3); |
|
51 do_check_eq(stmt.getString(1), "broccoli pie"); |
|
52 do_check_eq(stmt.getString(2), "broccoli cheese onions flour"); |
|
53 |
|
54 do_check_true(stmt.executeStep()); |
|
55 do_check_eq(stmt.getInt32(0), 4); |
|
56 do_check_eq(stmt.getString(1), "pumpkin pie"); |
|
57 do_check_eq(stmt.getString(2), "pumpkin sugar flour butter"); |
|
58 |
|
59 do_check_false(stmt.executeStep()); |
|
60 |
|
61 stmt.reset(); |
|
62 stmt.finalize(); |
|
63 } |
|
64 |
|
65 var tests = [test_table_creation, test_insertion, test_selection]; |
|
66 |
|
67 function run_test() |
|
68 { |
|
69 // It's extra important to start from scratch, since these tests won't work |
|
70 // with an existing shared cache connection, so we do it even though the last |
|
71 // test probably did it already. |
|
72 cleanup(); |
|
73 |
|
74 try { |
|
75 for (var i = 0; i < tests.length; i++) { |
|
76 tests[i](); |
|
77 } |
|
78 } |
|
79 // It's extra important to clean up afterwards, since later tests that use |
|
80 // a shared cache connection will not be able to read the database we create, |
|
81 // so we do this in a finally block to ensure it happens even if some of our |
|
82 // tests fail. |
|
83 finally { |
|
84 cleanup(); |
|
85 } |
|
86 } |