File: ValidatePangoFonts.java

package info (click to toggle)
java-gnome 4.1.3-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 9,840 kB
  • sloc: java: 27,002; ansic: 4,517; perl: 1,651; python: 1,187; makefile: 136
file content (140 lines) | stat: -rw-r--r-- 4,227 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * java-gnome, a UI library for writing GTK and GNOME programs from Java!
 *
 * Copyright © 2011 Operational Dynamics Consulting, Pty Ltd
 *
 * The code in this file, and the program it is a part of, is made available
 * to you by its authors as open source software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License version
 * 2 ("GPL") as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
 *
 * You should have received a copy of the GPL along with this program. If not,
 * see http://www.gnu.org/licenses/. The authors of this program may be
 * contacted through http://java-gnome.sourceforge.net/.
 */
package org.gnome.pango;

import org.freedesktop.cairo.Format;
import org.freedesktop.cairo.ImageSurface;
import org.gnome.gtk.GraphicalTestCase;

/**
 * Test the Pango Font loading logic. This is a problematic test, since its
 * outcomes depend on the following fonts being installed: DejaVu, Corefonts,
 * Liberation, and Arkandis Gillius. FIXME None of these are "dependencies" of
 * java-gnome so this can't run by UnitTests. Any ideas?
 * 
 * @author Andrew Cowie
 */
public class ValidatePangoFonts extends GraphicalTestCase
{
    private static FontDescription loadFont(final FontDescription request) {
        final FontDescription actual;
        final Layout layout;
        final org.freedesktop.cairo.Surface surface;
        final org.freedesktop.cairo.Context cr;
        final Context context;
        final Font font;

        /*
         * Setup
         */

        surface = new ImageSurface(Format.RGB24, 100, 100);
        cr = new org.freedesktop.cairo.Context(surface);

        layout = new Layout(cr);
        context = layout.getContext();

        /*
         * Now test
         */

        font = context.loadFont(request);
        actual = font.describe();

        return actual;
    }

    /*
     * This depends on Deja Vu Sans being the actual default fallback font.
     * Can't really assume that, can we?
     */
    public final void testLoadKnownFallback() {
        final FontDescription request, actual;
        final String family;
        final Style style;

        request = new FontDescription("Deja Vu Sans");
        actual = loadFont(request);

        assertNotSame(actual, request);

        family = actual.getFamily();
        style = actual.getStyle();

        assertEquals("DejaVu Sans", family);
        assertSame(Style.NORMAL, style);
    }

    public final void testLoadWrongName() {
        final FontDescription request, actual;
        final String family;

        request = new FontDescription("Times New");
        actual = loadFont(request);

        family = actual.getFamily();

        assertEquals("DejaVu Sans", family);
    }

    /*
     * This depends on Microsoft Corefonts being installed. Not going to make
     * that a prerequisite of java-gnome, are we!
     */
    public final void testLoadCorrectName() {
        final FontDescription request, actual;
        final String family;

        request = new FontDescription("Times New Roman,");
        actual = loadFont(request);

        family = actual.getFamily();

        assertEquals("Times New Roman", family);
    }

    /*
     * This depends on Liberation being installed. Not unreasonable, but
     * again, should java-gnome depend on it? No.
     */
    public final void testLoadMinimumName() {
        final FontDescription request, actual;
        final String family;

        request = new FontDescription("Liberation Sans,");
        actual = loadFont(request);

        family = actual.getFamily();

        assertEquals("Liberation Sans", family);
    }

    public final void testLoadMinimumGilus() {
        final FontDescription request, actual;
        final String family;

        request = new FontDescription();
        request.setFamily("Gillius ADF No2 Cd");
        actual = loadFont(request);

        family = actual.getFamily();

        assertEquals("Gillius ADF No2 Cd", family);
    }
}