ICU-2410 make max(bogus)=-1, script(bogus)=0, min(script)=0

X-SVN-Rev: 10235
This commit is contained in:
Alan Liu 2002-11-13 20:19:43 +00:00
parent 93e834a970
commit f21bcd8e05
3 changed files with 65 additions and 16 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterTest.java,v $
* $Date: 2002/10/03 23:42:02 $
* $Revision: 1.43 $
* $Date: 2002/11/13 20:19:43 $
* $Revision: 1.44 $
*
*******************************************************************************
*/
@ -1588,7 +1588,7 @@ public final class UCharacterTest extends TestFmwk
|| UCharacter.getIntPropertyMinValue(UProperty.BLOCK)
!= UCharacter.UnicodeBlock.INVALID_CODE_ID
|| UCharacter.getIntPropertyMinValue(UProperty.SCRIPT)
!= UScript.INVALID_CODE
!= 0 /* JB#2410 */
|| UCharacter.getIntPropertyMinValue(0x2345) != 0) {
errln("error: UCharacter.getIntPropertyMinValue() wrong");
}
@ -1604,7 +1604,7 @@ public final class UCharacterTest extends TestFmwk
!= UCharacter.LineBreak.COUNT - 1
|| UCharacter.getIntPropertyMaxValue(UProperty.SCRIPT)
!= UScript.CODE_LIMIT - 1
|| UCharacter.getIntPropertyMaxValue(0x2345) != 0) {
|| UCharacter.getIntPropertyMaxValue(0x2345) != -1 /*JB#2410*/ ) {
errln("error: UCharacter.getIntPropertyMaxValue() wrong");
}
@ -1767,5 +1767,57 @@ public final class UCharacterTest extends TestFmwk
}
}
}
}
/**
* Test the property values API. See JB#2410.
*/
public void TestPropertyValues() {
int i, p, min, max;
/* Min should be 0 for everything. */
/* Until JB#2478 is fixed, the one exception is UCHAR_BLOCK. */
for (p=UProperty.INT_START; p<UProperty.INT_LIMIT; ++p) {
min = UCharacter.getIntPropertyMinValue(p);
if (min != 0) {
if (p == UProperty.BLOCK) {
/* This is okay...for now. See JB#2487.
TODO Update this for JB#2487. */
} else {
String name;
name = UCharacter.getPropertyName(p, UProperty.NameChoice.LONG);
errln("FAIL: UCharacter.getIntPropertyMinValue(" + name + ") = " +
min + ", exp. 0");
}
}
}
/* Max should be -1 for invalid properties. */
max = UCharacter.getIntPropertyMaxValue(-1);
if (max != -1) {
errln("FAIL: UCharacter.getIntPropertyMaxValue(-1) = " +
max + ", exp. -1");
}
/* Script should return 0 for an invalid code point. If the API
throws an exception then that's fine too. */
for (i=0; i<2; ++i) {
try {
int script = 0;
String desc = null;
switch (i) {
case 0:
script = UScript.getScript(-1);
desc = "UScript.getScript(-1)";
break;
case 1:
script = UCharacter.getIntPropertyValue(-1, UProperty.SCRIPT);
desc = "UCharacter.getIntPropertyValue(-1, UProperty.SCRIPT)";
break;
}
if (script != 0) {
errln("FAIL: " + desc + " = " + script + ", exp. 0");
}
} catch (IllegalArgumentException e) {}
}
}
}

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/UCharacter.java,v $
* $Date: 2002/11/06 19:50:21 $
* $Revision: 1.50 $
* $Date: 2002/11/13 20:19:43 $
* $Revision: 1.51 $
*
*******************************************************************************
*/
@ -3740,7 +3740,7 @@ public final class UCharacter
* &lt; UProperty.BINARY_LIMIT or UProperty.INT_START &lt;= which
* &lt; UProperty.INT_LIMIT.
* @return Minimum value returned by UCharacter.getIntPropertyValue(int)
* for a Unicode property. Can be negative. 0 if the property
* for a Unicode property. 0 if the property
* selector is out of range.
* @see UProperty
* @see #hasBinaryProperty
@ -3754,8 +3754,6 @@ public final class UCharacter
switch (type) {
case UProperty.BLOCK:
return UnicodeBlock.INVALID_CODE.getID();
case UProperty.SCRIPT:
return UScript.INVALID_CODE;
}
return 0; // undefined; and: all other properties have a minimum value
// of 0
@ -3772,13 +3770,13 @@ public final class UCharacter
* <li> UProperty.SCRIPT: -1/45 (USCRIPT_INVALID_CODE/USCRIPT_TAGBANWA)
* <li> UProperty.IDEOGRAPHIC: 0/1 (FALSE/TRUE)
* </ul>
* For undefined UProperty constant values, both min/max values will be 0.
* For undefined UProperty constant values, min/max values will be 0/-1.
* @param which UProperty selector constant, identifies which binary
* property to check. Must be UProperty.BINARY_START &lt;= which
* &lt; UProperty.BINARY_LIMIT or UProperty.INT_START &lt;= which
* &lt; UProperty.INT_LIMIT.
* @return Maximum value returned by u_getIntPropertyValue for a Unicode property.
* 0 if the property selector is out of range.
* <= 0 if the property selector is out of range.
* @see UProperty
* @see #hasBinaryProperty
* @see #getUnicodeVersion
@ -3789,13 +3787,13 @@ public final class UCharacter
public static int getIntPropertyMaxValue(int type)
{
if (type < UProperty.BINARY_START) {
return 0; // undefined
return -1; // undefined
}
else if (type < UProperty.BINARY_LIMIT) {
return 1; // maximum TRUE for all binary properties
}
else if (type < UProperty.INT_START) {
return 0; // undefined
return -1; // undefined
}
else if (type < UProperty.INT_LIMIT) {
int max = 0;
@ -3834,7 +3832,7 @@ public final class UCharacter
return max;
}
}
return 0; // undefined
return -1; // undefined
}
// protected data members --------------------------------------------

View file

@ -154,7 +154,6 @@ public final class UScript {
* Gets the script code associated with the given codepoint.
* Returns UScript.MALAYAM given 0x0D02
* @param codepoint UChar32 codepoint
* @param err the error status code.
* @return The script code
* @exception IllegalArgumentException
* @draft