2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-08-10 09:19:57 -07:00
|
|
|
|
|
|
|
// This file tests the unicode functions that we have added
|
|
|
|
|
|
|
|
const LATIN1_AE = "\xc6"; // "Æ"
|
|
|
|
const LATIN1_ae = "\xe6"; // "æ"
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
{
|
|
|
|
getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT");
|
|
|
|
|
|
|
|
var stmt = createStatement("INSERT INTO test (name, id) VALUES (?1, ?2)");
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_AE);
|
|
|
|
stmt.bindByIndex(1, 1);
|
2007-08-10 09:19:57 -07:00
|
|
|
stmt.execute();
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, "A");
|
|
|
|
stmt.bindByIndex(1, 2);
|
2007-08-10 09:19:57 -07:00
|
|
|
stmt.execute();
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, "b");
|
|
|
|
stmt.bindByIndex(1, 3);
|
2007-08-10 09:19:57 -07:00
|
|
|
stmt.execute();
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_ae);
|
|
|
|
stmt.bindByIndex(1, 4);
|
2007-08-10 09:19:57 -07:00
|
|
|
stmt.execute();
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_upper_ascii()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT name, id FROM test WHERE name = upper('a')");
|
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq("A", stmt.getString(0));
|
|
|
|
do_check_eq(2, stmt.getInt32(1));
|
|
|
|
stmt.reset();
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_upper_non_ascii()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT name, id FROM test WHERE name = upper(?1)");
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_ae);
|
2007-08-10 09:19:57 -07:00
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq(LATIN1_AE, stmt.getString(0));
|
|
|
|
do_check_eq(1, stmt.getInt32(1));
|
|
|
|
stmt.reset();
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_lower_ascii()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT name, id FROM test WHERE name = lower('B')");
|
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq("b", stmt.getString(0));
|
|
|
|
do_check_eq(3, stmt.getInt32(1));
|
|
|
|
stmt.reset();
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_lower_non_ascii()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT name, id FROM test WHERE name = lower(?1)");
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_AE);
|
2007-08-10 09:19:57 -07:00
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq(LATIN1_ae, stmt.getString(0));
|
|
|
|
do_check_eq(4, stmt.getInt32(1));
|
|
|
|
stmt.reset();
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_like_search_different()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1");
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_AE);
|
2007-08-10 09:19:57 -07:00
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq(2, stmt.getInt32(0));
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_like_search_same()
|
|
|
|
{
|
|
|
|
var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1");
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, LATIN1_ae);
|
2007-08-10 09:19:57 -07:00
|
|
|
do_check_true(stmt.executeStep());
|
|
|
|
do_check_eq(2, stmt.getInt32(0));
|
2007-09-18 20:26:51 -07:00
|
|
|
stmt.finalize();
|
2007-08-10 09:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var tests = [test_upper_ascii, test_upper_non_ascii, test_lower_ascii,
|
|
|
|
test_lower_non_ascii, test_like_search_different,
|
|
|
|
test_like_search_same];
|
|
|
|
|
|
|
|
function run_test()
|
|
|
|
{
|
|
|
|
setup();
|
|
|
|
|
|
|
|
for (var i = 0; i < tests.length; i++)
|
|
|
|
tests[i]();
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|