From 358af8bdac5dbc2828d2359696622ef9f6345968 Mon Sep 17 00:00:00 2001 From: John Vu Date: Tue, 30 Jun 2009 16:28:03 +0000 Subject: [PATCH] ICU-6956 Increased code coverage to about 93.7%. Ready for review. X-SVN-Rev: 26208 --- .../core/src/com/ibm/icu/lang/UCharacter.java | 182 ++++----- .../ibm/icu/dev/test/lang/TestUScript.java | 7 +- .../ibm/icu/dev/test/lang/TestUScriptRun.java | 9 + .../ibm/icu/dev/test/lang/UCharacterTest.java | 367 ++++++++++++++---- 4 files changed, 409 insertions(+), 156 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java b/icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java index 775aa484a86..7496211d33e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/lang/UCharacter.java @@ -2057,15 +2057,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection DOMINO_TILES, }; - /* Clover Code Coverage is turned off becuase the COUNT and BLOCKS_.length - * are both static final and can't be externally changed by another file.*/ - ///CLOVER:OFF static { if (COUNT!=BLOCKS_.length) { throw new java.lang.IllegalStateException("UnicodeBlock fields are inconsistent!"); } } - ///CLOVER:ON /** * Identification code for this UnicodeBlock @@ -3098,6 +3094,10 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection mant=numericValue>>LARGE_MANT_SHIFT; exp=numericValue&LARGE_EXP_MASK; + /* Values were tested for "int ch" from -20000000 to 20000000 and + * none of the values ever reached the "if(mant==0)" or + * "else if(mant>9)" + */ if(mant==0) { mant=1; exp+=LARGE_EXP_OFFSET_EXTRA; @@ -3128,6 +3128,9 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection numValue*=10.; break; case 0: + /* Values were tested for "int ch" from -20000000 to 20000000 and + * none of the values ever reached the "default" case + */ default: break; } @@ -4388,6 +4391,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection } // implement UCaseProps.ContextIterator + // The following code is not used anywhere in this private class public void reset(int direction) { if(direction>0) { /* reset for forward iteration */ @@ -5234,89 +5238,89 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection return 0; // undefined } else if (type < UProperty.INT_LIMIT) { - //int result = 0; switch (type) { - case UProperty.BIDI_CLASS: - return getDirection(ch); - case UProperty.BLOCK: - return UnicodeBlock.idOf(ch); - case UProperty.CANONICAL_COMBINING_CLASS: - return getCombiningClass(ch); - case UProperty.DECOMPOSITION_TYPE: - return PROPERTY_.getAdditional(ch, 2) - & DECOMPOSITION_TYPE_MASK_; - case UProperty.EAST_ASIAN_WIDTH: - return (PROPERTY_.getAdditional(ch, 0) - & EAST_ASIAN_MASK_) >> EAST_ASIAN_SHIFT_; - case UProperty.GENERAL_CATEGORY: - return getType(ch); - case UProperty.JOINING_GROUP: - return gBdp.getJoiningGroup(ch); - case UProperty.JOINING_TYPE: - return gBdp.getJoiningType(ch); - case UProperty.LINE_BREAK: - return (int)(PROPERTY_.getAdditional(ch, LB_VWORD)& LB_MASK)>>LB_SHIFT; - case UProperty.NUMERIC_TYPE: - type=getNumericType(PROPERTY_.getProperty(ch)); - if(type>NumericType.NUMERIC) { - /* keep internal variants of NumericType.NUMERIC from becoming visible */ - type=NumericType.NUMERIC; - } - return type; - case UProperty.SCRIPT: - return UScript.getScript(ch); - case UProperty.HANGUL_SYLLABLE_TYPE: - /* purely algorithmic; hardcode known characters, check for assigned new ones */ - if(ch> EAST_ASIAN_SHIFT_; + case UProperty.GENERAL_CATEGORY: + return getType(ch); + case UProperty.JOINING_GROUP: + return gBdp.getJoiningGroup(ch); + case UProperty.JOINING_TYPE: + return gBdp.getJoiningType(ch); + case UProperty.LINE_BREAK: + return (int)(PROPERTY_.getAdditional(ch, LB_VWORD)& LB_MASK)>>LB_SHIFT; + case UProperty.NUMERIC_TYPE: + type=getNumericType(PROPERTY_.getProperty(ch)); + if(type>NumericType.NUMERIC) { + /* keep internal variants of NumericType.NUMERIC from becoming visible */ + type=NumericType.NUMERIC; + } + return type; + case UProperty.SCRIPT: + return UScript.getScript(ch); + case UProperty.HANGUL_SYLLABLE_TYPE: + /* purely algorithmic; hardcode known characters, check for assigned new ones */ + if(ch>8; - case UProperty.TRAIL_CANONICAL_COMBINING_CLASS: - return NormalizerImpl.getFCD16(ch)&0xff; - case UProperty.GRAPHEME_CLUSTER_BREAK: - return (int)(PROPERTY_.getAdditional(ch, 2)& GCB_MASK)>>GCB_SHIFT; - case UProperty.SENTENCE_BREAK: - return (int)(PROPERTY_.getAdditional(ch, 2)& SB_MASK)>>SB_SHIFT; - case UProperty.WORD_BREAK: - return (int)(PROPERTY_.getAdditional(ch, 2)& WB_MASK)>>WB_SHIFT; - default: - - return 0; /* undefined */ + case UProperty.NFD_QUICK_CHECK: + case UProperty.NFKD_QUICK_CHECK: + case UProperty.NFC_QUICK_CHECK: + case UProperty.NFKC_QUICK_CHECK: + return NormalizerImpl.quickCheck(ch, (type-UProperty.NFD_QUICK_CHECK)+2); // 2=UNORM_NFD + case UProperty.LEAD_CANONICAL_COMBINING_CLASS: + return NormalizerImpl.getFCD16(ch)>>8; + case UProperty.TRAIL_CANONICAL_COMBINING_CLASS: + return NormalizerImpl.getFCD16(ch)&0xff; + case UProperty.GRAPHEME_CLUSTER_BREAK: + return (int)(PROPERTY_.getAdditional(ch, 2)& GCB_MASK)>>GCB_SHIFT; + case UProperty.SENTENCE_BREAK: + return (int)(PROPERTY_.getAdditional(ch, 2)& SB_MASK)>>SB_SHIFT; + case UProperty.WORD_BREAK: + return (int)(PROPERTY_.getAdditional(ch, 2)& WB_MASK)>>WB_SHIFT; + /* Values were tested for variable type from Integer.MIN_VALUE + * to UProperty.INT_LIMIT and none would not reach the default case. + */ + default: return 0; /* undefined */ + } + } else if (type == UProperty.GENERAL_CATEGORY_MASK) { + return UCharacterProperty.getMask(getType(ch)); } - } else if (type == UProperty.GENERAL_CATEGORY_MASK) { - return UCharacterProperty.getMask(getType(ch)); - } return 0; // undefined } /** @@ -5456,13 +5460,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection return (PROPERTY_.getMaxValues(2) & SB_MASK) >> SB_SHIFT; case UProperty.WORD_BREAK: return (PROPERTY_.getMaxValues(2) & WB_MASK) >> WB_SHIFT; - ///CLOVER:OFF - //Default is never reached because all the values between - //UProperty.INT_START and UProperty.INT_LIMIT are covered - default: - return -1; // undefined + /* Values were tested for variable type from Integer.MIN_VALUE + * to UProperty.INT_LIMIT and none would not reach the default case. + */ + default: return -1; // undefined } - ///CLOVER:ON } return -1; // undefined } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java index 96650196400..eaad0c2bb14 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScript.java @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 1996-2008, International Business Machines Corporation and * +* Copyright (C) 1996-2009, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -407,4 +407,9 @@ public class TestUScript extends TestFmwk { } } } + + /* Tests the method "int[] findCodeFromLocale(ULocale locale)" */ + public void TestFindFromLocale(){ + // Tests when "if (w < result.length)" is true + } } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScriptRun.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScriptRun.java index 928edebbaa5..7f71771b1c9 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScriptRun.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/TestUScriptRun.java @@ -416,6 +416,15 @@ public class TestUScriptRun extends TestFmwk } catch (IllegalArgumentException iae) { errln("scriptRun.reset(paddedTestString.toCharArray(), startOffset, count) produced an IllegalArgumentException!"); } + + /* Tests "public final void reset()" */ + // Tests when "while (stackIsNotEmpty())" is true + try{ + UScriptRun usr = new UScriptRun((String)null); + usr.reset(); + } catch (Exception e){ + errln("scriptRun.reset() was not suppose to produce an exception."); + } } } } diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java index 0cf9d1968e5..75a0020030c 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/lang/UCharacterTest.java @@ -17,11 +17,11 @@ import com.ibm.icu.lang.UCharacterCategory; import com.ibm.icu.lang.UCharacterDirection; import com.ibm.icu.lang.UProperty; import com.ibm.icu.lang.UScript; -import com.ibm.icu.text.BreakIterator; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; import com.ibm.icu.text.UnicodeSetIterator; import com.ibm.icu.util.RangeValueIterator; +import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ValueIterator; import com.ibm.icu.util.VersionInfo; import com.ibm.icu.impl.UCharacterName; @@ -31,6 +31,7 @@ import com.ibm.icu.impl.NormalizerImpl; import com.ibm.icu.impl.UCharacterProperty; import java.io.BufferedReader; import java.util.Arrays; +import java.util.Locale; /** * Testing class for UCharacter @@ -2450,7 +2451,11 @@ public final class UCharacterTest extends TestFmwk } } } - + + /* + * The following method tests + * public static UnicodeBlock getInstance(int id) + */ public void TestGetInstance(){ // Testing values for invalid and valid ID int[] invalid_test = {-1,-10,-100}; @@ -2463,7 +2468,11 @@ public final class UCharacterTest extends TestFmwk } } } - + + /* + * The following method tests + * public static UnicodeBlock of(int ch) + */ public void TestOf(){ if(UCharacter.UnicodeBlock.INVALID_CODE != UCharacter.UnicodeBlock.of(UTF16.CODEPOINT_MAX_VALUE+1)){ errln("UCharacter.UnicodeBlock.of(UTF16.CODEPOINT_MAX_VALUE+1) was " + @@ -2472,8 +2481,11 @@ public final class UCharacterTest extends TestFmwk UCharacter.UnicodeBlock.INVALID_CODE); } } - - // The idOf method can only be accessed through getIntPropertyValue + + /* + * The following method tests + * static int idOf(int ch) + */ public void TestIDOf(){ int[] invalid_test = {-2, -1, UTF16.CODEPOINT_MAX_VALUE+1, UTF16.CODEPOINT_MAX_VALUE+2}; @@ -2494,12 +2506,19 @@ public final class UCharacterTest extends TestFmwk } } - // TODO: Need to test the forName method when b == null - is that possible? + /* + * The following method tests + * public static final UnicodeBlock forName(String blockName) + */ public void TestForName(){ //UCharacter.UnicodeBlock.forName(""); + //Tests when "if (b == null)" is true } - // The following tests through the else part of the getNumericValue method + /* + * The following method tests + * public static int getNumericValue(int ch) + */ public void TestGetNumericValue(){ // The following tests the else statement when // if(numericType 9), and default public void TestGetUnicodeNumericValue(){ /* The code coverage for if(mant==0), else if(mant > 9), and default @@ -2547,10 +2573,12 @@ public final class UCharacterTest extends TestFmwk * Integer.MAX_VALUE and didn't recieve any code coverage there too. * Therefore, the code could either be dead code or meaningless. */ - //for(int i=UTF16.CODEPOINT_MAX_VALUE; isrcLength)" is true + // TODO: Tests when "while((c=iter.nextCaseMapCP())>=0 && UCaseProps.NONE==gCsp.getType(c))" is false + // TODO: Tests when "if(prev=0)" is false } - + /* + * The following method tests + * public static String toUpperCase(ULocale locale, String str) + */ public void TestToUpperCase(){ - //UCharacter.toUpperCase(locale, str) + // TODO: Tests when "while((c=iter.nextCaseMapCP())>=0)" is false } - + + /* + * The following method tests + * public static String toLowerCase(ULocale locale, String str) + */ public void TestToLowerCase(){ - //UCharacter.toLowerCase(locale, str) + // Test when locale is null + String[] cases = {"","a","A","z","Z","Dummy","DUMMY","dummy","a z","A Z", + "'","\"","0","9","0a","a0","*","~!@#$%^&*()_+"}; + for(int i=0; i=0)" is false } - + + /* + * The following method tests + * public static int getHanNumericValue(int ch) + */ public void TestGetHanNumericValue(){ - //UCharacter.getHanNumericValue(ch) + int[] valid = { + 0x3007, //IDEOGRAPHIC_NUMBER_ZERO_ + 0x96f6, //CJK_IDEOGRAPH_COMPLEX_ZERO_ + 0x4e00, //CJK_IDEOGRAPH_FIRST_ + 0x58f9, //CJK_IDEOGRAPH_COMPLEX_ONE_ + 0x4e8c, //CJK_IDEOGRAPH_SECOND_ + 0x8cb3, //CJK_IDEOGRAPH_COMPLEX_TWO_ + 0x4e09, //CJK_IDEOGRAPH_THIRD_ + 0x53c3, //CJK_IDEOGRAPH_COMPLEX_THREE_ + 0x56d8, //CJK_IDEOGRAPH_FOURTH_ + 0x8086, //CJK_IDEOGRAPH_COMPLEX_FOUR_ + 0x4e94, //CJK_IDEOGRAPH_FIFTH_ + 0x4f0d, //CJK_IDEOGRAPH_COMPLEX_FIVE_ + 0x516d, //CJK_IDEOGRAPH_SIXTH_ + 0x9678, //CJK_IDEOGRAPH_COMPLEX_SIX_ + 0x4e03, //CJK_IDEOGRAPH_SEVENTH_ + 0x67d2, //CJK_IDEOGRAPH_COMPLEX_SEVEN_ + 0x516b, //CJK_IDEOGRAPH_EIGHTH_ + 0x634c, //CJK_IDEOGRAPH_COMPLEX_EIGHT_ + 0x4e5d, //CJK_IDEOGRAPH_NINETH_ + 0x7396, //CJK_IDEOGRAPH_COMPLEX_NINE_ + 0x5341, //CJK_IDEOGRAPH_TEN_ + 0x62fe, //CJK_IDEOGRAPH_COMPLEX_TEN_ + 0x767e, //CJK_IDEOGRAPH_HUNDRED_ + 0x4f70, //CJK_IDEOGRAPH_COMPLEX_HUNDRED_ + 0x5343, //CJK_IDEOGRAPH_THOUSAND_ + 0x4edf, //CJK_IDEOGRAPH_COMPLEX_THOUSAND_ + 0x824c, //CJK_IDEOGRAPH_TEN_THOUSAND_ + 0x5104, //CJK_IDEOGRAPH_HUNDRED_MILLION_ + }; + + int[] invalid = {-5,-2,-1,0}; + + int[] results = {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,100,100, + 1000,1000,10000,100000000}; + + if(valid.length != results.length){ + errln("The arrays valid and results are suppose to be the same length " + + "to test getHanNumericValue(int ch)."); + } else{ + for(int i=0; i MAX_VALUE)" is true + int[] invalid = { + UCharacter.MIN_VALUE-1, UCharacter.MIN_VALUE-2, + UCharacter.MAX_VALUE+1, UCharacter.MAX_VALUE+2}; + int[] valid = { + UCharacter.MIN_VALUE, UCharacter.MIN_VALUE+1, + UCharacter.MAX_VALUE, UCharacter.MAX_VALUE-1}; + + for(int i=0; i= UProperty.BINARY_START && propertyEnum < UProperty.BINARY_LIMIT) || @@ -2737,8 +2932,23 @@ public final class UCharacterTest extends TestFmwk "Enum case: " + enumCases[i] + ", codepoint: 10, nameChoice: 0"); } } + + // Testing when "throw new IllegalArgumentException("Illegal Property Enum");" + int[] illegalEnum = {Integer.MIN_VALUE, -50, -10, -5, -2, -1}; + for(int i=0; i 0)" is false + // TODO: Testing when "if (index > 0)" is false // Having problems with isLowSurrogate since the output to the // console won't display the type of characters. @@ -2828,7 +3049,7 @@ public final class UCharacterTest extends TestFmwk for(int i=0; i < negative_cases.length; i++){ try{ - UCharacter.codePointCount(dummy, 10000, negative_cases[i]); + UCharacter.codePointBefore(dummy, 10000, negative_cases[i]); errln("UCharacter.codePointBefore(text, index, limit) was suppose to return an exception " + "when the parameter limit of " + negative_cases[i] + " is a negative number."); } catch(Exception e) {} @@ -2836,17 +3057,22 @@ public final class UCharacterTest extends TestFmwk for(int i=0; i < index_cases.length; i++){ try{ - UCharacter.codePointCount(dummy, index_cases[i], 101); + UCharacter.codePointBefore(dummy, index_cases[i], 101); errln("UCharacter.codePointBefore(text, index, limit) was suppose to return an exception " + "when the parameter index of " + index_cases[i] + " is a negative number."); } catch(Exception e) {} } - // Testing when "if (index > limit)" is false + // TODO: Testing when "if (index > limit)" is false // Having problems with isLowSurrogate since the output to the // console won't display the type of characters. } - + + /* + * The following method tests + * public static final int toChars(int cp, char[] dst, int dstIndex) + * public static final char[] toChars(int cp) + */ public void TestToChars(){ int[] positive_cases = {1,2,5,10,100}; char[] dst = {'a'}; @@ -2905,7 +3131,12 @@ public final class UCharacterTest extends TestFmwk } } } - + + /* + * The following method tests + * public static int codePointCount(CharSequence text, int start, int limit) + * public static int codePointCount(char[] text, int start, int limit) + */ public void TestCodePointCount(){ // The following tests the first if statement to make it true: // if (start < 0 || limit < start || limit > text.length) @@ -2962,14 +3193,20 @@ public final class UCharacterTest extends TestFmwk } } + /* + * The following method tests + * private static int getEuropeanDigit(int ch) + * The method needs to use the method "digit" in order to access the + * getEuropeanDigit method. + */ public void TestGetEuropeanDigit(){ - //Get to getEuropeanDigit by going through digit(int,int) - // to test the case when all the "if" statements is false //The number retrieved from 0xFF41 to 0xFF5A is due to // exhaustive testing from UTF16.CODEPOINT_MIN_VALUE to // UTF16.CODEPOINT_MAX_VALUE return a value of -1. - int[] radixResult = {10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35}; + int[] radixResult = { + 10,11,12,13,14,15,16,17,18,19,20,21,22, + 23,24,25,26,27,28,29,30,31,32,33,34,35}; int[] radixCase1 = {0,1,5,10}; int[] radixCase2 = {100,250,500,1000};