1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/test/unit/test_unicode.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 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 the unicode functions that we have added 1.9 + 1.10 +const LATIN1_AE = "\xc6"; // "Æ" 1.11 +const LATIN1_ae = "\xe6"; // "æ" 1.12 + 1.13 +function setup() 1.14 +{ 1.15 + getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT"); 1.16 + 1.17 + var stmt = createStatement("INSERT INTO test (name, id) VALUES (?1, ?2)"); 1.18 + stmt.bindByIndex(0, LATIN1_AE); 1.19 + stmt.bindByIndex(1, 1); 1.20 + stmt.execute(); 1.21 + stmt.bindByIndex(0, "A"); 1.22 + stmt.bindByIndex(1, 2); 1.23 + stmt.execute(); 1.24 + stmt.bindByIndex(0, "b"); 1.25 + stmt.bindByIndex(1, 3); 1.26 + stmt.execute(); 1.27 + stmt.bindByIndex(0, LATIN1_ae); 1.28 + stmt.bindByIndex(1, 4); 1.29 + stmt.execute(); 1.30 + stmt.finalize(); 1.31 +} 1.32 + 1.33 +function test_upper_ascii() 1.34 +{ 1.35 + var stmt = createStatement("SELECT name, id FROM test WHERE name = upper('a')"); 1.36 + do_check_true(stmt.executeStep()); 1.37 + do_check_eq("A", stmt.getString(0)); 1.38 + do_check_eq(2, stmt.getInt32(1)); 1.39 + stmt.reset(); 1.40 + stmt.finalize(); 1.41 +} 1.42 + 1.43 +function test_upper_non_ascii() 1.44 +{ 1.45 + var stmt = createStatement("SELECT name, id FROM test WHERE name = upper(?1)"); 1.46 + stmt.bindByIndex(0, LATIN1_ae); 1.47 + do_check_true(stmt.executeStep()); 1.48 + do_check_eq(LATIN1_AE, stmt.getString(0)); 1.49 + do_check_eq(1, stmt.getInt32(1)); 1.50 + stmt.reset(); 1.51 + stmt.finalize(); 1.52 +} 1.53 + 1.54 +function test_lower_ascii() 1.55 +{ 1.56 + var stmt = createStatement("SELECT name, id FROM test WHERE name = lower('B')"); 1.57 + do_check_true(stmt.executeStep()); 1.58 + do_check_eq("b", stmt.getString(0)); 1.59 + do_check_eq(3, stmt.getInt32(1)); 1.60 + stmt.reset(); 1.61 + stmt.finalize(); 1.62 +} 1.63 + 1.64 +function test_lower_non_ascii() 1.65 +{ 1.66 + var stmt = createStatement("SELECT name, id FROM test WHERE name = lower(?1)"); 1.67 + stmt.bindByIndex(0, LATIN1_AE); 1.68 + do_check_true(stmt.executeStep()); 1.69 + do_check_eq(LATIN1_ae, stmt.getString(0)); 1.70 + do_check_eq(4, stmt.getInt32(1)); 1.71 + stmt.reset(); 1.72 + stmt.finalize(); 1.73 +} 1.74 + 1.75 +function test_like_search_different() 1.76 +{ 1.77 + var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); 1.78 + stmt.bindByIndex(0, LATIN1_AE); 1.79 + do_check_true(stmt.executeStep()); 1.80 + do_check_eq(2, stmt.getInt32(0)); 1.81 + stmt.finalize(); 1.82 +} 1.83 + 1.84 +function test_like_search_same() 1.85 +{ 1.86 + var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); 1.87 + stmt.bindByIndex(0, LATIN1_ae); 1.88 + do_check_true(stmt.executeStep()); 1.89 + do_check_eq(2, stmt.getInt32(0)); 1.90 + stmt.finalize(); 1.91 +} 1.92 + 1.93 +var tests = [test_upper_ascii, test_upper_non_ascii, test_lower_ascii, 1.94 + test_lower_non_ascii, test_like_search_different, 1.95 + test_like_search_same]; 1.96 + 1.97 +function run_test() 1.98 +{ 1.99 + setup(); 1.100 + 1.101 + for (var i = 0; i < tests.length; i++) 1.102 + tests[i](); 1.103 + 1.104 + cleanup(); 1.105 +} 1.106 +