ICU-6958 Added CLOVER:OFF for portions that test code can't touch and also increased code coverage.

X-SVN-Rev: 26318
This commit is contained in:
John Vu 2009-07-13 23:02:23 +00:00
parent d87079d337
commit 1430cc93d2
9 changed files with 116 additions and 5 deletions

View file

@ -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. *
*******************************************************************************
*/
@ -202,7 +202,9 @@ final class CollatorReader
m_dataInputStream_.skipBytes(56); // for future use
readcount += 56;
if (m_headerSize_ < readcount) {
///CLOVER:OFF
throw new IOException("Internal Error: Header size error");
///CLOVER:ON
}
m_dataInputStream_.skipBytes(m_headerSize_ - readcount);
@ -275,7 +277,9 @@ final class CollatorReader
readcount += 60;
m_dataInputStream_.skipBytes(m_optionSize_ - readcount);
if (m_optionSize_ < readcount) {
///CLOVER:OFF
throw new IOException("Internal Error: Option size error");
///CLOVER:ON
}
}
@ -448,12 +452,16 @@ final class CollatorReader
}
readcount += m_UCAValuesSize_;
if (readcount != m_size_) {
///CLOVER:OFF
throw new IOException("Internal Error: Data file size error");
///CLOVER:ON
}
return result;
}
if (readcount != m_size_) {
///CLOVER:OFF
throw new IOException("Internal Error: Data file size error");
///CLOVER:ON
}
return null;
}

View file

@ -435,9 +435,11 @@ public abstract class NumberFormat extends UFormat {
* @deprecated This API is ICU internal only.
*/
CurrencyAmount parseCurrency(String text, ParsePosition pos) {
///CLOVER:OFF
// Default implementation only -- subclasses should override
Number n = parse(text, pos);
return n == null ? null : new CurrencyAmount(n, getEffectiveCurrency());
///CLOVER:ON
}
/**

View file

@ -10,7 +10,6 @@ import java.io.IOException;
import java.text.ParsePosition;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.MissingResourceException;
import java.util.TreeSet;
@ -2788,12 +2787,14 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
int b;
// TODO: Based on the call hierarchy, polarity of 1 or 2 is never used
// so the following if statement will not be called.
///CLOVER:OFF
if (polarity == 1 || polarity == 2) {
b = LOW;
if (other[j] == LOW) { // skip base if already LOW
++j;
b = other[j];
}
///CLOVER:ON
} else {
b = other[j++];
}

View file

@ -597,10 +597,12 @@ class TransliteratorRegistry {
Spec trg,
String variant) {
String ID = TransliteratorIDParser.STVtoID(src.get(), trg.get(), variant);
///CLOVER:OFF
if (DEBUG) {
System.out.println("TransliteratorRegistry.findInDynamicStore:" +
ID);
}
///CLOVER:ON
return (Object[]) registry.get(new CaseInsensitiveString(ID));
}
@ -616,11 +618,13 @@ class TransliteratorRegistry {
private Object[] findInStaticStore(Spec src,
Spec trg,
String variant) {
///CLOVER:OFF
if (DEBUG) {
String ID = TransliteratorIDParser.STVtoID(src.get(), trg.get(), variant);
System.out.println("TransliteratorRegistry.findInStaticStore:" +
ID);
}
///CLOVER:ON
Object[] entry = null;
if (src.isLocale()) {
entry = findInBundle(src, trg, variant, Transliterator.FORWARD);
@ -708,7 +712,9 @@ class TransliteratorRegistry {
}
} catch (MissingResourceException e) {
///CLOVER:OFF
if (DEBUG) System.out.println("missing resource: " + e);
///CLOVER:ON
}
}

View file

@ -22,6 +22,7 @@ import com.ibm.icu.text.CollationElementIterator;
import com.ibm.icu.text.CollationKey;
import com.ibm.icu.text.Collator;
import com.ibm.icu.text.Normalizer;
import com.ibm.icu.text.RawCollationKey;
import com.ibm.icu.text.RuleBasedCollator;
import com.ibm.icu.text.UTF16;
import com.ibm.icu.text.CollationKey.BoundMode;
@ -2577,5 +2578,22 @@ public class CollationMiscTest extends TestFmwk {
} catch (Exception e) {
}
}
/* Test the method public int compareTo(RawCollationKey rhs) */
public void TestRawCollationKeyCompareTo(){
RawCollationKey rck = new RawCollationKey();
byte[] b = {(byte) 10, (byte) 20};
RawCollationKey rck100 = new RawCollationKey(b, 2);
if(rck.compareTo(rck) != 0){
errln("RawCollatonKey.compareTo(RawCollationKey) was suppose to return 0 " +
"for two idential RawCollationKey objects.");
}
if(rck.compareTo(rck100) == 0){
errln("RawCollatonKey.compareTo(RawCollationKey) was not suppose to return 0 " +
"for two different RawCollationKey objects.");
}
}
}

