1 /* 2 * Copyright (C) 2008 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.text.style.cts; 18 19 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertNotSame; 21 import static org.junit.Assert.assertSame; 22 import static org.junit.Assert.assertTrue; 23 24 import android.support.test.filters.SmallTest; 25 import android.support.test.runner.AndroidJUnit4; 26 import android.text.TextPaint; 27 import android.text.style.CharacterStyle; 28 import android.text.style.MetricAffectingSpan; 29 import android.text.style.SuperscriptSpan; 30 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @SmallTest 35 @RunWith(AndroidJUnit4.class) 36 public class CharacterStyleTest { 37 @Test 38 public void testWrap() { 39 // use a MetricAffectingSpan 40 MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan(); 41 42 CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan); 43 assertNotNull(result); 44 assertSame(metricAffectingSpan, result.getUnderlying()); 45 assertNotSame(metricAffectingSpan, result); 46 47 // use a no-MetricAffectingSpan 48 CharacterStyle characterStyle = new MyCharacterStyle(); 49 result = CharacterStyle.wrap(characterStyle); 50 assertNotNull(result); 51 assertTrue(result instanceof CharacterStyle); 52 assertSame(characterStyle, result.getUnderlying()); 53 assertNotSame(characterStyle, result); 54 55 result = CharacterStyle.wrap((MetricAffectingSpan) null); 56 assertNotNull(result); 57 assertTrue(result instanceof CharacterStyle); 58 59 result = CharacterStyle.wrap((CharacterStyle) null); 60 assertNotNull(result); 61 assertTrue(result instanceof CharacterStyle); 62 } 63 64 @Test 65 public void testGetUnderlying() { 66 CharacterStyle expected = new MyCharacterStyle(); 67 assertSame(expected, expected.getUnderlying()); 68 69 MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan(); 70 CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan); 71 assertNotNull(result); 72 assertTrue(result instanceof MetricAffectingSpan); 73 assertSame(metricAffectingSpan, result.getUnderlying()); 74 } 75 76 private class MyCharacterStyle extends CharacterStyle { 77 @Override 78 public void updateDrawState(TextPaint tp) { 79 } 80 } 81 } 82