blob: c8ce884cf8267adce2af799d800dea45961eb8e9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Neal Nguyen1a44d5d2010-01-13 10:42:43 -080017package android.graphics;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import android.graphics.Paint;
20import android.graphics.Typeface;
21import android.test.suitebuilder.annotation.MediumTest;
22import android.test.suitebuilder.annotation.SmallTest;
Roozbeh Pournaderede3a172016-07-27 16:35:12 -070023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import junit.framework.TestCase;
25
26
27public class TypefaceTest extends TestCase {
28
29 // create array of all std faces
30 private final Typeface[] mFaces = new Typeface[] {
31 Typeface.create(Typeface.SANS_SERIF, 0),
32 Typeface.create(Typeface.SANS_SERIF, 1),
33 Typeface.create(Typeface.SERIF, 0),
34 Typeface.create(Typeface.SERIF, 1),
35 Typeface.create(Typeface.SERIF, 2),
36 Typeface.create(Typeface.SERIF, 3),
37 Typeface.create(Typeface.MONOSPACE, 0)
38 };
39
40 @SmallTest
41 public void testBasic() throws Exception {
42 assertTrue("basic", Typeface.DEFAULT != null);
43 assertTrue("basic", Typeface.DEFAULT_BOLD != null);
44 assertTrue("basic", Typeface.SANS_SERIF != null);
45 assertTrue("basic", Typeface.SERIF != null);
46 assertTrue("basic", Typeface.MONOSPACE != null);
47 }
48
49 @SmallTest
50 public void testUnique() throws Exception {
51 final int n = mFaces.length;
52 for (int i = 0; i < n; i++) {
53 for (int j = i + 1; j < n; j++) {
54 assertTrue("unique", mFaces[i] != mFaces[j]);
55 }
56 }
57 }
58
59 @SmallTest
60 public void testStyles() throws Exception {
61 assertTrue("style", mFaces[0].getStyle() == Typeface.NORMAL);
62 assertTrue("style", mFaces[1].getStyle() == Typeface.BOLD);
63 assertTrue("style", mFaces[2].getStyle() == Typeface.NORMAL);
64 assertTrue("style", mFaces[3].getStyle() == Typeface.BOLD);
65 assertTrue("style", mFaces[4].getStyle() == Typeface.ITALIC);
66 assertTrue("style", mFaces[5].getStyle() == Typeface.BOLD_ITALIC);
67 assertTrue("style", mFaces[6].getStyle() == Typeface.NORMAL);
68 }
69
70 @MediumTest
71 public void testUniformY() throws Exception {
72 Paint p = new Paint();
73 final int n = mFaces.length;
74 for (int i = 1; i <= 36; i++) {
75 p.setTextSize(i);
76 float ascent = 0;
77 float descent = 0;
78 for (int j = 0; j < n; j++) {
79 p.setTypeface(mFaces[j]);
80 Paint.FontMetrics fm = p.getFontMetrics();
81 if (j == 0) {
82 ascent = fm.ascent;
83 descent = fm.descent;
84 } else {
85 assertTrue("fontMetrics", fm.ascent == ascent);
86 assertTrue("fontMetrics", fm.descent == descent);
87 }
88 }
89 }
90 }
91
92}