• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.cts.stub.R;
20 
21 import dalvik.annotation.TestLevel;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.TestTargetNew;
24 import dalvik.annotation.TestTargets;
25 import dalvik.annotation.ToBeFixed;
26 
27 import android.graphics.Canvas;
28 import android.graphics.Rect;
29 import android.graphics.Paint.FontMetricsInt;
30 import android.graphics.drawable.Drawable;
31 import android.test.AndroidTestCase;
32 import android.text.style.DynamicDrawableSpan;
33 
34 @TestTargetClass(DynamicDrawableSpan.class)
35 public class DynamicDrawableSpanTest extends AndroidTestCase {
36     @TestTargets({
37         @TestTargetNew(
38             level = TestLevel.COMPLETE,
39             notes = "Test constructor(s) of DynamicDrawableSpan.",
40             method = "DynamicDrawableSpan",
41             args = {}
42         ),
43         @TestTargetNew(
44             level = TestLevel.COMPLETE,
45             notes = "Test constructor(s) of DynamicDrawableSpan.",
46             method = "DynamicDrawableSpan",
47             args = {int.class}
48         ),
49         @TestTargetNew(
50             level = TestLevel.COMPLETE,
51             notes = "Test getVerticalAlignment().",
52             method = "getVerticalAlignment",
53             args = {}
54         )
55     })
56     @ToBeFixed(bug = "1695243", explanation = "miss javadoc for constructor DynamicDrawableSpan()")
testConstructor()57     public void testConstructor() {
58         DynamicDrawableSpan d = new MyDynamicDrawableSpan();
59         assertEquals(DynamicDrawableSpan.ALIGN_BOTTOM, d.getVerticalAlignment());
60 
61         d = new MyDynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BASELINE);
62         assertEquals(DynamicDrawableSpan.ALIGN_BASELINE, d.getVerticalAlignment());
63 
64         d = new MyDynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BOTTOM);
65         assertEquals(DynamicDrawableSpan.ALIGN_BOTTOM, d.getVerticalAlignment());
66     }
67 
68     @TestTargetNew(
69         level = TestLevel.COMPLETE,
70         notes = "Test getSize(Paint paint, CharSequence text, int start, int end," +
71                 " FontMetricsInt fm). And the following parameters are never used in" +
72                 " this method: paint, text, start, end",
73         method = "getSize",
74         args = {android.graphics.Paint.class, java.lang.CharSequence.class, int.class,
75                 int.class, android.graphics.Paint.FontMetricsInt.class}
76     )
77     @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
testGetSize()78     public void testGetSize() {
79         DynamicDrawableSpan dynamicDrawableSpan = new MyDynamicDrawableSpan();
80         FontMetricsInt fm = new FontMetricsInt();
81 
82         assertEquals(0, fm.ascent);
83         assertEquals(0, fm.bottom);
84         assertEquals(0, fm.descent);
85         assertEquals(0, fm.leading);
86         assertEquals(0, fm.top);
87 
88         Rect rect = dynamicDrawableSpan.getDrawable().getBounds();
89         assertEquals(rect.right, dynamicDrawableSpan.getSize(null, null, 0, 0, fm));
90 
91         assertEquals(-rect.bottom, fm.ascent);
92         assertEquals(0, fm.bottom);
93         assertEquals(0, fm.descent);
94         assertEquals(0, fm.leading);
95         assertEquals(-rect.bottom, fm.top);
96 
97         assertEquals(rect.right, dynamicDrawableSpan.getSize(null, null, 0, 0, null));
98     }
99 
100     @TestTargetNew(
101         level = TestLevel.COMPLETE,
102         notes = "Test draw(Canvas canvas, CharSequence text, int start, int end, float x," +
103                 " int top, int y, int bottom, Paint paint). And the following parameters are" +
104                 " never used in this method: text, start, end, top, y, paint",
105         method = "draw",
106         args = {android.graphics.Canvas.class, java.lang.CharSequence.class, int.class, int.class,
107                 float.class, int.class, int.class, int.class, android.graphics.Paint.class}
108     )
109     @ToBeFixed(bug = "1695243", explanation = "miss javadoc")
testDraw()110     public void testDraw() {
111         DynamicDrawableSpan dynamicDrawableSpan = new MyDynamicDrawableSpan();
112         Canvas canvas = new Canvas();
113         dynamicDrawableSpan.draw(canvas, null, 0, 0, 1.0f, 0, 0, 1, null);
114 
115         try {
116             dynamicDrawableSpan.draw(null, null, 0, 0, 1.0f, 0, 0, 1, null);
117             fail("should throw NullPointerException.");
118         } catch (NullPointerException e) {
119             // expected, test success.
120         }
121     }
122 
123     /**
124      * The MyDynamicDrawableSpan for test.
125      */
126     private class MyDynamicDrawableSpan extends DynamicDrawableSpan {
MyDynamicDrawableSpan()127         public MyDynamicDrawableSpan() {
128             super();
129         }
130 
MyDynamicDrawableSpan(int verticalAlignment)131         protected MyDynamicDrawableSpan(int verticalAlignment) {
132             super(verticalAlignment);
133         }
134 
135         @Override
getDrawable()136         public Drawable getDrawable() {
137             // implement abstract method
138             return getContext().getResources().getDrawable(R.drawable.scenery);
139         }
140     }
141 }
142