2 **********************************************************************
\r
3 * Copyright (c) 2002-2007, 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.lang.*;
\r
14 import com.ibm.icu.dev.test.TestFmwk;
\r
16 public class UPropertyAliasesTest extends TestFmwk {
\r
18 public UPropertyAliasesTest() {}
\r
20 public static void main(String[] args) throws Exception {
\r
21 new UPropertyAliasesTest().run(args);
\r
25 * Test the property names and property value names API.
\r
27 public void TestPropertyNames() {
\r
28 int p, v, choice, rev;
\r
30 boolean sawProp = false;
\r
31 for (choice=0; ; ++choice) {
\r
34 name = UCharacter.getPropertyName(p, choice);
\r
35 if (!sawProp) log("prop " + p + ":");
\r
36 String n = (name != null) ? ("\"" + name + '"') : "null";
\r
37 log(" " + choice + "=" + n);
\r
39 } catch (IllegalArgumentException e) {
\r
40 if (choice > 0) break;
\r
43 /* test reverse mapping */
\r
44 rev = UCharacter.getPropertyEnum(name);
\r
46 errln("Property round-trip failure: " + p + " -> " +
\r
47 name + " -> " + rev);
\r
52 /* looks like a valid property; check the values */
\r
53 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
\r
55 if (p == UProperty.CANONICAL_COMBINING_CLASS) {
\r
57 } else if (p == UProperty.GENERAL_CATEGORY_MASK) {
\r
58 /* it's far too slow to iterate all the way up to
\r
59 the real max, U_GC_P_MASK */
\r
60 max = 0x1000; // U_GC_NL_MASK;
\r
61 } else if (p == UProperty.BLOCK) {
\r
62 /* UBlockCodes, unlike other values, start at 1 */
\r
67 boolean sawValue = false;
\r
68 for (choice=0; ; ++choice) {
\r
69 String vname = null;
\r
71 vname = UCharacter.getPropertyValueName(p, v, choice);
\r
72 String n = (vname != null) ? ("\"" + vname + '"') : "null";
\r
73 if (!sawValue) log(" " + pname + ", value " + v + ":");
\r
74 log(" " + choice + "=" + n);
\r
77 catch (IllegalArgumentException e) {
\r
78 if (choice>0) break;
\r
80 if (vname != null) {
\r
81 /* test reverse mapping */
\r
82 rev = UCharacter.getPropertyValueEnum(p, vname);
\r
84 errln("Value round-trip failure (" + pname +
\r
85 "): " + v + " -> " +
\r
86 vname + " -> " + rev);
\r
93 if (!sawValue && v>=max) break;
\r
97 if (p>=UProperty.STRING_LIMIT) {
\r
99 } else if (p>=UProperty.DOUBLE_LIMIT) {
\r
100 p = UProperty.STRING_START - 1;
\r
101 } else if (p>=UProperty.MASK_LIMIT) {
\r
102 p = UProperty.DOUBLE_START - 1;
\r
103 } else if (p>=UProperty.INT_LIMIT) {
\r
104 p = UProperty.MASK_START - 1;
\r
105 } else if (p>=UProperty.BINARY_LIMIT) {
\r
106 p = UProperty.INT_START - 1;
\r
111 int i = UCharacter.getIntPropertyMinValue(
\r
112 UProperty.CANONICAL_COMBINING_CLASS);
\r
114 for (; i <= UCharacter.getIntPropertyMaxValue(
\r
115 UProperty.CANONICAL_COMBINING_CLASS);
\r
117 UCharacter.getPropertyValueName(
\r
118 UProperty.CANONICAL_COMBINING_CLASS,
\r
119 i, UProperty.NameChoice.LONG);
\r
122 catch (IllegalArgumentException e) {
\r
123 errln("0x" + Integer.toHexString(i)
\r
124 + " should have a null property value name");
\r