1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5********************************************************************** 6* Copyright (c) 2002-2010, International Business Machines 7* Corporation and others. All Rights Reserved. 8********************************************************************** 9* Author: Alan Liu 10* Created: November 5 2002 11* Since: ICU 2.4 12********************************************************************** 13*/ 14package android.icu.dev.test.lang; 15 16import org.junit.Test; 17 18import android.icu.dev.test.TestFmwk; 19import android.icu.lang.UCharacter; 20import android.icu.lang.UProperty; 21 22public class UPropertyAliasesTest extends TestFmwk { 23 24 public UPropertyAliasesTest() {} 25 26 /** 27 * Test the property names and property value names API. 28 */ 29 @Test 30 public void TestPropertyNames() { 31 int p, v, choice, rev; 32 for (p=0; ; ++p) { 33 boolean sawProp = false; 34 for (choice=0; ; ++choice) { 35 String name = null; 36 try { 37 name = UCharacter.getPropertyName(p, choice); 38 if (!sawProp) log("prop " + p + ":"); 39 String n = (name != null) ? ("\"" + name + '"') : "null"; 40 log(" " + choice + "=" + n); 41 sawProp = true; 42 } catch (IllegalArgumentException e) { 43 if (choice > 0) break; 44 } 45 if (name != null) { 46 /* test reverse mapping */ 47 rev = UCharacter.getPropertyEnum(name); 48 if (rev != p) { 49 errln("Property round-trip failure: " + p + " -> " + 50 name + " -> " + rev); 51 } 52 } 53 } 54 if (sawProp) { 55 /* looks like a valid property; check the values */ 56 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG); 57 int max = 0; 58 if (p == UProperty.CANONICAL_COMBINING_CLASS) { 59 max = 255; 60 } else if (p == UProperty.GENERAL_CATEGORY_MASK) { 61 /* it's far too slow to iterate all the way up to 62 the real max, U_GC_P_MASK */ 63 max = 0x1000; // U_GC_NL_MASK; 64 } else if (p == UProperty.BLOCK) { 65 /* UBlockCodes, unlike other values, start at 1 */ 66 max = 1; 67 } 68 logln(""); 69 for (v=-1; ; ++v) { 70 boolean sawValue = false; 71 for (choice=0; ; ++choice) { 72 String vname = null; 73 try { 74 vname = UCharacter.getPropertyValueName(p, v, choice); 75 String n = (vname != null) ? ("\"" + vname + '"') : "null"; 76 if (!sawValue) log(" " + pname + ", value " + v + ":"); 77 log(" " + choice + "=" + n); 78 sawValue = true; 79 } 80 catch (IllegalArgumentException e) { 81 if (choice>0) break; 82 } 83 if (vname != null) { 84 /* test reverse mapping */ 85 rev = UCharacter.getPropertyValueEnum(p, vname); 86 if (rev != v) { 87 errln("Value round-trip failure (" + pname + 88 "): " + v + " -> " + 89 vname + " -> " + rev); 90 } 91 } 92 } 93 if (sawValue) { 94 logln(""); 95 } 96 if (!sawValue && v>=max) break; 97 } 98 } 99 if (!sawProp) { 100 if (p>=UProperty.STRING_LIMIT) { 101 break; 102 } else if (p>=UProperty.DOUBLE_LIMIT) { 103 p = UProperty.STRING_START - 1; 104 } else if (p>=UProperty.MASK_LIMIT) { 105 p = UProperty.DOUBLE_START - 1; 106 } else if (p>=UProperty.INT_LIMIT) { 107 p = UProperty.MASK_START - 1; 108 } else if (p>=UProperty.BINARY_LIMIT) { 109 p = UProperty.INT_START - 1; 110 } 111 } 112 } 113 114 int i = UCharacter.getIntPropertyMinValue( 115 UProperty.CANONICAL_COMBINING_CLASS); 116 try { 117 for (; i <= UCharacter.getIntPropertyMaxValue( 118 UProperty.CANONICAL_COMBINING_CLASS); 119 i ++) { 120 UCharacter.getPropertyValueName( 121 UProperty.CANONICAL_COMBINING_CLASS, 122 i, UProperty.NameChoice.LONG); 123 } 124 } 125 catch (IllegalArgumentException e) { 126 errln("0x" + Integer.toHexString(i) 127 + " should have a null property value name"); 128 } 129 } 130 131 @Test 132 public void TestUnknownPropertyNames() { 133 try { 134 int p = UCharacter.getPropertyEnum("??"); 135 errln("UCharacter.getPropertyEnum(??) returned " + p + 136 " rather than throwing an exception"); 137 } catch (IllegalArgumentException e) { 138 // ok 139 } 140 try { 141 int p = UCharacter.getPropertyValueEnum(UProperty.LINE_BREAK, "?!"); 142 errln("UCharacter.getPropertyValueEnum(UProperty.LINE_BREAK, ?!) returned " + p + 143 " rather than throwing an exception"); 144 } catch (IllegalArgumentException e) { 145 // ok 146 } 147 } 148} 149