1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.providers.contacts.database;
18
19import android.test.suitebuilder.annotation.SmallTest;
20
21import junit.framework.TestCase;
22
23/**
24 * Unit tests for MoreDatabaseutil.
25 */
26@SmallTest
27public class MoreDatabaseUtilTest extends TestCase {
28
29    public void testBuildBindArgString() {
30        assertEquals("?", MoreDatabaseUtils.buildBindArgString(1));
31        assertEquals("?,?", MoreDatabaseUtils.buildBindArgString(2));
32        assertEquals("?,?,?", MoreDatabaseUtils.buildBindArgString(3));
33        assertEquals("?,?,?,?", MoreDatabaseUtils.buildBindArgString(4));
34    }
35
36    public void testBuildIndex() {
37        String expected = "create index testtable_testfield_index on testtable(testfield)";
38        String actual = MoreDatabaseUtils.buildCreateIndexSql("testtable", "testfield")
39                .toLowerCase();
40        assertEquals(expected, actual);
41
42        expected = "create index test_table_test_field_index on test_table(test_field)";
43        actual = MoreDatabaseUtils.buildCreateIndexSql("test_table", "test_field").toLowerCase();
44        assertEquals(expected, actual);
45    }
46
47    public void testDropIndex() {
48        String expected = "drop index if exists testtable_testfield_index";
49        String actual = MoreDatabaseUtils.buildDropIndexSql("testtable", "testfield").toLowerCase();
50        assertEquals(expected, actual);
51    }
52
53    public void testBuildIndexName() {
54        assertEquals("testtable_testfield_index",
55                MoreDatabaseUtils.buildIndexName("testtable", "testfield"));
56    }
57}
58