View file

@ -77,4 +77,17 @@ public class IndexCharactersTest extends TestFmwk {
logln("\t" + title + ":\t" + alreadyIn);
}
}
/* Test the method public ULocale getLocale() */
public void TestGetLocale(){
IndexCharacters ic = new IndexCharacters(new ULocale("en_US"));
if(!ic.getLocale().equals(new ULocale("en_US"))){
errln("IndexCharacter.getLocale() was suppose to return the same " +
"ULocale that was passed for the object.");
}
if(ic.getLocale().equals(new ULocale("jp_JP"))){
errln("IndexCharacter.getLocale() was not suppose to return the same " +
"ULocale that was passed for the object.");
}
}
}

View file

@ -3663,4 +3663,17 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
}
}
}
/* Tests the method public final static DateFormat getPatternInstance */
public void TestGetPatternInstance(){
//public final static DateFormat getPatternInstance(String pattern)
try{
@SuppressWarnings("unused")
DateFormat df = DateFormat.getPatternInstance("");
df = DateFormat.getPatternInstance("", new Locale("en_US"));
df = DateFormat.getPatternInstance(null, "", new Locale("en_US"));
} catch(Exception e) {
errln("DateFormat.getPatternInstance is not suppose to return an exception.");
}
}
}

View file

@ -2436,11 +2436,39 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
/*
* Tests the method public static ULocale[] getAvailableLocales()
*/
@SuppressWarnings("static-access")
public void TestGetAvailableLocales() {
// Tests when "if (shim == null)" is true
@SuppressWarnings("serial")
class TestGetAvailableLocales extends NumberFormat {
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
return null;
}
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
return null;
}
public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) {
return null;
}
public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {
return null;
}
public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {
return null;
}
public Number parse(String text, ParsePosition parsePosition) {
return null;
}
}
try {
@SuppressWarnings("unused")
Locale[] nf = NumberFormat.getAvailableLocales();
TestGetAvailableLocales test = new TestGetAvailableLocales();
test.getAvailableLocales();
} catch (Exception e) {
errln("NumberFormat.getAvailableLocales() was not suppose to "
+ "return an exception when getting getting available locales.");

View file

@ -1629,6 +1629,7 @@ public class UnicodeSetTest extends TestFmwk {
try {
actual = null;
@SuppressWarnings("unused")
UnicodeSet u = new UnicodeSet(5);
} catch (IllegalArgumentException e) {
actual = e.getClass();
@ -1637,6 +1638,7 @@ public class UnicodeSetTest extends TestFmwk {
try {
actual = null;
@SuppressWarnings("unused")
UnicodeSet u = new UnicodeSet(3, 2, 7, 9);
} catch (IllegalArgumentException e) {
actual = e.getClass();
@ -1645,6 +1647,7 @@ public class UnicodeSetTest extends TestFmwk {
try {
actual = null;
@SuppressWarnings("unused")
UnicodeSet u = new UnicodeSet(3, 5, 6, 9);
} catch (IllegalArgumentException e) {
actual = e.getClass();
@ -2322,5 +2325,24 @@ public class UnicodeSetTest extends TestFmwk {
return Utility.unescape(s);
}
/* Test the method public UnicodeSet getSet() */
public void TestGetSet() {
UnicodeSetIterator us = new UnicodeSetIterator();
try {
us.getSet();
} catch (Exception e) {
errln("UnicodeSetIterator.getSet() was not suppose to given an " + "an exception.");
}
}
/* Tests the method public UnicodeSet add(Collection<?> source) */
public void TestAddCollection() {
UnicodeSet us = new UnicodeSet();
Collection<?> s = null;
try {
us.add(s);
errln("UnicodeSet.add(Collection<?>) was suppose to return an exception for a null parameter.");
} catch (Exception e) {
}
}
}