michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This file tests support for the fts3 (full-text index) module. michael@0: michael@0: // Example statements in these tests are taken from the Full Text Index page michael@0: // on the SQLite wiki: http://www.sqlite.org/cvstrac/wiki?p=FullTextIndex michael@0: michael@0: function test_table_creation() michael@0: { michael@0: var msc = getOpenedUnsharedDatabase(); michael@0: michael@0: msc.executeSimpleSQL( michael@0: "CREATE VIRTUAL TABLE recipe USING fts3(name, ingredients)"); michael@0: michael@0: do_check_true(msc.tableExists("recipe")); michael@0: } michael@0: michael@0: function test_insertion() michael@0: { michael@0: var msc = getOpenedUnsharedDatabase(); michael@0: michael@0: msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + michael@0: "('broccoli stew', 'broccoli peppers cheese tomatoes')"); michael@0: msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + michael@0: "('pumpkin stew', 'pumpkin onions garlic celery')"); michael@0: msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + michael@0: "('broccoli pie', 'broccoli cheese onions flour')"); michael@0: msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + michael@0: "('pumpkin pie', 'pumpkin sugar flour butter')"); michael@0: michael@0: var stmt = msc.createStatement("SELECT COUNT(*) FROM recipe"); michael@0: stmt.executeStep(); michael@0: michael@0: do_check_eq(stmt.getInt32(0), 4); michael@0: michael@0: stmt.reset(); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function test_selection() michael@0: { michael@0: var msc = getOpenedUnsharedDatabase(); michael@0: michael@0: var stmt = msc.createStatement( michael@0: "SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'"); michael@0: michael@0: do_check_true(stmt.executeStep()); michael@0: do_check_eq(stmt.getInt32(0), 3); michael@0: do_check_eq(stmt.getString(1), "broccoli pie"); michael@0: do_check_eq(stmt.getString(2), "broccoli cheese onions flour"); michael@0: michael@0: do_check_true(stmt.executeStep()); michael@0: do_check_eq(stmt.getInt32(0), 4); michael@0: do_check_eq(stmt.getString(1), "pumpkin pie"); michael@0: do_check_eq(stmt.getString(2), "pumpkin sugar flour butter"); michael@0: michael@0: do_check_false(stmt.executeStep()); michael@0: michael@0: stmt.reset(); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: var tests = [test_table_creation, test_insertion, test_selection]; michael@0: michael@0: function run_test() michael@0: { michael@0: // It's extra important to start from scratch, since these tests won't work michael@0: // with an existing shared cache connection, so we do it even though the last michael@0: // test probably did it already. michael@0: cleanup(); michael@0: michael@0: try { michael@0: for (var i = 0; i < tests.length; i++) { michael@0: tests[i](); michael@0: } michael@0: } michael@0: // It's extra important to clean up afterwards, since later tests that use michael@0: // a shared cache connection will not be able to read the database we create, michael@0: // so we do this in a finally block to ensure it happens even if some of our michael@0: // tests fail. michael@0: finally { michael@0: cleanup(); michael@0: } michael@0: }