michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=2 sts=2 et : */ michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: /** michael@0: * This file tests that the JS language helpers in various ways. michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Test Functions michael@0: michael@0: function test_params_enumerate() michael@0: { michael@0: let stmt = createStatement( michael@0: "SELECT * FROM test WHERE id IN (:a, :b, :c)" michael@0: ); michael@0: michael@0: // Make sure they are right. michael@0: let expected = ["a", "b", "c"]; michael@0: let index = 0; michael@0: for (let name in stmt.params) michael@0: do_check_eq(name, expected[index++]); michael@0: } michael@0: michael@0: function test_params_prototype() michael@0: { michael@0: let stmt = createStatement( michael@0: "SELECT * FROM sqlite_master" michael@0: ); michael@0: michael@0: // Set a property on the prototype and make sure it exist (will not be a michael@0: // bindable parameter, however). michael@0: Object.getPrototypeOf(stmt.params).test = 2; michael@0: do_check_eq(stmt.params.test, 2); michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function test_row_prototype() michael@0: { michael@0: let stmt = createStatement( michael@0: "SELECT * FROM sqlite_master" michael@0: ); michael@0: michael@0: do_check_true(stmt.executeStep()); michael@0: michael@0: // Set a property on the prototype and make sure it exists (will not be in the michael@0: // results, however). michael@0: Object.getPrototypeOf(stmt.row).test = 2; michael@0: do_check_eq(stmt.row.test, 2); michael@0: michael@0: // Clean up after ourselves. michael@0: delete Object.getPrototypeOf(stmt.row).test; michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: function test_params_gets_sync() michael@0: { michael@0: // Added for bug 562866. michael@0: /* michael@0: let stmt = createStatement( michael@0: "SELECT * FROM test WHERE id IN (:a, :b, :c)" michael@0: ); michael@0: michael@0: // Make sure we do not assert in getting the value. michael@0: let originalCount = Object.getOwnPropertyNames(stmt.params).length; michael@0: let expected = ["a", "b", "c"]; michael@0: for each (let name in expected) { michael@0: stmt.params[name]; michael@0: } michael@0: michael@0: // Now make sure we didn't magically get any additional properties. michael@0: let finalCount = Object.getOwnPropertyNames(stmt.params).length; michael@0: do_check_eq(originalCount + expected.length, finalCount); michael@0: */ michael@0: } michael@0: michael@0: function test_params_gets_async() michael@0: { michael@0: // Added for bug 562866. michael@0: /* michael@0: let stmt = createAsyncStatement( michael@0: "SELECT * FROM test WHERE id IN (:a, :b, :c)" michael@0: ); michael@0: michael@0: // Make sure we do not assert in getting the value. michael@0: let originalCount = Object.getOwnPropertyNames(stmt.params).length; michael@0: let expected = ["a", "b", "c"]; michael@0: for each (let name in expected) { michael@0: stmt.params[name]; michael@0: } michael@0: michael@0: // Now make sure we didn't magically get any additional properties. michael@0: let finalCount = Object.getOwnPropertyNames(stmt.params).length; michael@0: do_check_eq(originalCount + expected.length, finalCount); michael@0: */ michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Test Runner michael@0: michael@0: let tests = [ michael@0: test_params_enumerate, michael@0: test_params_prototype, michael@0: test_row_prototype, michael@0: test_params_gets_sync, michael@0: test_params_gets_async, michael@0: ]; michael@0: function run_test() michael@0: { michael@0: cleanup(); michael@0: michael@0: // Create our database. michael@0: getOpenedDatabase().executeSimpleSQL( michael@0: "CREATE TABLE test (" + michael@0: "id INTEGER PRIMARY KEY " + michael@0: ")" michael@0: ); michael@0: michael@0: // Run the tests. michael@0: tests.forEach(function(test) test()); michael@0: }