1 /* 2 * Copyright (C) 2009 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.content.res.cts; 18 19 import android.content.res.Resources; 20 import android.test.AndroidTestCase; 21 import android.test.suitebuilder.annotation.SmallTest; 22 23 import android.content.cts.R; 24 25 public class ArrayTest extends AndroidTestCase { 26 private Resources mResources; 27 28 @Override 29 protected void setUp() throws Exception { 30 super.setUp(); 31 mResources = mContext.getResources(); 32 } 33 34 private void checkEntry(final int resid, final int index, final Object res, 35 final Object expected) { 36 assertEquals("in resource 0x" + Integer.toHexString(resid) 37 + " at index " + index, expected, res); 38 } 39 40 private void checkStringArray(final int resid, final String[] expected) { 41 final String[] res = mResources.getStringArray(resid); 42 assertEquals(res.length, expected.length); 43 for (int i = 0; i < expected.length; i++) { 44 checkEntry(resid, i, res[i], expected[i]); 45 } 46 } 47 48 private void checkTextArray(final int resid, final String[] expected) { 49 final CharSequence[] res = mResources.getTextArray(resid); 50 assertEquals(res.length, expected.length); 51 for (int i = 0; i < expected.length; i++) { 52 checkEntry(resid, i, res[i], expected[i]); 53 } 54 } 55 56 private void checkIntArray(final int resid, final int[] expected) { 57 final int[] res = mResources.getIntArray(resid); 58 assertEquals(res.length, expected.length); 59 for (int i = 0; i < expected.length; i++) { 60 assertEquals("in resource 0x" + Integer.toHexString(resid) 61 + " at index " + i, expected[i], res[i]); 62 } 63 } 64 65 @SmallTest 66 public void testStrings() throws Exception { 67 checkStringArray(R.array.strings, new String[] {"zero", "1", "here"}); 68 checkTextArray(R.array.strings, new String[] {"zero", "1", "here"}); 69 checkStringArray(R.array.integers, new String[] {null, null, null}); 70 checkTextArray(R.array.integers, new String[] {null, null, null}); 71 } 72 73 @SmallTest 74 public void testIntegers() throws Exception { 75 checkIntArray(R.array.strings, new int[] {0, 0, 0}); 76 checkIntArray(R.array.integers, new int[] {0, 1, 101}); 77 } 78 } 79