]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/core/src/com/ibm/icu/dev/test/lang/UPropertyAliasesTest.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / core / src / com / ibm / icu / dev / test / lang / UPropertyAliasesTest.java
1 /*\r
2 **********************************************************************\r
3 * Copyright (c) 2002-2010, 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.dev.test.TestFmwk;\r
14 import com.ibm.icu.lang.UCharacter;\r
15 import com.ibm.icu.lang.UProperty;\r
16 \r
17 public class UPropertyAliasesTest extends TestFmwk {\r
18   \r
19     public UPropertyAliasesTest() {}\r
20     \r
21     public static void main(String[] args) throws Exception {\r
22         new UPropertyAliasesTest().run(args);\r
23     }\r
24 \r
25     /**\r
26      * Test the property names and property value names API.\r
27      */\r
28     public void TestPropertyNames() {\r
29         int p, v, choice, rev;\r
30         for (p=0; ; ++p) {\r
31             boolean sawProp = false;\r
32             for (choice=0; ; ++choice) {\r
33                 String name = null;\r
34                 try {\r
35                     name = UCharacter.getPropertyName(p, choice);\r
36                     if (!sawProp) log("prop " + p + ":");\r
37                     String n = (name != null) ? ("\"" + name + '"') : "null";\r
38                     log(" " + choice + "=" + n);\r
39                     sawProp = true;\r
40                 } catch (IllegalArgumentException e) {\r
41                     if (choice > 0) break;\r
42                 }\r
43                 if (name != null) {\r
44                     /* test reverse mapping */\r
45                     rev = UCharacter.getPropertyEnum(name);\r
46                     if (rev != p) {\r
47                         errln("Property round-trip failure: " + p + " -> " +\r
48                               name + " -> " + rev);\r
49                     }\r
50                 }\r
51             }\r
52             if (sawProp) {\r
53                 /* looks like a valid property; check the values */\r
54                 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);\r
55                 int max = 0;\r
56                 if (p == UProperty.CANONICAL_COMBINING_CLASS) {\r
57                     max = 255;\r
58                 } else if (p == UProperty.GENERAL_CATEGORY_MASK) {\r
59                     /* it's far too slow to iterate all the way up to\r
60                        the real max, U_GC_P_MASK */\r
61                     max = 0x1000; // U_GC_NL_MASK;\r
62                 } else if (p == UProperty.BLOCK) {\r
63                     /* UBlockCodes, unlike other values, start at 1 */\r
64                     max = 1;\r
65                 }\r
66                 logln("");\r
67                 for (v=-1; ; ++v) {\r
68                     boolean sawValue = false;\r
69                     for (choice=0; ; ++choice) {\r
70                         String vname = null;\r
71                         try {\r
72                             vname = UCharacter.getPropertyValueName(p, v, choice);\r
73                             String n = (vname != null) ? ("\"" + vname + '"') : "null";\r
74                             if (!sawValue) log(" " + pname + ", value " + v + ":");\r
75                             log(" " + choice + "=" + n);\r
76                             sawValue = true;\r
77                         }\r
78                         catch (IllegalArgumentException e) {\r
79                             if (choice>0) break;\r
80                         }\r
81                         if (vname != null) {\r
82                             /* test reverse mapping */\r
83                             rev = UCharacter.getPropertyValueEnum(p, vname);\r
84                             if (rev != v) {\r
85                                 errln("Value round-trip failure (" + pname +\r
86                                       "): " + v + " -> " +\r
87                                       vname + " -> " + rev);\r
88                             }\r
89                         }\r
90                     }\r
91                     if (sawValue) {\r
92                         logln("");\r
93                     }\r
94                     if (!sawValue && v>=max) break;\r
95                 }\r
96             }\r
97             if (!sawProp) {\r
98                 if (p>=UProperty.STRING_LIMIT) {\r
99                     break;\r
100                 } else if (p>=UProperty.DOUBLE_LIMIT) {\r
101                     p = UProperty.STRING_START - 1;\r
102                 } else if (p>=UProperty.MASK_LIMIT) {\r
103                     p = UProperty.DOUBLE_START - 1;\r
104                 } else if (p>=UProperty.INT_LIMIT) {\r
105                     p = UProperty.MASK_START - 1;\r
106                 } else if (p>=UProperty.BINARY_LIMIT) {\r
107                     p = UProperty.INT_START - 1;\r
108                 }\r
109             }\r
110         }\r
111         \r
112         int i = UCharacter.getIntPropertyMinValue(\r
113                                         UProperty.CANONICAL_COMBINING_CLASS);\r
114         try {\r
115             for (; i <= UCharacter.getIntPropertyMaxValue(\r
116                                           UProperty.CANONICAL_COMBINING_CLASS);\r
117                  i ++) {   \r
118                  UCharacter.getPropertyValueName(\r
119                                            UProperty.CANONICAL_COMBINING_CLASS,\r
120                                            i, UProperty.NameChoice.LONG);\r
121             }\r
122         }      \r
123         catch (IllegalArgumentException e) {\r
124             errln("0x" + Integer.toHexString(i) \r
125                   + " should have a null property value name");\r
126         }\r
127     }\r
128 }\r