• 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 static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertSame;
23 import static org.junit.Assert.assertTrue;
24 
25 import android.content.Context;
26 import android.content.pm.PackageManager;
27 import android.content.res.ColorStateList;
28 import android.graphics.Bitmap;
29 import android.graphics.Canvas;
30 import android.graphics.Color;
31 import android.graphics.Rect;
32 import android.graphics.Typeface;
33 import android.os.LocaleList;
34 import android.os.Parcel;
35 import android.text.TextPaint;
36 import android.text.style.TextAppearanceSpan;
37 import android.widget.TextView;
38 
39 import androidx.test.InstrumentationRegistry;
40 import androidx.test.filters.SmallTest;
41 import androidx.test.runner.AndroidJUnit4;
42 
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 
47 @SmallTest
48 @RunWith(AndroidJUnit4.class)
49 public class TextAppearanceSpanTest {
50     private Context mContext;
51     private ColorStateList mColorStateList;
52 
53     @Before
setup()54     public void setup() {
55         mContext = InstrumentationRegistry.getTargetContext();
56 
57         int[][] states = new int[][] { new int[0], new int[0] };
58         int[] colors = new int[] { Color.rgb(0, 0, 255), Color.BLACK };
59         mColorStateList = new ColorStateList(states, colors);
60     }
61 
62     @Test
testConstructor()63     public void testConstructor() {
64         new TextAppearanceSpan(mContext, 1);
65         new TextAppearanceSpan(mContext, 1, 1);
66 
67         TextAppearanceSpan textAppearanceSpan =
68                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
69         Parcel p = Parcel.obtain();
70         try {
71             textAppearanceSpan.writeToParcel(p, 0);
72             p.setDataPosition(0);
73             new TextAppearanceSpan(p);
74         } finally {
75             p.recycle();
76         }
77 
78         new TextAppearanceSpan(null, -1, -1, null, null);
79     }
80 
81     @Test(expected=NullPointerException.class)
testConstructorNullContext1()82     public void testConstructorNullContext1() {
83         new TextAppearanceSpan(null, -1);
84     }
85 
86 
87     @Test(expected=NullPointerException.class)
testConstructorNullContext2()88     public void testConstructorNullContext2() {
89         new TextAppearanceSpan(null, -1, -1);
90     }
91 
92     @Test
testGetFamily()93     public void testGetFamily() {
94         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
95         assertNull(textAppearanceSpan.getFamily());
96 
97         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
98         assertNull(textAppearanceSpan.getFamily());
99 
100         textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
101         assertEquals("sans", textAppearanceSpan.getFamily());
102     }
103 
104     @Test
testUpdateMeasureState()105     public void testUpdateMeasureState() {
106         TextAppearanceSpan textAppearanceSpan =
107                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
108         TextPaint tp = new TextPaint();
109         tp.setTextSize(1.0f);
110         assertEquals(1.0f, tp.getTextSize(), 0.0f);
111 
112         textAppearanceSpan.updateMeasureState(tp);
113 
114         assertEquals(6.0f, tp.getTextSize(), 0.0f);
115     }
116 
117     @Test(expected=NullPointerException.class)
testUpdateMeasureStateNull()118     public void testUpdateMeasureStateNull() {
119         TextAppearanceSpan textAppearanceSpan =
120                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
121         textAppearanceSpan.updateMeasureState(null);
122     }
123 
124     @Test
testGetTextColor()125     public void testGetTextColor() {
126         TextAppearanceSpan textAppearanceSpan =
127                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
128         assertSame(mColorStateList, textAppearanceSpan.getTextColor());
129 
130         textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, null, mColorStateList);
131         assertNull(textAppearanceSpan.getTextColor());
132     }
133 
134     @Test
testGetTextSize()135     public void testGetTextSize() {
136         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
137         assertEquals(-1, textAppearanceSpan.getTextSize());
138 
139         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
140         assertEquals(-1, textAppearanceSpan.getTextSize());
141 
142         textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
143         assertEquals(6, textAppearanceSpan.getTextSize());
144     }
145 
146     @Test
testGetTextStyle()147     public void testGetTextStyle() {
148         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
149         assertEquals(0, textAppearanceSpan.getTextStyle());
150 
151         textAppearanceSpan = new TextAppearanceSpan(mContext, 1, 1);
152         assertEquals(0, textAppearanceSpan.getTextStyle());
153 
154         textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
155         assertEquals(1, textAppearanceSpan.getTextStyle());
156     }
157 
158     @Test
testGetLinkTextColor()159     public void testGetLinkTextColor() {
160         TextAppearanceSpan textAppearanceSpan =
161                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
162         assertSame(mColorStateList, textAppearanceSpan.getLinkTextColor());
163 
164         textAppearanceSpan = new TextAppearanceSpan("sans", 1, 6, mColorStateList, null);
165         assertNull(textAppearanceSpan.getLinkTextColor());
166     }
167 
168     @Test
testGetTextFontWeight()169     public void testGetTextFontWeight() {
170         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
171                 android.text.cts.R.style.textAppearanceWithFontWeight);
172         assertEquals(500, textAppearanceSpan.getTextFontWeight());
173 
174         textAppearanceSpan = new TextAppearanceSpan(mContext,
175                 android.text.cts.R.style.textAppearanceWithNoAttributes);
176         assertEquals(-1, textAppearanceSpan.getTextFontWeight());
177     }
178 
179     @Test
testGetTextLocales()180     public void testGetTextLocales() {
181         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
182                 android.text.cts.R.style.textAppearanceWithTextLocales);
183         assertEquals(textAppearanceSpan.getTextLocales(),
184                 LocaleList.forLanguageTags("ja-JP,zh-CN"));
185     }
186 
187     @Test
testGetShadowColor()188     public void testGetShadowColor() {
189         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
190                 android.text.cts.R.style.textAppearanceWithShadow);
191         assertEquals(Color.parseColor("#00FFFF"), textAppearanceSpan.getShadowColor());
192 
193         textAppearanceSpan = new TextAppearanceSpan(mContext,
194                 android.text.cts.R.style.textAppearanceWithNoAttributes);
195         assertEquals(0, textAppearanceSpan.getShadowColor());
196     }
197 
198     @Test
testGetShadowDx()199     public void testGetShadowDx() {
200         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
201                 android.text.cts.R.style.textAppearanceWithShadow);
202         assertEquals(1.0f, textAppearanceSpan.getShadowDx(), 0.0f);
203 
204         textAppearanceSpan = new TextAppearanceSpan(mContext,
205                 android.text.cts.R.style.textAppearanceWithNoAttributes);
206         assertEquals(0.0f, textAppearanceSpan.getShadowDx(), 0.0f);
207     }
208 
209     @Test
testGetShadowDy()210     public void testGetShadowDy() {
211         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
212                 android.text.cts.R.style.textAppearanceWithShadow);
213         assertEquals(2.0f , textAppearanceSpan.getShadowDy(), 0.0f);
214 
215         textAppearanceSpan = new TextAppearanceSpan(mContext,
216                 android.text.cts.R.style.textAppearanceWithNoAttributes);
217         assertEquals(0.0f, textAppearanceSpan.getShadowDy(), 0.0f);
218     }
219 
220     @Test
testGetShadowRadius()221     public void testGetShadowRadius() {
222         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
223                 android.text.cts.R.style.textAppearanceWithShadow);
224         assertEquals(3.0f , textAppearanceSpan.getShadowRadius(), 0.0f);
225 
226         textAppearanceSpan = new TextAppearanceSpan(mContext,
227                 android.text.cts.R.style.textAppearanceWithNoAttributes);
228         assertEquals(0.0f, textAppearanceSpan.getShadowRadius(), 0.0f);
229     }
230 
231     @Test
testGetFontFeatureSettings()232     public void testGetFontFeatureSettings() {
233         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
234                 android.text.cts.R.style.textAppearanceWithFontFeatureSettings);
235         assertEquals("\"smcp\"" , textAppearanceSpan.getFontFeatureSettings());
236 
237         textAppearanceSpan = new TextAppearanceSpan(mContext,
238                 android.text.cts.R.style.textAppearanceWithNoAttributes);
239         assertEquals(null, textAppearanceSpan.getFontFeatureSettings());
240     }
241 
242     @Test
testGetFontVariationSettings()243     public void testGetFontVariationSettings() {
244         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
245                 android.text.cts.R.style.textAppearanceWithFontVariationSettings);
246         assertEquals("\'wdth\' 150" , textAppearanceSpan.getFontVariationSettings());
247 
248         textAppearanceSpan = new TextAppearanceSpan(mContext,
249                 android.text.cts.R.style.textAppearanceWithNoAttributes);
250         assertEquals(null, textAppearanceSpan.getFontVariationSettings());
251     }
252 
253     @Test
testIsElegantTextHeight()254     public void testIsElegantTextHeight() {
255         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext,
256                 android.text.cts.R.style.textAppearanceWithElegantTextHeight);
257         assertEquals(true , textAppearanceSpan.isElegantTextHeight());
258 
259         textAppearanceSpan = new TextAppearanceSpan(mContext,
260                 android.text.cts.R.style.textAppearanceWithNoAttributes);
261         assertEquals(false, textAppearanceSpan.isElegantTextHeight());
262     }
263 
264     @Test
testUpdateDrawState()265     public void testUpdateDrawState() {
266         TextAppearanceSpan textAppearanceSpan =
267                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
268         TextPaint tp = new TextPaint();
269         tp.setColor(0);
270         tp.linkColor = 0;
271         assertEquals(0, tp.getColor());
272 
273         textAppearanceSpan.updateDrawState(tp);
274 
275         int expected = mColorStateList.getColorForState(tp.drawableState, 0);
276         assertEquals(expected, tp.getColor());
277         assertEquals(expected, tp.linkColor);
278     }
279 
280     @Test(expected=NullPointerException.class)
testUpdateDrawStateNull()281     public void testUpdateDrawStateNull() {
282         TextAppearanceSpan textAppearanceSpan =
283                 new TextAppearanceSpan("sans", 1, 6, mColorStateList, mColorStateList);
284 
285         textAppearanceSpan.updateDrawState(null);
286     }
287 
288     @Test
testDescribeContents()289     public void testDescribeContents() {
290         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
291         textAppearanceSpan.describeContents();
292     }
293 
294     @Test
testGetSpanTypeId()295     public void testGetSpanTypeId() {
296         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(mContext, 1);
297         textAppearanceSpan.getSpanTypeId();
298     }
299 
300     @Test
testWriteToParcel()301     public void testWriteToParcel() {
302         Parcel p = Parcel.obtain();
303         String family = "sans";
304         TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(family, 1, 6, null, null);
305         textAppearanceSpan.writeToParcel(p, 0);
306         p.setDataPosition(0);
307         TextAppearanceSpan newSpan = new TextAppearanceSpan(p);
308         assertEquals(family, newSpan.getFamily());
309         p.recycle();
310     }
311 
312     @Test
testCreateFromStyle_FontResource()313     public void testCreateFromStyle_FontResource() {
314         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
315                 android.text.cts.R.style.customFont);
316         final TextPaint tp = new TextPaint();
317         final float originalTextWidth = tp.measureText("a");
318         span.updateDrawState(tp);
319         assertNotEquals(originalTextWidth, tp.measureText("a"), 0.0f);
320     }
321 
322     @Test
testCreateFromStyle_ElegantTextHeight()323     public void testCreateFromStyle_ElegantTextHeight() {
324         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
325                 android.text.cts.R.style.textAppearanceWithElegantTextHeight);
326         final TextPaint tp = new TextPaint();
327         span.updateDrawState(tp);
328         assertTrue(tp.isElegantTextHeight());
329     }
330 
331     @Test
testCreateFromStyle_LetterSpacing()332     public void testCreateFromStyle_LetterSpacing() {
333         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
334                 android.text.cts.R.style.textAppearanceWithLetterSpacing);
335         final TextPaint tp = new TextPaint();
336         span.updateDrawState(tp);
337         assertEquals(1.0f, tp.getLetterSpacing(), 0.0f);
338     }
339 
340     @Test
testCreateFromStyle_FontFeatureSettings()341     public void testCreateFromStyle_FontFeatureSettings() {
342         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
343                 android.text.cts.R.style.textAppearanceWithFontFeatureSettings);
344         final TextPaint tp = new TextPaint();
345         span.updateDrawState(tp);
346         assertEquals("\"smcp\"", tp.getFontFeatureSettings());
347     }
348 
349     @Test
testCreateFromStyle_FontVariationSettings()350     public void testCreateFromStyle_FontVariationSettings() {
351         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
352                 android.text.cts.R.style.textAppearanceWithFontVariationSettings);
353         final TextPaint tp = new TextPaint();
354         span.updateDrawState(tp);
355         assertEquals("'wdth' 150", tp.getFontVariationSettings());
356     }
357 
358     @Test
testCreateFromStyle_letterSpacing()359     public void testCreateFromStyle_letterSpacing() {
360         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
361                 android.text.cts.R.style.textAppearanceWithLetterSpacing);
362         final TextPaint tp = new TextPaint();
363         span.updateDrawState(tp);
364         assertEquals(1.0f, tp.getLetterSpacing(), 0f);
365     }
366 
367     @Test
testWriteReadParcel_FontResource()368     public void testWriteReadParcel_FontResource() {
369         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
370                 android.text.cts.R.style.customFont);
371 
372         final Parcel p = Parcel.obtain();
373         span.writeToParcel(p, 0);
374         p.setDataPosition(0);
375         final TextAppearanceSpan unparceledSpan = new TextAppearanceSpan(p);
376 
377         final TextPaint tp = new TextPaint();
378         span.updateDrawState(tp);
379         final float originalSpanTextWidth = tp.measureText("a");
380         unparceledSpan.updateDrawState(tp);
381         assertEquals(originalSpanTextWidth, tp.measureText("a"), 0.0f);
382     }
383 
384     @Test
testWriteReadParcel_FontResource_WithStyle()385     public void testWriteReadParcel_FontResource_WithStyle() {
386         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
387                 android.text.cts.R.style.customFontWithStyle);
388 
389         final Parcel p = Parcel.obtain();
390         span.writeToParcel(p, 0);
391         p.setDataPosition(0);
392         final TextAppearanceSpan unparceledSpan = new TextAppearanceSpan(p);
393 
394         final TextPaint tp = new TextPaint();
395         span.updateDrawState(tp);
396         final float originalSpanTextWidth = tp.measureText("a");
397         unparceledSpan.updateDrawState(tp);
398         assertEquals(originalSpanTextWidth, tp.measureText("a"), 0.0f);
399     }
400 
401     @Test
testWriteReadParcel_WithAllAttributes()402     public void testWriteReadParcel_WithAllAttributes() {
403         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
404                 android.text.cts.R.style.textAppearanceWithAllAttributes);
405 
406         final Parcel p = Parcel.obtain();
407         span.writeToParcel(p, 0);
408         p.setDataPosition(0);
409         final TextAppearanceSpan unparceledSpan = new TextAppearanceSpan(p);
410         final ColorStateList originalTextColor = span.getTextColor();
411         final ColorStateList unparceledTextColor = unparceledSpan.getTextColor();
412         final ColorStateList originalLinkTextColor = span.getLinkTextColor();
413         final ColorStateList unparceledLinkTextColor = unparceledSpan.getLinkTextColor();
414 
415         assertEquals(span.getFamily(), unparceledSpan.getFamily());
416         // ColorStateList doesn't implement equals(), so we borrow this code
417         // from ColorStateListTest.java to test correctness of parceling.
418         assertEquals(originalTextColor.isStateful(), unparceledTextColor.isStateful());
419         assertEquals(originalTextColor.getDefaultColor(), unparceledTextColor.getDefaultColor());
420         assertEquals(originalLinkTextColor.isStateful(),
421                 unparceledLinkTextColor.isStateful());
422         assertEquals(originalLinkTextColor.getDefaultColor(),
423                 unparceledLinkTextColor.getDefaultColor());
424 
425         assertEquals(span.getTextSize(), unparceledSpan.getTextSize());
426         assertEquals(span.getTextStyle(), unparceledSpan.getTextStyle());
427         assertEquals(span.getTextFontWeight(), unparceledSpan.getTextFontWeight());
428         assertEquals(span.getTextLocales(), unparceledSpan.getTextLocales());
429         assertEquals(span.getTypeface(), unparceledSpan.getTypeface());
430 
431         assertEquals(span.getShadowColor(), unparceledSpan.getShadowColor());
432         assertEquals(span.getShadowDx(), unparceledSpan.getShadowDx(), 0.0f);
433         assertEquals(span.getShadowDy(), unparceledSpan.getShadowDy(), 0.0f);
434         assertEquals(span.getShadowRadius(), unparceledSpan.getShadowRadius(), 0.0f);
435 
436         assertEquals(span.getFontFeatureSettings(), unparceledSpan.getFontFeatureSettings());
437         assertEquals(span.getFontVariationSettings(), unparceledSpan.getFontVariationSettings());
438         assertEquals(span.isElegantTextHeight(), unparceledSpan.isElegantTextHeight());
439         assertEquals(span.getLetterSpacing(), unparceledSpan.getLetterSpacing(), 0f);
440     }
441 
442     @Test
testRestrictContext()443     public void testRestrictContext() throws PackageManager.NameNotFoundException {
444         final Context ctx = mContext.createPackageContext(mContext.getPackageName(),
445                 Context.CONTEXT_RESTRICTED);
446         final TextAppearanceSpan span = new TextAppearanceSpan(ctx,
447                 android.text.cts.R.style.customFont);
448         final TextPaint tp = new TextPaint();
449         final float originalTextWidth = tp.measureText("a");
450         span.updateDrawState(tp);
451         // Custom font must not be loaded with the restricted context.
452         assertEquals(originalTextWidth, tp.measureText("a"), 0.0f);
453 
454     }
455 
456     @Test
testSameAsTextView_TextColor()457     public void testSameAsTextView_TextColor() {
458         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
459                 android.text.cts.R.style.TextAppearanceWithTextColor);
460         final TextView tv = new TextView(mContext);
461         tv.setTextAppearance(android.text.cts.R.style.TextAppearanceWithTextColor);
462 
463         // No equals implemented in ColorStateList
464         assertEquals(span.getTextColor().toString(), tv.getTextColors().toString());
465     }
466 
467     @Test
testSameAsTextView_TextColorLink()468     public void testSameAsTextView_TextColorLink() {
469         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
470                 android.text.cts.R.style.TextAppearanceWithTextColorLink);
471         final TextView tv = new TextView(mContext);
472         tv.setTextAppearance(android.text.cts.R.style.TextAppearanceWithTextColorLink);
473 
474         // No equals implemented in ColorStateList
475         assertEquals(span.getLinkTextColor().toString(), tv.getLinkTextColors().toString());
476     }
477 
478     @Test
testSameAsTextView_TextSize()479     public void testSameAsTextView_TextSize() {
480         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
481                 android.text.cts.R.style.TextAppearanceWithTextSize);
482         final TextView tv = new TextView(mContext);
483         tv.setTextAppearance(android.text.cts.R.style.TextAppearanceWithTextSize);
484 
485         assertEquals((float) span.getTextSize(), tv.getTextSize(), 0.0f);
486     }
487 
488     // Currently we don't have a good way to compare typefaces. So this function simply draws
489     // text on Bitmap use the input typeface and then compare the result Bitmaps.
assertTypefaceSame(Typeface typeface0, Typeface typeface1)490     private void assertTypefaceSame(Typeface typeface0, Typeface typeface1) {
491         final int width = 200;
492         final int height = 100;
493         final String testStr = "Ez 123*!\u7B80";
494 
495         final Bitmap bitmap0 = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
496         final Bitmap bitmap1 = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
497         final Canvas canvas0 = new Canvas(bitmap0);
498         final Canvas canvas1 = new Canvas(bitmap1);
499         final TextPaint paint0 = new TextPaint();
500         final TextPaint paint1 = new TextPaint();
501         // Set the textSize smaller than the bitmap.
502         paint0.setTextSize(20);
503         paint1.setTextSize(20);
504         // Set the bitmap background color to white.
505         canvas0.drawColor(0xFFFFFFFF);
506         canvas1.drawColor(0xFFFFFFFF);
507         // Set paint a different color from the background.
508         paint0.setColor(0xFF000000);
509         paint1.setColor(0xFF000000);
510         paint0.setTypeface(typeface0);
511         paint1.setTypeface(typeface1);
512 
513         final Rect bound0 = new Rect();
514         final Rect bound1 = new Rect();
515 
516         paint0.getTextBounds(testStr, 0, testStr.length(), bound0);
517         paint1.getTextBounds(testStr, 0, testStr.length(), bound1);
518 
519         // The bounds measured by two paints should be the same.
520         assertEquals(bound0, bound1);
521 
522         canvas0.drawText(testStr, -bound0.left, -bound0.top, paint0);
523         canvas1.drawText(testStr, -bound1.left, -bound1.top, paint1);
524 
525         assertTrue(bitmap0.sameAs(bitmap1));
526     }
527 
528     @Test
testSameAsTextView_Typeface()529     public void testSameAsTextView_Typeface() {
530         // Here we need textView0 to get a default typeface, which will be updated by
531         // TextAppearanceSpan, and the result of update should be the same as that of
532         // textView1.setTextAppearance().
533         final TextView textView0 = new TextView(mContext);
534         final TextView textView1 = new TextView(mContext);
535 
536         final TextPaint paint = new TextPaint();
537         paint.setTypeface(textView0.getTypeface());
538         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
539                 android.text.cts.R.style.TextAppearanceWithTypeface);
540         span.updateDrawState(paint);
541 
542         textView1.setTextAppearance(android.text.cts.R.style.TextAppearanceWithTypeface);
543 
544         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
545     }
546 
547     @Test
testSameAsTextView_TypefaceWithStyle()548     public void testSameAsTextView_TypefaceWithStyle() {
549         final TextView textView0 = new TextView(mContext);
550         final TextView textView1 = new TextView(mContext);
551 
552         final TextPaint paint = new TextPaint();
553         paint.setTypeface(textView0.getTypeface());
554         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
555                 android.text.cts.R.style.TextAppearanceWithTypefaceAndBold);
556         span.updateDrawState(paint);
557 
558         textView1.setTextAppearance(android.text.cts.R.style.TextAppearanceWithTypefaceAndBold);
559 
560         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
561     }
562 
563     @Test
testSameAsTextView_TypefaceWithWeight()564     public void testSameAsTextView_TypefaceWithWeight() {
565         final TextView textView0 = new TextView(mContext);
566         final TextView textView1 = new TextView(mContext);
567 
568         final TextPaint paint = new TextPaint();
569         paint.setTypeface(textView0.getTypeface());
570         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
571                 android.text.cts.R.style.TextAppearanceWithTypefaceAndWeight);
572         span.updateDrawState(paint);
573 
574         textView1.setTextAppearance(
575                 android.text.cts.R.style.TextAppearanceWithTypefaceAndWeight);
576 
577         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
578     }
579 
580     // The priority of fontWeight and bold should be identical in both classes.
581     @Test
testSameAsTextView_WeightAndBold()582     public void testSameAsTextView_WeightAndBold() {
583         final TextView textView0 = new TextView(mContext);
584         final TextView textView1 = new TextView(mContext);
585 
586         final TextPaint paint = new TextPaint();
587         paint.setTypeface(textView0.getTypeface());
588         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
589                 android.text.cts.R.style.TextAppearanceWithBoldAndWeight);
590         span.updateDrawState(paint);
591 
592         textView1.setTextAppearance(android.text.cts.R.style.TextAppearanceWithBoldAndWeight);
593 
594         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
595     }
596 
597     @Test
testSameAsTextView_FontFamily()598     public void testSameAsTextView_FontFamily() {
599         final TextView textView0 = new TextView(mContext);
600         final TextView textView1 = new TextView(mContext);
601 
602         final TextPaint paint = new TextPaint();
603         paint.setTypeface(textView0.getTypeface());
604         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
605                 android.text.cts.R.style.TextAppearanceWithFontFamily);
606         span.updateDrawState(paint);
607 
608         textView1.setTextAppearance(android.text.cts.R.style.TextAppearanceWithFontFamily);
609 
610         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
611     }
612 
613     // The priority of fontFamily and typeface should be identical in both classes.
614     @Test
testSameAsTextView_FontFamilyAndTypeface()615     public void testSameAsTextView_FontFamilyAndTypeface() {
616         final TextView textView0 = new TextView(mContext);
617         final TextView textView1 = new TextView(mContext);
618 
619         final TextPaint paint = new TextPaint();
620         paint.setTypeface(textView0.getTypeface());
621         final TextAppearanceSpan span = new TextAppearanceSpan(mContext,
622                 android.text.cts.R.style.TextAppearanceWithFontFamilyAndTypeface);
623         span.updateDrawState(paint);
624 
625         textView1.setTextAppearance(
626                 android.text.cts.R.style.TextAppearanceWithFontFamilyAndTypeface);
627 
628         assertTypefaceSame(paint.getTypeface(), textView1.getTypeface());
629     }
630 }
631