1 /* 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 17 package android.database; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertTrue; 22 23 import android.content.Context; 24 import android.net.Uri; 25 26 import androidx.test.InstrumentationRegistry; 27 import androidx.test.runner.AndroidJUnit4; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 @RunWith(AndroidJUnit4.class) 33 public class RedactingCursorTest { getContext()34 private Context getContext() { 35 return InstrumentationRegistry.getContext(); 36 } 37 38 @Test testMissing()39 public void testMissing() throws Exception { 40 final Cursor redacting = getContext().getContentResolver().query( 41 Uri.parse("content://android.content.RedactingProvider/missing"), null, null, null); 42 43 redacting.moveToNext(); 44 assertEquals("foo", redacting.getString(0)); 45 assertEquals(10, redacting.getInt(1)); 46 assertEquals("/path/to/foo", redacting.getString(2)); 47 redacting.moveToNext(); 48 assertEquals("bar", redacting.getString(0)); 49 assertEquals(20, redacting.getInt(1)); 50 assertEquals("/path/to/bar", redacting.getString(2)); 51 } 52 53 @Test testSingle()54 public void testSingle() throws Exception { 55 final Cursor redacting = getContext().getContentResolver().query( 56 Uri.parse("content://android.content.RedactingProvider/single"), null, null, null); 57 58 redacting.moveToNext(); 59 assertEquals(null, redacting.getString(0)); 60 assertEquals(10, redacting.getInt(1)); 61 assertEquals("/dev/null", redacting.getString(2)); 62 assertEquals(Cursor.FIELD_TYPE_NULL, redacting.getType(0)); 63 assertEquals(Cursor.FIELD_TYPE_INTEGER, redacting.getType(1)); 64 assertEquals(Cursor.FIELD_TYPE_STRING, redacting.getType(2)); 65 assertTrue(redacting.isNull(0)); 66 assertFalse(redacting.isNull(1)); 67 assertFalse(redacting.isNull(2)); 68 69 redacting.moveToNext(); 70 assertEquals(null, redacting.getString(0)); 71 assertEquals(20, redacting.getInt(1)); 72 assertEquals("/dev/null", redacting.getString(2)); 73 } 74 75 @Test testMultiple()76 public void testMultiple() throws Exception { 77 final Cursor redacting = getContext().getContentResolver().query( 78 Uri.parse("content://android.content.RedactingProvider/multiple"), 79 null, null, null); 80 81 redacting.moveToNext(); 82 assertEquals(null, redacting.getString(0)); 83 assertEquals("foo", redacting.getString(1)); 84 assertEquals(null, redacting.getString(2)); 85 } 86 } 87