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.cts; 18 19 import android.graphics.Color; 20 import android.graphics.Paint; 21 import android.graphics.Typeface; 22 import android.test.AndroidTestCase; 23 import android.text.TextPaint; 24 25 /** 26 * Test {@link TextPaint}. 27 */ 28 public class TextPaintTest extends AndroidTestCase { 29 private static final int DEFAULT_PAINT_FLAGS = TextPaint.DEV_KERN_TEXT_FLAG 30 | TextPaint.EMBEDDED_BITMAP_TEXT_FLAG; 31 32 public void testConstructor() { 33 TextPaint textPaint; 34 35 textPaint = new TextPaint(); 36 assertEquals(DEFAULT_PAINT_FLAGS, textPaint.getFlags()); 37 38 textPaint = new TextPaint(TextPaint.DITHER_FLAG); 39 assertEquals((TextPaint.DITHER_FLAG | DEFAULT_PAINT_FLAGS), 40 textPaint.getFlags()); 41 42 final Paint paint = new Paint(); 43 paint.setTextSize(42f); 44 textPaint = new TextPaint(paint); 45 assertEquals(paint.getTextSize(), textPaint.getTextSize()); 46 } 47 48 public void testSet() { 49 TextPaint textPaintSrc = new TextPaint(TextPaint.DITHER_FLAG); 50 int[] drawableState = new int[] { 0, 1 }; 51 textPaintSrc.bgColor = Color.GREEN; 52 textPaintSrc.baselineShift = 10; 53 textPaintSrc.linkColor = Color.BLUE; 54 textPaintSrc.drawableState = drawableState; 55 textPaintSrc.setTypeface(Typeface.DEFAULT_BOLD); 56 57 TextPaint textPaint = new TextPaint(); 58 assertEquals(0, textPaint.bgColor); 59 assertEquals(0, textPaint.baselineShift); 60 assertEquals(0, textPaint.linkColor); 61 assertNull(textPaint.drawableState); 62 assertNull(textPaint.getTypeface()); 63 64 textPaint.set(textPaintSrc); 65 assertEquals(textPaintSrc.bgColor, textPaint.bgColor); 66 assertEquals(textPaintSrc.baselineShift, textPaint.baselineShift); 67 assertEquals(textPaintSrc.linkColor, textPaint.linkColor); 68 assertSame(textPaintSrc.drawableState, textPaint.drawableState); 69 assertEquals(textPaintSrc.getTypeface(), textPaint.getTypeface()); 70 assertEquals(textPaintSrc.getFlags(), textPaint.getFlags()); 71 72 try { 73 textPaint.set(null); 74 fail("Should throw NullPointerException!"); 75 } catch (NullPointerException e) { 76 } 77 } 78 } 79