1 /* 2 * Copyright (C) 2020 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; 18 19 import org.junit.Test; 20 21 import static android.util.TypedValue.TYPE_ATTRIBUTE; 22 import static android.util.TypedValue.TYPE_DIMENSION; 23 import static android.util.TypedValue.TYPE_FLOAT; 24 import static android.util.TypedValue.TYPE_INT_BOOLEAN; 25 import static android.util.TypedValue.TYPE_INT_COLOR_ARGB4; 26 import static android.util.TypedValue.TYPE_INT_COLOR_ARGB8; 27 import static android.util.TypedValue.TYPE_INT_COLOR_RGB4; 28 import static android.util.TypedValue.TYPE_INT_COLOR_RGB8; 29 import static android.util.TypedValue.TYPE_INT_DEC; 30 import static android.util.TypedValue.TYPE_INT_HEX; 31 import static android.util.TypedValue.TYPE_NULL; 32 import static android.util.TypedValue.TYPE_REFERENCE; 33 import static android.util.TypedValue.TYPE_STRING; 34 import static org.junit.Assert.assertEquals; 35 36 public class BridgeTypedArrayTest { 37 38 @Test getType()39 public void getType() { 40 assertEquals(TYPE_NULL, BridgeTypedArray.getType(null)); 41 assertEquals(TYPE_REFERENCE, BridgeTypedArray.getType("@drawable/my_drawable")); 42 assertEquals(TYPE_ATTRIBUTE, BridgeTypedArray.getType("?attr/colorPrimary")); 43 assertEquals(TYPE_INT_BOOLEAN, BridgeTypedArray.getType("true")); 44 assertEquals(TYPE_STRING, BridgeTypedArray.getType("False")); 45 assertEquals(TYPE_INT_HEX, BridgeTypedArray.getType("0xffa39d")); 46 assertEquals(TYPE_STRING, BridgeTypedArray.getType("0xnothex")); 47 assertEquals(TYPE_INT_COLOR_RGB4, BridgeTypedArray.getType("#f34")); 48 assertEquals(TYPE_INT_COLOR_ARGB4, BridgeTypedArray.getType("#2f34")); 49 assertEquals(TYPE_INT_COLOR_RGB8, BridgeTypedArray.getType("#f34ab4")); 50 assertEquals(TYPE_INT_COLOR_ARGB8, BridgeTypedArray.getType("#1f34dc28")); 51 assertEquals(TYPE_STRING, BridgeTypedArray.getType("#notacolor")); 52 assertEquals(TYPE_DIMENSION, BridgeTypedArray.getType("16dp")); 53 assertEquals(TYPE_STRING, BridgeTypedArray.getType("16notaunit")); 54 assertEquals(TYPE_INT_DEC, BridgeTypedArray.getType("98543")); 55 assertEquals(TYPE_FLOAT, BridgeTypedArray.getType("43.364")); 56 assertEquals(TYPE_STRING, BridgeTypedArray.getType("5432dp342")); 57 } 58 } 59