]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/tests/core/src/com/ibm/icu/dev/test/lang/UPropertyAliasesTest.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / tests / core / src / com / ibm / icu / dev / test / lang / UPropertyAliasesTest.java
1 /*
2 **********************************************************************
3 * Copyright (c) 2002-2010, International Business Machines
4 * Corporation and others.  All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: November 5 2002
8 * Since: ICU 2.4
9 **********************************************************************
10 */
11 package com.ibm.icu.dev.test.lang;
12
13 import com.ibm.icu.dev.test.TestFmwk;
14 import com.ibm.icu.lang.UCharacter;
15 import com.ibm.icu.lang.UProperty;
16
17 public class UPropertyAliasesTest extends TestFmwk {
18   
19     public UPropertyAliasesTest() {}
20     
21     public static void main(String[] args) throws Exception {
22         new UPropertyAliasesTest().run(args);
23     }
24
25     /**
26      * Test the property names and property value names API.
27      */
28     public void TestPropertyNames() {
29         int p, v, choice, rev;
30         for (p=0; ; ++p) {
31             boolean sawProp = false;
32             for (choice=0; ; ++choice) {
33                 String name = null;
34                 try {
35                     name = UCharacter.getPropertyName(p, choice);
36                     if (!sawProp) log("prop " + p + ":");
37                     String n = (name != null) ? ("\"" + name + '"') : "null";
38                     log(" " + choice + "=" + n);
39                     sawProp = true;
40                 } catch (IllegalArgumentException e) {
41                     if (choice > 0) break;
42                 }
43                 if (name != null) {
44                     /* test reverse mapping */
45                     rev = UCharacter.getPropertyEnum(name);
46                     if (rev != p) {
47                         errln("Property round-trip failure: " + p + " -> " +
48                               name + " -> " + rev);
49                     }
50                 }
51             }
52             if (sawProp) {
53                 /* looks like a valid property; check the values */
54                 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
55                 int max = 0;
56                 if (p == UProperty.CANONICAL_COMBINING_CLASS) {
57                     max = 255;
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 */
64                     max = 1;
65                 }
66                 logln("");
67                 for (v=-1; ; ++v) {
68                     boolean sawValue = false;
69                     for (choice=0; ; ++choice) {
70                         String vname = null;
71                         try {
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);
76                             sawValue = true;
77                         }
78                         catch (IllegalArgumentException e) {
79                             if (choice>0) break;
80                         }
81                         if (vname != null) {
82                             /* test reverse mapping */
83                             rev = UCharacter.getPropertyValueEnum(p, vname);
84                             if (rev != v) {
85                                 errln("Value round-trip failure (" + pname +
86                                       "): " + v + " -> " +
87                                       vname + " -> " + rev);
88                             }
89                         }
90                     }
91                     if (sawValue) {
92                         logln("");
93                     }
94                     if (!sawValue && v>=max) break;
95                 }
96             }
97             if (!sawProp) {
98                 if (p>=UProperty.STRING_LIMIT) {
99                     break;
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;
108                 }
109             }
110         }
111         
112         int i = UCharacter.getIntPropertyMinValue(
113                                         UProperty.CANONICAL_COMBINING_CLASS);
114         try {
115             for (; i <= UCharacter.getIntPropertyMaxValue(
116                                           UProperty.CANONICAL_COMBINING_CLASS);
117                  i ++) {   
118                  UCharacter.getPropertyValueName(
119                                            UProperty.CANONICAL_COMBINING_CLASS,
120                                            i, UProperty.NameChoice.LONG);
121             }
122         }      
123         catch (IllegalArgumentException e) {
124             errln("0x" + Integer.toHexString(i) 
125                   + " should have a null property value name");
126         }
127     }
128
129     public void TestUnknownPropertyNames() {
130         try {
131             int p = UCharacter.getPropertyEnum("??");
132             errln("UCharacter.getPropertyEnum(??) returned " + p +
133                   " rather than throwing an exception");
134         } catch (IllegalArgumentException e) {
135             // ok
136         }
137         try {
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) {
142             // ok
143         }
144     }
145 }