1 /* <lambda>null2 * Copyright (C) 2021 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 com.android.systemui.qs.tileimpl 18 19 import androidx.test.ext.junit.runners.AndroidJUnit4 20 import androidx.test.filters.MediumTest 21 import com.android.systemui.res.R 22 import com.android.systemui.SysuiTestCase 23 import com.google.common.truth.Truth.assertThat 24 import org.junit.Assert.assertEquals 25 import org.junit.Assert.assertNotEquals 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 29 @RunWith(AndroidJUnit4::class) 30 @MediumTest 31 class TilesStatesTextTest : SysuiTestCase() { 32 33 @Test 34 fun testStockTilesHaveStatesArray() { 35 val tiles = mContext.getString(R.string.quick_settings_tiles_stock).split(",") 36 tiles.forEach { spec -> 37 val resName = "${QSTileViewImpl.TILE_STATE_RES_PREFIX}$spec" 38 val resId = mContext.resources.getIdentifier(resName, "array", mContext.packageName) 39 40 assertNotEquals("Missing resource for $resName", 0, resId) 41 42 val array = mContext.resources.getStringArray(resId) 43 44 assertEquals("Array for $spec is of wrong size", 3, array.size) 45 } 46 } 47 48 @Test 49 fun testDefaultArray() { 50 val array = mContext.resources.getStringArray(R.array.tile_states_default) 51 52 assertThat(array.size).isEqualTo(3) 53 } 54 55 @Test 56 fun testStockTilesSubtitlesMap() { 57 val tiles = mContext.getString(R.string.quick_settings_tiles_stock).split(",") 58 tiles.forEach { spec -> 59 val resName = "${QSTileViewImpl.TILE_STATE_RES_PREFIX}$spec" 60 val resId = mContext.resources.getIdentifier(resName, "array", mContext.packageName) 61 62 assertNotEquals("Missing resource for $resName", 0, resId) 63 64 assertThat(SubtitleArrayMapping.getSubtitleId(spec)).isEqualTo(resId) 65 } 66 } 67 68 @Test 69 fun testStockTilesSubtitlesReturnsDefault_unknown() { 70 assertThat(SubtitleArrayMapping.getSubtitleId("unknown")) 71 .isEqualTo(R.array.tile_states_default) 72 } 73 74 @Test 75 fun testStockTilesSubtitlesReturnsDefault_null() { 76 assertThat(SubtitleArrayMapping.getSubtitleId(null)) 77 .isEqualTo(R.array.tile_states_default) 78 } 79 } 80