001: /*
002: **********************************************************************
003: * Copyright (c) 2002-2003, International Business Machines
004: * Corporation and others. All Rights Reserved.
005: **********************************************************************
006: * Author: Alan Liu
007: * Created: November 5 2002
008: * Since: ICU 2.4
009: **********************************************************************
010: */
011: package com.ibm.icu.dev.test.lang;
012:
013: import java.io.*;
014: import com.ibm.icu.lang.*;
015: import com.ibm.icu.dev.test.TestFmwk;
016:
017: public class UPropertyAliasesTest extends TestFmwk {
018:
019: public UPropertyAliasesTest() {
020: }
021:
022: public static void main(String[] args) throws Exception {
023: new UPropertyAliasesTest().run(args);
024: }
025:
026: /**
027: * Test the property names and property value names API.
028: */
029: public void TestPropertyNames() throws IOException {
030: int p, v, choice, rev;
031: for (p = 0;; ++p) {
032: boolean sawProp = false;
033: for (choice = 0;; ++choice) {
034: String name = null;
035: try {
036: name = UCharacter.getPropertyName(p, choice);
037: if (!sawProp)
038: log("prop " + p + ":");
039: String n = (name != null) ? ("\"" + name + '"')
040: : "null";
041: log(" " + choice + "=" + n);
042: sawProp = true;
043: } catch (IllegalArgumentException e) {
044: if (choice > 0)
045: break;
046: }
047: if (name != null) {
048: /* test reverse mapping */
049: rev = UCharacter.getPropertyEnum(name);
050: if (rev != p) {
051: errln("Property round-trip failure: " + p
052: + " -> " + name + " -> " + rev);
053: }
054: }
055: }
056: if (sawProp) {
057: /* looks like a valid property; check the values */
058: String pname = UCharacter.getPropertyName(p,
059: UProperty.NameChoice.LONG);
060: int max = 0;
061: if (p == UProperty.CANONICAL_COMBINING_CLASS) {
062: max = 255;
063: } else if (p == UProperty.GENERAL_CATEGORY_MASK) {
064: /* it's far too slow to iterate all the way up to
065: the real max, U_GC_P_MASK */
066: max = 0x1000; // U_GC_NL_MASK;
067: } else if (p == UProperty.BLOCK) {
068: /* UBlockCodes, unlike other values, start at 1 */
069: max = 1;
070: }
071: logln("");
072: for (v = -1;; ++v) {
073: boolean sawValue = false;
074: for (choice = 0;; ++choice) {
075: String vname = null;
076: try {
077: vname = UCharacter.getPropertyValueName(p,
078: v, choice);
079: String n = (vname != null) ? ("\"" + vname + '"')
080: : "null";
081: if (!sawValue)
082: log(" " + pname + ", value " + v + ":");
083: log(" " + choice + "=" + n);
084: sawValue = true;
085: } catch (IllegalArgumentException e) {
086: if (choice > 0)
087: break;
088: }
089: if (vname != null) {
090: /* test reverse mapping */
091: rev = UCharacter.getPropertyValueEnum(p,
092: vname);
093: if (rev != v) {
094: errln("Value round-trip failure ("
095: + pname + "): " + v + " -> "
096: + vname + " -> " + rev);
097: }
098: }
099: }
100: if (sawValue) {
101: logln("");
102: }
103: if (!sawValue && v >= max)
104: break;
105: }
106: }
107: if (!sawProp) {
108: if (p >= UProperty.STRING_LIMIT) {
109: break;
110: } else if (p >= UProperty.DOUBLE_LIMIT) {
111: p = UProperty.STRING_START - 1;
112: } else if (p >= UProperty.MASK_LIMIT) {
113: p = UProperty.DOUBLE_START - 1;
114: } else if (p >= UProperty.INT_LIMIT) {
115: p = UProperty.MASK_START - 1;
116: } else if (p >= UProperty.BINARY_LIMIT) {
117: p = UProperty.INT_START - 1;
118: }
119: }
120: }
121:
122: int i = UCharacter
123: .getIntPropertyMinValue(UProperty.CANONICAL_COMBINING_CLASS);
124: try {
125: for (; i <= UCharacter
126: .getIntPropertyMaxValue(UProperty.CANONICAL_COMBINING_CLASS); i++) {
127: UCharacter.getPropertyValueName(
128: UProperty.CANONICAL_COMBINING_CLASS, i,
129: UProperty.NameChoice.LONG);
130: }
131: } catch (IllegalArgumentException e) {
132: errln("0x" + Integer.toHexString(i)
133: + " should have a null property value name");
134: }
135: }
136: }
|