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
17package android.text.style.cts;
18
19
20import android.text.TextPaint;
21import android.text.style.CharacterStyle;
22import android.text.style.MetricAffectingSpan;
23import android.text.style.SuperscriptSpan;
24
25import junit.framework.TestCase;
26
27public class CharacterStyleTest extends TestCase {
28    public void testWrap() {
29        // use a MetricAffectingSpan
30        MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan();
31
32        CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan);
33        assertNotNull(result);
34        assertSame(metricAffectingSpan, result.getUnderlying());
35        assertNotSame(metricAffectingSpan, result);
36
37        // use a no-MetricAffectingSpan
38        CharacterStyle characterStyle = new MyCharacterStyle();
39        result = CharacterStyle.wrap(characterStyle);
40        assertNotNull(result);
41        assertTrue(result instanceof CharacterStyle);
42        assertSame(characterStyle, result.getUnderlying());
43        assertNotSame(characterStyle, result);
44
45        result = CharacterStyle.wrap((MetricAffectingSpan) null);
46        assertNotNull(result);
47        assertTrue(result instanceof CharacterStyle);
48
49        result = CharacterStyle.wrap((CharacterStyle) null);
50        assertNotNull(result);
51        assertTrue(result instanceof CharacterStyle);
52    }
53
54    public void testGetUnderlying() {
55        CharacterStyle expected = new MyCharacterStyle();
56        assertSame(expected, expected.getUnderlying());
57
58        MetricAffectingSpan metricAffectingSpan = new SuperscriptSpan();
59        CharacterStyle result = CharacterStyle.wrap(metricAffectingSpan);
60        assertNotNull(result);
61        assertTrue(result instanceof MetricAffectingSpan);
62        assertSame(metricAffectingSpan, result.getUnderlying());
63    }
64
65    /**
66     * MyCharacterStyle for test.
67     */
68    private class MyCharacterStyle extends CharacterStyle {
69        @Override
70        public void updateDrawState(TextPaint tp) {
71            // implement abstract method.
72        }
73    }
74}
75