mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-2015 initial checkin of test for property name<->enum
X-SVN-Rev: 10169
This commit is contained in:
parent
12764fba1a
commit
9401304a6a
2 changed files with 114 additions and 2 deletions
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestAll.java,v $
|
||||
* $Date: 2002/10/28 21:59:22 $
|
||||
* $Revision: 1.41 $
|
||||
* $Date: 2002/11/06 19:50:39 $
|
||||
* $Revision: 1.42 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -128,6 +128,7 @@ public class TestAll extends TestFmwk {
|
|||
new com.ibm.icu.dev.test.lang.UCharacterIteratorTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterCategoryTest(),
|
||||
new com.ibm.icu.dev.test.lang.UCharacterDirectionTest(),
|
||||
new com.ibm.icu.dev.test.lang.UPropertyAliasesTest(),
|
||||
new com.ibm.icu.dev.test.lang.UTF16Test()
|
||||
});
|
||||
}
|
||||
|
|
111
icu4j/src/com/ibm/icu/dev/test/lang/UPropertyAliasesTest.java
Normal file
111
icu4j/src/com/ibm/icu/dev/test/lang/UPropertyAliasesTest.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2002, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
* Created: November 5 2002
|
||||
* Since: ICU 2.4
|
||||
**********************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.lang;
|
||||
|
||||
import java.io.*;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.dev.test.TestFmwk;
|
||||
|
||||
public class UPropertyAliasesTest extends TestFmwk {
|
||||
|
||||
public UPropertyAliasesTest() {}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new UPropertyAliasesTest().run(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the property names and property value names API.
|
||||
*/
|
||||
public void TestPropertyNames() throws IOException {
|
||||
int p, v, choice, rev;
|
||||
|
||||
for (p=0; ; ++p) {
|
||||
boolean sawProp = false;
|
||||
for (choice=0; ; ++choice) {
|
||||
String name = null;
|
||||
try {
|
||||
name = UCharacter.getPropertyName(p, choice);
|
||||
if (!sawProp) log("prop " + p + ":");
|
||||
String n = (name != null) ? ("\"" + name + '"') : "null";
|
||||
log(" " + choice + "=" + n);
|
||||
sawProp = true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (choice > 0) break;
|
||||
}
|
||||
if (name != null) {
|
||||
/* test reverse mapping */
|
||||
rev = UCharacter.getPropertyEnum(name);
|
||||
if (rev != p) {
|
||||
errln("Property round-trip failure: " + p + " -> " +
|
||||
name + " -> " + rev);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sawProp) {
|
||||
/* looks like a valid property; check the values */
|
||||
String pname = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
|
||||
int max = 0;
|
||||
if (p == UProperty.CANONICAL_COMBINING_CLASS) {
|
||||
max = 255;
|
||||
} else if (p == UProperty.GENERAL_CATEGORY) {
|
||||
/* it's far too slow to iterate all the way up to
|
||||
the real max, U_GC_P_MASK */
|
||||
max = 0x1000; // U_GC_NL_MASK;
|
||||
} else if (p == UProperty.BLOCK) {
|
||||
/* UBlockCodes, unlike other values, start at 1 */
|
||||
max = 1;
|
||||
}
|
||||
logln("");
|
||||
for (v=-1; ; ++v) {
|
||||
boolean sawValue = false;
|
||||
for (choice=0; ; ++choice) {
|
||||
String vname = null;
|
||||
try {
|
||||
vname = UCharacter.getPropertyValueName(p, v, choice);
|
||||
String n = (vname != null) ? ("\"" + vname + '"') : "null";
|
||||
if (!sawValue) log(" " + pname + ", value " + v + ":");
|
||||
log(" " + choice + "=" + n);
|
||||
sawValue = true;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
if (choice>0) break;
|
||||
}
|
||||
if (vname != null) {
|
||||
/* test reverse mapping */
|
||||
rev = UCharacter.getPropertyValueEnum(p, vname);
|
||||
if (rev != v) {
|
||||
errln("Value round-trip failure (" + pname +
|
||||
"): " + v + " -> " +
|
||||
vname + " -> " + rev);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sawValue) {
|
||||
logln("");
|
||||
}
|
||||
if (!sawValue && v>=max) break;
|
||||
}
|
||||
}
|
||||
if (!sawProp) {
|
||||
if (p>=UProperty.STRING_LIMIT) {
|
||||
break;
|
||||
} else if (p>=UProperty.DOUBLE_LIMIT) {
|
||||
p = UProperty.STRING_START - 1;
|
||||
} else if (p>=UProperty.INT_LIMIT) {
|
||||
p = UProperty.DOUBLE_START - 1;
|
||||
} else if (p>=UProperty.BINARY_LIMIT) {
|
||||
p = UProperty.INT_START - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue