2 **********************************************************************
\r
3 * Copyright (c) 2002-2010, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 **********************************************************************
\r
7 * Created: November 5 2002
\r
9 **********************************************************************
\r
11 package com.ibm.icu.dev.test.lang;
\r
13 import com.ibm.icu.dev.test.TestFmwk;
\r
14 import com.ibm.icu.lang.UCharacter;
\r
15 import com.ibm.icu.lang.UProperty;
\r
17 public class UPropertyAliasesTest extends TestFmwk {
\r
19 public UPropertyAliasesTest() {}
\r
21 public static void main(String[] args) throws Exception {
\r
22 new UPropertyAliasesTest().run(args);
\r
26 * Test the property names and property value names API.
\r
28 public void TestPropertyNames() {
\r
29 int p, v, choice, rev;
\r
31 boolean sawProp = false;
\r
32 for (choice=0; ; ++choice) {
\r
35 name = UCharacter.getPropertyName(p, choice);
\r
36 if (!sawProp) log("prop " + p + ":");
\r
37 String n = (name != null) ? ("\"" + name + '"') : "null";
\r
38 log(" " + choice + "=" + n);
\r
40 } catch (IllegalArgumentException e) {
\r
41 if (choice > 0) break;
\r
44 /* test reverse mapping */
\r
45 rev = UCharacter.getPropertyEnum(name);
\r
47 errln("Property round-trip failure: " + p + " -> " +
\r
48 name + " -> " + rev);
\r
53 /* looks like a valid property; check the values */
\r
54 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
\r
56 if (p == UProperty.CANONICAL_COMBINING_CLASS) {
\r
58 } else if (p == UProperty.GENERAL_CATEGORY_MASK) {
\r
59 /* it's far too slow to iterate all the way up to
\r
60 the real max, U_GC_P_MASK */
\r
61 max = 0x1000; // U_GC_NL_MASK;
\r
62 } else if (p == UProperty.BLOCK) {
\r
63 /* UBlockCodes, unlike other values, start at 1 */
\r
68 boolean sawValue = false;
\r
69 for (choice=0; ; ++choice) {
\r
70 String vname = null;
\r
72 vname = UCharacter.getPropertyValueName(p, v, choice);
\r
73 String n = (vname != null) ? ("\"" + vname + '"') : "null";
\r
74 if (!sawValue) log(" " + pname + ", value " + v + ":");
\r
75 log(" " + choice + "=" + n);
\r
78 catch (IllegalArgumentException e) {
\r
79 if (choice>0) break;
\r
81 if (vname != null) {
\r
82 /* test reverse mapping */
\r
83 rev = UCharacter.getPropertyValueEnum(p, vname);
\r
85 errln("Value round-trip failure (" + pname +
\r
86 "): " + v + " -> " +
\r
87 vname + " -> " + rev);
\r
94 if (!sawValue && v>=max) break;
\r
98 if (p>=UProperty.STRING_LIMIT) {
\r
100 } else if (p>=UProperty.DOUBLE_LIMIT) {
\r
101 p = UProperty.STRING_START - 1;
\r
102 } else if (p>=UProperty.MASK_LIMIT) {
\r
103 p = UProperty.DOUBLE_START - 1;
\r
104 } else if (p>=UProperty.INT_LIMIT) {
\r
105 p = UProperty.MASK_START - 1;
\r
106 } else if (p>=UProperty.BINARY_LIMIT) {
\r
107 p = UProperty.INT_START - 1;
\r
112 int i = UCharacter.getIntPropertyMinValue(
\r
113 UProperty.CANONICAL_COMBINING_CLASS);
\r
115 for (; i <= UCharacter.getIntPropertyMaxValue(
\r
116 UProperty.CANONICAL_COMBINING_CLASS);
\r
118 UCharacter.getPropertyValueName(
\r
119 UProperty.CANONICAL_COMBINING_CLASS,
\r
120 i, UProperty.NameChoice.LONG);
\r
123 catch (IllegalArgumentException e) {
\r
124 errln("0x" + Integer.toHexString(i)
\r
125 + " should have a null property value name");
\r