1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/test/unit/test_storage_fulltextindex.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This file tests support for the fts3 (full-text index) module. 1.9 + 1.10 +// Example statements in these tests are taken from the Full Text Index page 1.11 +// on the SQLite wiki: http://www.sqlite.org/cvstrac/wiki?p=FullTextIndex 1.12 + 1.13 +function test_table_creation() 1.14 +{ 1.15 + var msc = getOpenedUnsharedDatabase(); 1.16 + 1.17 + msc.executeSimpleSQL( 1.18 + "CREATE VIRTUAL TABLE recipe USING fts3(name, ingredients)"); 1.19 + 1.20 + do_check_true(msc.tableExists("recipe")); 1.21 +} 1.22 + 1.23 +function test_insertion() 1.24 +{ 1.25 + var msc = getOpenedUnsharedDatabase(); 1.26 + 1.27 + msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + 1.28 + "('broccoli stew', 'broccoli peppers cheese tomatoes')"); 1.29 + msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + 1.30 + "('pumpkin stew', 'pumpkin onions garlic celery')"); 1.31 + msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + 1.32 + "('broccoli pie', 'broccoli cheese onions flour')"); 1.33 + msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " + 1.34 + "('pumpkin pie', 'pumpkin sugar flour butter')"); 1.35 + 1.36 + var stmt = msc.createStatement("SELECT COUNT(*) FROM recipe"); 1.37 + stmt.executeStep(); 1.38 + 1.39 + do_check_eq(stmt.getInt32(0), 4); 1.40 + 1.41 + stmt.reset(); 1.42 + stmt.finalize(); 1.43 +} 1.44 + 1.45 +function test_selection() 1.46 +{ 1.47 + var msc = getOpenedUnsharedDatabase(); 1.48 + 1.49 + var stmt = msc.createStatement( 1.50 + "SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'"); 1.51 + 1.52 + do_check_true(stmt.executeStep()); 1.53 + do_check_eq(stmt.getInt32(0), 3); 1.54 + do_check_eq(stmt.getString(1), "broccoli pie"); 1.55 + do_check_eq(stmt.getString(2), "broccoli cheese onions flour"); 1.56 + 1.57 + do_check_true(stmt.executeStep()); 1.58 + do_check_eq(stmt.getInt32(0), 4); 1.59 + do_check_eq(stmt.getString(1), "pumpkin pie"); 1.60 + do_check_eq(stmt.getString(2), "pumpkin sugar flour butter"); 1.61 + 1.62 + do_check_false(stmt.executeStep()); 1.63 + 1.64 + stmt.reset(); 1.65 + stmt.finalize(); 1.66 +} 1.67 + 1.68 +var tests = [test_table_creation, test_insertion, test_selection]; 1.69 + 1.70 +function run_test() 1.71 +{ 1.72 + // It's extra important to start from scratch, since these tests won't work 1.73 + // with an existing shared cache connection, so we do it even though the last 1.74 + // test probably did it already. 1.75 + cleanup(); 1.76 + 1.77 + try { 1.78 + for (var i = 0; i < tests.length; i++) { 1.79 + tests[i](); 1.80 + } 1.81 + } 1.82 + // It's extra important to clean up afterwards, since later tests that use 1.83 + // a shared cache connection will not be able to read the database we create, 1.84 + // so we do this in a finally block to ensure it happens even if some of our 1.85 + // tests fail. 1.86 + finally { 1.87 + cleanup(); 1.88 + } 1.89 +}