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