Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ca4a171 authored by Bjorn Bringert's avatar Bjorn Bringert Committed by The Android Open Source Project
Browse files

am 5615d35b: Add tests for the new SQLite _TOKENIZE() \'tag\' column.

Merge commit '5615d35b'

* commit '5615d35b':
  Add tests for the new SQLite _TOKENIZE() 'tag' column.
parents 0aa1fbae 5615d35b
Loading
Loading
Loading
Loading
+33 −5
Original line number Original line Diff line number Diff line
@@ -510,7 +510,8 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
        mDatabase.execSQL("CREATE TABLE tokens (" +
        mDatabase.execSQL("CREATE TABLE tokens (" +
                "token TEXT COLLATE unicode," +
                "token TEXT COLLATE unicode," +
                "source INTEGER," +
                "source INTEGER," +
                "token_index INTEGER" +
                "token_index INTEGER," +
                "tag TEXT" +
                ");");
                ");");
        mDatabase.execSQL("CREATE TABLE tokens_no_index (" +
        mDatabase.execSQL("CREATE TABLE tokens_no_index (" +
                "token TEXT COLLATE unicode," +
                "token TEXT COLLATE unicode," +
@@ -527,7 +528,9 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
                "SELECT _TOKENIZE('tokens', 10, 'some string', NULL)", null));
                "SELECT _TOKENIZE('tokens', 10, 'some string', NULL)", null));
     
     
        Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase, 
        Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase, 
                "SELECT _TOKENIZE('tokens', 11, 'some string ok', ' ', 1)", null));
                "SELECT _TOKENIZE('tokens', 11, 'some string ok', ' ', 1, 'foo')", null));
        Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase,
                "SELECT _TOKENIZE('tokens', 11, 'second field', ' ', 1, 'bar')", null));


        Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase,
        Assert.assertEquals(3, DatabaseUtils.longForQuery(mDatabase,
                "SELECT _TOKENIZE('tokens_no_index', 20, 'some string ok', ' ')", null));
                "SELECT _TOKENIZE('tokens_no_index', 20, 'some string ok', ' ')", null));
@@ -544,7 +547,7 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
        Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase, 
        Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase, 
                "SELECT _TOKENIZE('tokens', 13, '" + icustr + "', ' ', 1)", null));
                "SELECT _TOKENIZE('tokens', 13, '" + icustr + "', ' ', 1)", null));
        
        
        Assert.assertEquals(7, DatabaseUtils.longForQuery(mDatabase, 
        Assert.assertEquals(9, DatabaseUtils.longForQuery(mDatabase,
                "SELECT count(*) from tokens;", null));      
                "SELECT count(*) from tokens;", null));      


        String key = DatabaseUtils.getHexCollationKey("Frederic Hjonneva");
        String key = DatabaseUtils.getHexCollationKey("Frederic Hjonneva");
@@ -569,6 +572,8 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase,
        Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase,
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals("foo", DatabaseUtils.stringForQuery(mDatabase,
                "SELECT tag from tokens where token GLOB '" + key + "*'", null));
        key = DatabaseUtils.getHexCollationKey("string");
        key = DatabaseUtils.getHexCollationKey("string");
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, 
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, 
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
@@ -576,6 +581,8 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase,
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase,
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals("foo", DatabaseUtils.stringForQuery(mDatabase,
                "SELECT tag from tokens where token GLOB '" + key + "*'", null));
        key = DatabaseUtils.getHexCollationKey("ok");
        key = DatabaseUtils.getHexCollationKey("ok");
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, 
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase, 
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
@@ -583,6 +590,27 @@ public class DatabaseGeneralTest extends TestCase implements PerformanceTestCase
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase,
        Assert.assertEquals(2, DatabaseUtils.longForQuery(mDatabase,
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals("foo", DatabaseUtils.stringForQuery(mDatabase,
                "SELECT tag from tokens where token GLOB '" + key + "*'", null));

        key = DatabaseUtils.getHexCollationKey("second field");
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase,
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(11, DatabaseUtils.longForQuery(mDatabase,
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(0, DatabaseUtils.longForQuery(mDatabase,
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals("bar", DatabaseUtils.stringForQuery(mDatabase,
                "SELECT tag from tokens where token GLOB '" + key + "*'", null));
        key = DatabaseUtils.getHexCollationKey("field");
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase,
                "SELECT count(*) from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(11, DatabaseUtils.longForQuery(mDatabase,
                "SELECT source from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals(1, DatabaseUtils.longForQuery(mDatabase,
                "SELECT token_index from tokens where token GLOB '" + key + "*'", null));
        Assert.assertEquals("bar", DatabaseUtils.stringForQuery(mDatabase,
                "SELECT tag from tokens where token GLOB '" + key + "*'", null));


        key = DatabaseUtils.getHexCollationKey(chinese);
        key = DatabaseUtils.getHexCollationKey(chinese);
        String[] a = new String[1];
        String[] a = new String[1];