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