|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set sw=2 ts=2 sts=2 et : */ |
|
3 /** |
|
4 * Any copyright is dedicated to the Public Domain. |
|
5 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
6 */ |
|
7 |
|
8 /** |
|
9 * This file tests that the JS language helpers in various ways. |
|
10 */ |
|
11 |
|
12 //////////////////////////////////////////////////////////////////////////////// |
|
13 //// Test Functions |
|
14 |
|
15 function test_params_enumerate() |
|
16 { |
|
17 let stmt = createStatement( |
|
18 "SELECT * FROM test WHERE id IN (:a, :b, :c)" |
|
19 ); |
|
20 |
|
21 // Make sure they are right. |
|
22 let expected = ["a", "b", "c"]; |
|
23 let index = 0; |
|
24 for (let name in stmt.params) |
|
25 do_check_eq(name, expected[index++]); |
|
26 } |
|
27 |
|
28 function test_params_prototype() |
|
29 { |
|
30 let stmt = createStatement( |
|
31 "SELECT * FROM sqlite_master" |
|
32 ); |
|
33 |
|
34 // Set a property on the prototype and make sure it exist (will not be a |
|
35 // bindable parameter, however). |
|
36 Object.getPrototypeOf(stmt.params).test = 2; |
|
37 do_check_eq(stmt.params.test, 2); |
|
38 stmt.finalize(); |
|
39 } |
|
40 |
|
41 function test_row_prototype() |
|
42 { |
|
43 let stmt = createStatement( |
|
44 "SELECT * FROM sqlite_master" |
|
45 ); |
|
46 |
|
47 do_check_true(stmt.executeStep()); |
|
48 |
|
49 // Set a property on the prototype and make sure it exists (will not be in the |
|
50 // results, however). |
|
51 Object.getPrototypeOf(stmt.row).test = 2; |
|
52 do_check_eq(stmt.row.test, 2); |
|
53 |
|
54 // Clean up after ourselves. |
|
55 delete Object.getPrototypeOf(stmt.row).test; |
|
56 stmt.finalize(); |
|
57 } |
|
58 |
|
59 function test_params_gets_sync() |
|
60 { |
|
61 // Added for bug 562866. |
|
62 /* |
|
63 let stmt = createStatement( |
|
64 "SELECT * FROM test WHERE id IN (:a, :b, :c)" |
|
65 ); |
|
66 |
|
67 // Make sure we do not assert in getting the value. |
|
68 let originalCount = Object.getOwnPropertyNames(stmt.params).length; |
|
69 let expected = ["a", "b", "c"]; |
|
70 for each (let name in expected) { |
|
71 stmt.params[name]; |
|
72 } |
|
73 |
|
74 // Now make sure we didn't magically get any additional properties. |
|
75 let finalCount = Object.getOwnPropertyNames(stmt.params).length; |
|
76 do_check_eq(originalCount + expected.length, finalCount); |
|
77 */ |
|
78 } |
|
79 |
|
80 function test_params_gets_async() |
|
81 { |
|
82 // Added for bug 562866. |
|
83 /* |
|
84 let stmt = createAsyncStatement( |
|
85 "SELECT * FROM test WHERE id IN (:a, :b, :c)" |
|
86 ); |
|
87 |
|
88 // Make sure we do not assert in getting the value. |
|
89 let originalCount = Object.getOwnPropertyNames(stmt.params).length; |
|
90 let expected = ["a", "b", "c"]; |
|
91 for each (let name in expected) { |
|
92 stmt.params[name]; |
|
93 } |
|
94 |
|
95 // Now make sure we didn't magically get any additional properties. |
|
96 let finalCount = Object.getOwnPropertyNames(stmt.params).length; |
|
97 do_check_eq(originalCount + expected.length, finalCount); |
|
98 */ |
|
99 } |
|
100 |
|
101 //////////////////////////////////////////////////////////////////////////////// |
|
102 //// Test Runner |
|
103 |
|
104 let tests = [ |
|
105 test_params_enumerate, |
|
106 test_params_prototype, |
|
107 test_row_prototype, |
|
108 test_params_gets_sync, |
|
109 test_params_gets_async, |
|
110 ]; |
|
111 function run_test() |
|
112 { |
|
113 cleanup(); |
|
114 |
|
115 // Create our database. |
|
116 getOpenedDatabase().executeSimpleSQL( |
|
117 "CREATE TABLE test (" + |
|
118 "id INTEGER PRIMARY KEY " + |
|
119 ")" |
|
120 ); |
|
121 |
|
122 // Run the tests. |
|
123 tests.forEach(function(test) test()); |
|
124 } |