File: Basic.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (110 lines) | stat: -rw-r--r-- 3,822 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
/* Basic.java -- Test numeric shaper functionality
   Copyright (C) 2006 Red Hat, Inc.
This file is part of Mauve.

Mauve is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

Mauve 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 GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

*/

// Tags: JDK1.4

package gnu.testlet.java.awt.font.NumericShaper;

import java.awt.font.NumericShaper;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

public class Basic implements Testlet
{
	public String xform(String input)
	{
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < input.length(); ++i)
		{
			char c = input.charAt(i);
			if (c < ' ' || c > 0x7f)
				result.append("\\u").append(Integer.toHexString(c));
			else
				result.append(c);
		}
		return result.toString();
	}

	public void testOne(TestHarness harness, String input,
			NumericShaper shaper, String expected,
			int context)
	{
		char[] chars = input.toCharArray();
		if (context == -1)
			shaper.shape(chars, 0, chars.length);
		else
			shaper.shape(chars, 0, chars.length, context);
		// Transforming here makes the output legible in case of failure.
		harness.check(xform(new String(chars)), xform(expected));
	}

	public void test(TestHarness harness)
	{
		harness.checkPoint("non-contextual");
		NumericShaper nonc = NumericShaper.getShaper(NumericShaper.TIBETAN);
		harness.check(! nonc.isContextual());
		testOne(harness, "abc 0123", nonc,
				"abc \u0f20\u0f21\u0f22\u0f23", -1);
		testOne(harness, "abc 0123", nonc,
				"abc \u0f20\u0f21\u0f22\u0f23", NumericShaper.BENGALI);
		
		// Note that the JDK fails some of these, as ethiopic does not
		// have a digit zero.
		nonc = NumericShaper.getShaper(NumericShaper.ETHIOPIC);
		testOne(harness, "abc 0123", nonc,
				"abc 0\u1369\u136a\u136b", -1);
		testOne(harness, "abc 0123", nonc,
				"abc 0\u1369\u136a\u136b", NumericShaper.EASTERN_ARABIC);
		
		harness.checkPoint("contextual");
		NumericShaper contextualI
		  = NumericShaper.getContextualShaper(NumericShaper.KHMER
				  							  | NumericShaper.ETHIOPIC);
		NumericShaper contextualE
		  = NumericShaper.getContextualShaper(NumericShaper.KHMER
				  							  | NumericShaper.ETHIOPIC,
				  							  NumericShaper.EUROPEAN);
		harness.check(contextualE.equals(contextualI));
		harness.check(contextualE.isContextual());

		// Use built-in context.
		testOne(harness, "45", contextualE, "45", -1);
		// Explicit context.
		testOne(harness, "45", contextualE, "\u17e4\u17e5", NumericShaper.KHMER);
		// Explicit but unrecognized context.
		testOne(harness, "45", contextualE, "45", NumericShaper.ARABIC);
		// The other explicit context.
		testOne(harness, "45", contextualE, "\u136c\u136d", NumericShaper.ETHIOPIC);
		// Context from the text.  The first \\u is ethiopic, the second khmer.
		testOne(harness, "45 \u134d 045 \u1782 045", contextualI,
				"45 \u134d 0\u136c\u136d \u1782 \u17e0\u17e4\u17e5", -1);

		harness.checkPoint("arabic");
		NumericShaper arabic
		  = NumericShaper.getContextualShaper(NumericShaper.ARABIC
				  | NumericShaper.EASTERN_ARABIC);
		// According to testing, eastern arabic takes precedence here.
		testOne(harness, "\u062b 1", arabic, "\u062b \u06f1", -1);
		// This should choose eastern arabic.
		testOne(harness, "1", arabic, "\u06f1", NumericShaper.EASTERN_ARABIC);
	}
}