Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // This file tests our LIKE implementation since we override it for unicode |
michael@0 | 6 | |
michael@0 | 7 | function setup() |
michael@0 | 8 | { |
michael@0 | 9 | getOpenedDatabase().createTable("t1", "x TEXT"); |
michael@0 | 10 | |
michael@0 | 11 | var stmt = createStatement("INSERT INTO t1 (x) VALUES ('a')"); |
michael@0 | 12 | stmt.execute(); |
michael@0 | 13 | stmt.finalize(); |
michael@0 | 14 | |
michael@0 | 15 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('ab')"); |
michael@0 | 16 | stmt.execute(); |
michael@0 | 17 | stmt.finalize(); |
michael@0 | 18 | |
michael@0 | 19 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('abc')"); |
michael@0 | 20 | stmt.execute(); |
michael@0 | 21 | stmt.finalize(); |
michael@0 | 22 | |
michael@0 | 23 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('abcd')"); |
michael@0 | 24 | stmt.execute(); |
michael@0 | 25 | stmt.finalize(); |
michael@0 | 26 | |
michael@0 | 27 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('acd')"); |
michael@0 | 28 | stmt.execute(); |
michael@0 | 29 | stmt.finalize(); |
michael@0 | 30 | |
michael@0 | 31 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('abd')"); |
michael@0 | 32 | stmt.execute(); |
michael@0 | 33 | stmt.finalize(); |
michael@0 | 34 | |
michael@0 | 35 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('bc')"); |
michael@0 | 36 | stmt.execute(); |
michael@0 | 37 | stmt.finalize(); |
michael@0 | 38 | |
michael@0 | 39 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('bcd')"); |
michael@0 | 40 | stmt.execute(); |
michael@0 | 41 | stmt.finalize(); |
michael@0 | 42 | |
michael@0 | 43 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('xyz')"); |
michael@0 | 44 | stmt.execute(); |
michael@0 | 45 | stmt.finalize(); |
michael@0 | 46 | |
michael@0 | 47 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('ABC')"); |
michael@0 | 48 | stmt.execute(); |
michael@0 | 49 | stmt.finalize(); |
michael@0 | 50 | |
michael@0 | 51 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('CDE')"); |
michael@0 | 52 | stmt.execute(); |
michael@0 | 53 | stmt.finalize(); |
michael@0 | 54 | |
michael@0 | 55 | stmt = createStatement("INSERT INTO t1 (x) VALUES ('ABC abc xyz')"); |
michael@0 | 56 | stmt.execute(); |
michael@0 | 57 | stmt.finalize(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function test_count() |
michael@0 | 61 | { |
michael@0 | 62 | var stmt = createStatement("SELECT count(*) FROM t1;"); |
michael@0 | 63 | do_check_true(stmt.executeStep()); |
michael@0 | 64 | do_check_eq(stmt.getInt32(0), 12); |
michael@0 | 65 | stmt.reset(); |
michael@0 | 66 | stmt.finalize(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function test_like_1() |
michael@0 | 70 | { |
michael@0 | 71 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 72 | stmt.bindByIndex(0, 'abc'); |
michael@0 | 73 | var solutions = ["abc", "ABC"]; |
michael@0 | 74 | do_check_true(stmt.executeStep()); |
michael@0 | 75 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 76 | do_check_true(stmt.executeStep()); |
michael@0 | 77 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 78 | do_check_false(stmt.executeStep()); |
michael@0 | 79 | stmt.reset(); |
michael@0 | 80 | stmt.finalize(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function test_like_2() |
michael@0 | 84 | { |
michael@0 | 85 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 86 | stmt.bindByIndex(0, 'ABC'); |
michael@0 | 87 | var solutions = ["abc", "ABC"]; |
michael@0 | 88 | do_check_true(stmt.executeStep()); |
michael@0 | 89 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 90 | do_check_true(stmt.executeStep()); |
michael@0 | 91 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 92 | do_check_false(stmt.executeStep()); |
michael@0 | 93 | stmt.reset(); |
michael@0 | 94 | stmt.finalize(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | function test_like_3() |
michael@0 | 98 | { |
michael@0 | 99 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 100 | stmt.bindByIndex(0, 'aBc'); |
michael@0 | 101 | var solutions = ["abc", "ABC"]; |
michael@0 | 102 | do_check_true(stmt.executeStep()); |
michael@0 | 103 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 104 | do_check_true(stmt.executeStep()); |
michael@0 | 105 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 106 | do_check_false(stmt.executeStep()); |
michael@0 | 107 | stmt.reset(); |
michael@0 | 108 | stmt.finalize(); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function test_like_4() |
michael@0 | 112 | { |
michael@0 | 113 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 114 | stmt.bindByIndex(0, 'abc%'); |
michael@0 | 115 | var solutions = ["abc", "abcd", "ABC", "ABC abc xyz"]; |
michael@0 | 116 | do_check_true(stmt.executeStep()); |
michael@0 | 117 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 118 | do_check_true(stmt.executeStep()); |
michael@0 | 119 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 120 | do_check_true(stmt.executeStep()); |
michael@0 | 121 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 122 | do_check_true(stmt.executeStep()); |
michael@0 | 123 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 124 | do_check_false(stmt.executeStep()); |
michael@0 | 125 | stmt.reset(); |
michael@0 | 126 | stmt.finalize(); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function test_like_5() |
michael@0 | 130 | { |
michael@0 | 131 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 132 | stmt.bindByIndex(0, 'a_c'); |
michael@0 | 133 | var solutions = ["abc", "ABC"]; |
michael@0 | 134 | do_check_true(stmt.executeStep()); |
michael@0 | 135 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 136 | do_check_true(stmt.executeStep()); |
michael@0 | 137 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 138 | do_check_false(stmt.executeStep()); |
michael@0 | 139 | stmt.reset(); |
michael@0 | 140 | stmt.finalize(); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | function test_like_6() |
michael@0 | 144 | { |
michael@0 | 145 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 146 | stmt.bindByIndex(0, 'ab%d'); |
michael@0 | 147 | var solutions = ["abcd", "abd"]; |
michael@0 | 148 | do_check_true(stmt.executeStep()); |
michael@0 | 149 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 150 | do_check_true(stmt.executeStep()); |
michael@0 | 151 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 152 | do_check_false(stmt.executeStep()); |
michael@0 | 153 | stmt.reset(); |
michael@0 | 154 | stmt.finalize(); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | function test_like_7() |
michael@0 | 158 | { |
michael@0 | 159 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 160 | stmt.bindByIndex(0, 'a_c%'); |
michael@0 | 161 | var solutions = ["abc", "abcd", "ABC", "ABC abc xyz"]; |
michael@0 | 162 | do_check_true(stmt.executeStep()); |
michael@0 | 163 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 164 | do_check_true(stmt.executeStep()); |
michael@0 | 165 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 166 | do_check_true(stmt.executeStep()); |
michael@0 | 167 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 168 | do_check_true(stmt.executeStep()); |
michael@0 | 169 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 170 | do_check_false(stmt.executeStep()); |
michael@0 | 171 | stmt.reset(); |
michael@0 | 172 | stmt.finalize(); |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | function test_like_8() |
michael@0 | 176 | { |
michael@0 | 177 | var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?;"); |
michael@0 | 178 | stmt.bindByIndex(0, '%bcd'); |
michael@0 | 179 | var solutions = ["abcd", "bcd"]; |
michael@0 | 180 | do_check_true(stmt.executeStep()); |
michael@0 | 181 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 182 | do_check_true(stmt.executeStep()); |
michael@0 | 183 | do_check_true(solutions.indexOf(stmt.getString(0)) != -1); |
michael@0 | 184 | do_check_false(stmt.executeStep()); |
michael@0 | 185 | stmt.reset(); |
michael@0 | 186 | stmt.finalize(); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | var tests = [test_count, test_like_1, test_like_2, test_like_3, test_like_4, |
michael@0 | 190 | test_like_5, test_like_6, test_like_7, test_like_8]; |
michael@0 | 191 | |
michael@0 | 192 | function run_test() |
michael@0 | 193 | { |
michael@0 | 194 | setup(); |
michael@0 | 195 | |
michael@0 | 196 | for (var i = 0; i < tests.length; i++) |
michael@0 | 197 | tests[i](); |
michael@0 | 198 | |
michael@0 | 199 | cleanup(); |
michael@0 | 200 | } |
michael@0 | 201 |