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; 17import org.junit.runner.RunWith; 18import org.junit.runners.JUnit4; 19 20import android.icu.dev.test.TestFmwk; 21import android.icu.lang.UCharacter; 22import android.icu.lang.UProperty; 23import android.icu.testsharding.MainTestShard; 24 25@MainTestShard 26@RunWith(JUnit4.class) 27public class UPropertyAliasesTest extends TestFmwk { 28 29 public UPropertyAliasesTest() {} 30 31 /** 32 * Test the property names and property value names API. 33 */ 34 @Test 35 public void TestPropertyNames() { 36 int p, v, choice, rev; 37 for (p=0; ; ++p) { 38 boolean sawProp = false; 39 for (choice=0; ; ++choice) { 40 String name = null; 41 try { 42 name = UCharacter.getPropertyName(p, choice); 43 if (!sawProp) log("prop " + p + ":"); 44 String n = (name != null) ? ("\"" + name + '"') : "null"; 45 log(" " + choice + "=" + n); 46 sawProp = true; 47 } catch (IllegalArgumentException e) { 48 if (choice > 0) break; 49 } 50 if (name != null) { 51 /* test reverse mapping */ 52 rev = UCharacter.getPropertyEnum(name); 53 if (rev != p) { 54 errln("Property round-trip failure: " + p + " -> " + 55 name + " -> " + rev); 56 } 57 } 58 } 59 if (sawProp) { 60 /* looks like a valid property; check the values */ 61 String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG); 62 int max = 0; 63 if (p == UProperty.CANONICAL_COMBINING_CLASS) { 64 max = 255; 65 } else if (p == UProperty.GENERAL_CATEGORY_MASK) { 66 /* it's far too slow to iterate all the way up to 67 the real max, U_GC_P_MASK */ 68 max = 0x1000; // U_GC_NL_MASK; 69 } else if (p == UProperty.BLOCK) { 70 /* UBlockCodes, unlike other values, start at 1 */ 71 max = 1; 72 } 73 logln(""); 74 for (v=-1; ; ++v) { 75 boolean sawValue = false; 76 for (choice=0; ; ++choice) { 77 String vname = null; 78 try { 79 vname = UCharacter.getPropertyValueName(p, v, choice); 80 String n = (vname != null) ? ("\"" + vname + '"') : "null"; 81 if (!sawValue) log(" " + pname + ", value " + v + ":"); 82 log(" " + choice + "=" + n); 83 sawValue = true; 84 } 85 catch (IllegalArgumentException e) { 86 if (choice>0) break; 87 } 88 if (vname != null) { 89 /* test reverse mapping */ 90 rev = UCharacter.getPropertyValueEnum(p, vname); 91 if (rev != v) { 92 errln("Value round-trip failure (" + pname + 93 "): " + v + " -> " + 94 vname + " -> " + rev); 95 } 96 } 97 } 98 if (sawValue) { 99 logln(""); 100 } 101 if (!sawValue && v>=max) break; 102 } 103 } 104 if (!sawProp) { 105 if (p>=UProperty.STRING_LIMIT) { 106 break; 107 } else if (p>=UProperty.DOUBLE_LIMIT) { 108 p = UProperty.STRING_START - 1; 109 } else if (p>=UProperty.MASK_LIMIT) { 110 p = UProperty.DOUBLE_START - 1; 111 } else if (p>=UProperty.INT_LIMIT) { 112 p = UProperty.MASK_START - 1; 113 } else if (p>=UProperty.BINARY_LIMIT) { 114 p = UProperty.INT_START - 1; 115 } 116 } 117 } 118 119 int i = UCharacter.getIntPropertyMinValue( 120 UProperty.CANONICAL_COMBINING_CLASS); 121 try { 122 for (; i <= UCharacter.getIntPropertyMaxValue( 123 UProperty.CANONICAL_COMBINING_CLASS); 124 i ++) { 125 UCharacter.getPropertyValueName( 126 UProperty.CANONICAL_COMBINING_CLASS, 127 i, UProperty.NameChoice.LONG); 128 } 129 } 130 catch (IllegalArgumentException e) { 131 errln("0x" + Integer.toHexString(i) 132 + " should have a null property value name"); 133 } 134 } 135 136 @Test 137 public void TestUnknownPropertyNames() { 138 try { 139 int p = UCharacter.getPropertyEnum("??"); 140 errln("UCharacter.getPropertyEnum(??) returned " + p + 141 " rather than throwing an exception"); 142 } catch (IllegalArgumentException e) { 143 // ok 144 } 145 try { 146 int p = UCharacter.getPropertyValueEnum(UProperty.LINE_BREAK, "?!"); 147 errln("UCharacter.getPropertyValueEnum(UProperty.LINE_BREAK, ?!) returned " + p + 148 " rather than throwing an exception"); 149 } catch (IllegalArgumentException e) { 150 // ok 151 } 152 } 153} 154