storage/test/unit/test_unicode.js

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:a9e2f8c45fce
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // This file tests the unicode functions that we have added
6
7 const LATIN1_AE = "\xc6"; // "Æ"
8 const LATIN1_ae = "\xe6"; // "æ"
9
10 function setup()
11 {
12 getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT");
13
14 var stmt = createStatement("INSERT INTO test (name, id) VALUES (?1, ?2)");
15 stmt.bindByIndex(0, LATIN1_AE);
16 stmt.bindByIndex(1, 1);
17 stmt.execute();
18 stmt.bindByIndex(0, "A");
19 stmt.bindByIndex(1, 2);
20 stmt.execute();
21 stmt.bindByIndex(0, "b");
22 stmt.bindByIndex(1, 3);
23 stmt.execute();
24 stmt.bindByIndex(0, LATIN1_ae);
25 stmt.bindByIndex(1, 4);
26 stmt.execute();
27 stmt.finalize();
28 }
29
30 function test_upper_ascii()
31 {
32 var stmt = createStatement("SELECT name, id FROM test WHERE name = upper('a')");
33 do_check_true(stmt.executeStep());
34 do_check_eq("A", stmt.getString(0));
35 do_check_eq(2, stmt.getInt32(1));
36 stmt.reset();
37 stmt.finalize();
38 }
39
40 function test_upper_non_ascii()
41 {
42 var stmt = createStatement("SELECT name, id FROM test WHERE name = upper(?1)");
43 stmt.bindByIndex(0, LATIN1_ae);
44 do_check_true(stmt.executeStep());
45 do_check_eq(LATIN1_AE, stmt.getString(0));
46 do_check_eq(1, stmt.getInt32(1));
47 stmt.reset();
48 stmt.finalize();
49 }
50
51 function test_lower_ascii()
52 {
53 var stmt = createStatement("SELECT name, id FROM test WHERE name = lower('B')");
54 do_check_true(stmt.executeStep());
55 do_check_eq("b", stmt.getString(0));
56 do_check_eq(3, stmt.getInt32(1));
57 stmt.reset();
58 stmt.finalize();
59 }
60
61 function test_lower_non_ascii()
62 {
63 var stmt = createStatement("SELECT name, id FROM test WHERE name = lower(?1)");
64 stmt.bindByIndex(0, LATIN1_AE);
65 do_check_true(stmt.executeStep());
66 do_check_eq(LATIN1_ae, stmt.getString(0));
67 do_check_eq(4, stmt.getInt32(1));
68 stmt.reset();
69 stmt.finalize();
70 }
71
72 function test_like_search_different()
73 {
74 var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1");
75 stmt.bindByIndex(0, LATIN1_AE);
76 do_check_true(stmt.executeStep());
77 do_check_eq(2, stmt.getInt32(0));
78 stmt.finalize();
79 }
80
81 function test_like_search_same()
82 {
83 var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1");
84 stmt.bindByIndex(0, LATIN1_ae);
85 do_check_true(stmt.executeStep());
86 do_check_eq(2, stmt.getInt32(0));
87 stmt.finalize();
88 }
89
90 var tests = [test_upper_ascii, test_upper_non_ascii, test_lower_ascii,
91 test_lower_non_ascii, test_like_search_different,
92 test_like_search_same];
93
94 function run_test()
95 {
96 setup();
97
98 for (var i = 0; i < tests.length; i++)
99 tests[i]();
100
101 cleanup();
102 }
103

mercurial