1 /* 2 * Copyright (C) 2022 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.settings.accessibility; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.graphics.Color; 22 import android.view.accessibility.CaptioningManager; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.robolectric.RobolectricTestRunner; 27 28 /** Tests for {@link CaptionUtils}. */ 29 @RunWith(RobolectricTestRunner.class) 30 public class CaptionUtilsTest { 31 32 @Test parseColor_defaultPackedColor_shouldReturnUnspecified()33 public void parseColor_defaultPackedColor_shouldReturnUnspecified() { 34 final int color = CaptionUtils.parseColor(0xFFFF00); 35 36 assertThat(color).isEqualTo(CaptioningManager.CaptionStyle.COLOR_UNSPECIFIED); 37 } 38 39 @Test parseColor_unrecognizedColor_shouldReturnTransparent()40 public void parseColor_unrecognizedColor_shouldReturnTransparent() { 41 final int color = CaptionUtils.parseColor(0x00); 42 43 assertThat(color).isEqualTo(Color.TRANSPARENT); 44 } 45 46 @Test parseColor_redColor_shouldReturnRed()47 public void parseColor_redColor_shouldReturnRed() { 48 final int color = CaptionUtils.parseColor(0xFFFF0000); 49 50 assertThat(color).isEqualTo(Color.RED); 51 } 52 53 @Test parseOpacity_defaultPackedColor_shouldReturnUnspecified()54 public void parseOpacity_defaultPackedColor_shouldReturnUnspecified() { 55 final int color = CaptionUtils.parseOpacity(0xFFFF00); 56 57 assertThat(color).isEqualTo(CaptioningManager.CaptionStyle.COLOR_UNSPECIFIED); 58 } 59 60 @Test parseOpacity_unrecognizedColor_shouldReturnTransparent()61 public void parseOpacity_unrecognizedColor_shouldReturnTransparent() { 62 final int color = CaptionUtils.parseOpacity(0x00); 63 64 assertThat(color).isEqualTo(0xFFFFFF); 65 } 66 67 @Test parseOpacity_halfTransparentValue_shouldReturnHalfTransparent()68 public void parseOpacity_halfTransparentValue_shouldReturnHalfTransparent() { 69 final int color = CaptionUtils.parseOpacity(0x80FFFFFF); 70 71 assertThat(color).isEqualTo(0x80FFFFFF); 72 } 73 74 @Test mergeColorOpacity_halfTransparentRedValue_shouldReturnMergeColorOpacityValue()75 public void mergeColorOpacity_halfTransparentRedValue_shouldReturnMergeColorOpacityValue() { 76 final int color = CaptionUtils.mergeColorOpacity(0xFFFF0000, 0x80FFFFFF); 77 78 assertThat(color).isEqualTo(0x80FF0000); 79 } 80 } 81