blob: 7c206d7eecf73e717a7344076b6ba4b34036084a [file] [log] [blame]
Jeff Sharkey0da04832018-07-26 14:36:59 -06001/*
2 * Copyright (C) 2018 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 android.database;
18
19import static android.database.DatabaseUtils.bindSelection;
20
21import static org.junit.Assert.assertEquals;
22
23import android.support.test.runner.AndroidJUnit4;
24
25import org.junit.Test;
26import org.junit.runner.RunWith;
27
28@RunWith(AndroidJUnit4.class)
29public class DatabaseUtilsTest {
30 private static final Object[] ARGS = { "baz", 4, null };
31
32 @Test
33 public void testBindSelection_none() throws Exception {
34 assertEquals(null,
35 bindSelection(null, ARGS));
36 assertEquals("",
37 bindSelection("", ARGS));
38 assertEquals("foo=bar",
39 bindSelection("foo=bar", ARGS));
40 }
41
42 @Test
43 public void testBindSelection_normal() throws Exception {
44 assertEquals("foo='baz'",
45 bindSelection("foo=?", ARGS));
46 assertEquals("foo='baz' AND bar=4",
47 bindSelection("foo=? AND bar=?", ARGS));
48 assertEquals("foo='baz' AND bar=4 AND meow=NULL",
49 bindSelection("foo=? AND bar=? AND meow=?", ARGS));
50 }
51
52 @Test
53 public void testBindSelection_whitespace() throws Exception {
54 assertEquals("BETWEEN 5 AND 10",
55 bindSelection("BETWEEN? AND ?", 5, 10));
56 assertEquals("IN 'foo'",
57 bindSelection("IN?", "foo"));
58 }
59
60 @Test
61 public void testBindSelection_indexed() throws Exception {
62 assertEquals("foo=10 AND bar=11 AND meow=1",
63 bindSelection("foo=?10 AND bar=? AND meow=?1",
64 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12));
65 }
66}