ICU-6958 Increased code coverage for com.ibm.icu.text especially adding test cases in DecompressionTest, DateIntervalFormatTest, BreakIteratorTest, and SearchTest.

X-SVN-Rev: 26232
This commit is contained in:
John Vu 2009-07-07 16:30:09 +00:00
parent 9fa22ec833
commit bbcf8411d9
6 changed files with 179 additions and 8 deletions

View file

@ -26,12 +26,14 @@ final class CollatorServiceShim extends Collator.ServiceShim {
// if (service.isDefault()) {
// return new RuleBasedCollator(locale);
// }
try {
ULocale[] actualLoc = new ULocale[1];
Collator coll = (Collator)service.get(locale, actualLoc);
if (coll == null) {
///CLOVER:OFF
//Can't really change coll after it's been initialized
throw new MissingResourceException("Could not locate Collator data", "", "");
///CLOVER:ON
}
coll = (Collator) coll.clone();
coll.setLocale(actualLoc[0], actualLoc[0]); // services make no distinction between actual & valid

View file

@ -764,7 +764,9 @@ public class DateIntervalInfo implements Cloneable, Freezable, Serializable {
other.frozen = false;
return other;
} catch ( CloneNotSupportedException e ) {
///CLOVER:OFF
throw new IllegalStateException("clone is not supported");
///CLOVER:ON
}
}

View file

@ -166,9 +166,6 @@ public class DecompressionTest extends TestFmwk {
ud.decompress(null, 0, 0, null, charValid, 0, 1);
errln("UnicodeDecompressor.decompress was suppose to return an exception.");
} catch(Exception e){}
}
}

View file

@ -22,6 +22,7 @@ import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.DateIntervalFormat;
import com.ibm.icu.text.DateIntervalInfo;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.text.DateIntervalInfo.PatternInfo;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.DateInterval;
import com.ibm.icu.util.ULocale;
@ -1024,4 +1025,107 @@ public class DateIntervalFormatTest extends com.ibm.icu.dev.test.TestFmwk {
errln("FAIL: Exception - " + e.getClass().getName());
}
}
/* Tests the method
* public boolean equals(Object a)
*/
public void TestDateIntervalInfoEquals(){
// Tests when "if ( a instanceof PatternInfo )" is false
DateIntervalInfo diia = new DateIntervalInfo();
if(diia.equals("dummy") != false){
errln("DateIntervalInfo.equals(Object a) was suppose to return " +
"false for a String object.");
}
if(diia.equals(0) != false){
errln("DateIntervalInfo.equals(Object a) was suppose to return " +
"false for an Integer object.");
}
if(diia.equals(0.0) != false){
errln("DateIntervalInfo.equals(Object a) was suppose to return " +
"false for an Integer object.");
}
if(diia.equals(new Object()) != false){
errln("DateIntervalInfo.equals(Object a) was suppose to return " +
"false for an Integer object.");
}
}
/* Tests the method
* public Object cloneAsThawed()
*/
public void TestCloseAsThawed(){
DateIntervalInfo dii = new DateIntervalInfo();
try{
dii.cloneAsThawed();
} catch(Exception e){
errln("DateIntervalInfo.closeAsThawed() was not suppose to return " +
"an exception.");
}
}
/* Tests the method
* public boolean isFrozen()
*/
public void TestIsFrozen(){
DateIntervalInfo dii = new DateIntervalInfo();
if(dii.isFrozen() != false){
errln("DateIntervalInfo.isFrozen() is suppose to return false.");
}
dii.freeze();
if(dii.isFrozen() != true){
errln("DateIntervalInfo.isFrozen() is suppose to return true.");
}
}
/* Tests the method
* public boolean clone()
*/
public void TestClone(){
DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
DateIntervalInfo dii_clone = (DateIntervalInfo) dii.clone();
dii_clone.freeze();
// Tests when "if ( frozen )" is true
if(!dii.equals(dii_clone)){
errln("DateIntervalInfo.clone() is suppose to return true for " +
"an original DateIntervalInfo object and a clone of the " +
"original DateIntervalInfo object.");
}
}
/* Tests the method
* public void setFallbackIntervalPattern(String fallbackPattern)
*/
public void TestSetFallbackIntervalPattern(){
DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
// Tests when "if ( frozen )" is true
try{
dii.freeze();
dii.setFallbackIntervalPattern("");
errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
"was suppose to return an exception for a frozen object.");
} catch (Exception e){}
// Tests when "if ( firstPatternIndex == -1 || secondPatternIndex == -1 )" is true
dii = (DateIntervalInfo) dii.cloneAsThawed();
try{
dii.setFallbackIntervalPattern("");
errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
"was suppose to return an exception for a string object of ''.");
} catch(Exception e){}
try{
dii.setFallbackIntervalPattern("0");
errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
"was suppose to return an exception for a string object of 0.");
} catch(Exception e){}
// Tests when "if ( firstPatternIndex > secondPatternIndex )" is true
dii.setFallbackIntervalPattern("{1}{0}");
if(dii.getDefaultOrder() != true)
errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " +
"was suppose to change the variable 'fFirstDateInPtnIsLaterDate' " +
"to true.");
}
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* Copyright (C) 1996-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -8,6 +8,10 @@ package com.ibm.icu.dev.test.rbbi;
import com.ibm.icu.dev.test.*;
import com.ibm.icu.text.BreakIterator;
import com.ibm.icu.text.DictionaryBasedBreakIterator;
import java.io.IOException;
import java.io.InputStream;
import java.text.StringCharacterIterator;
import java.util.Locale;
import java.util.Vector;
@ -23,7 +27,6 @@ public class BreakIteratorTest extends TestFmwk
public static void main(String[] args) throws Exception {
new BreakIteratorTest().run(args);
}
public BreakIteratorTest()
{
@ -842,5 +845,41 @@ public class BreakIteratorTest extends TestFmwk
errln("ERR: Failed to create an instance type: " + type + " / locale: " + loc + " / exception: " + e.getMessage());
}
}
}
/* Tests the constructors
* public DictionaryBasedBreakIterator(String rules, ...
* public DictionaryBasedBreakIterator(InputStream compiledRules, ...
*/
public void TestDictionaryBasedBreakIterator() throws IOException{
// The following class allows the testing of the constructor
// public DictionaryBasedBreakIterator(String rules, ...
class TestDictionaryBasedBreakIterator extends DictionaryBasedBreakIterator{
public TestDictionaryBasedBreakIterator() throws IOException{
super("",null);
}
}
try{
@SuppressWarnings("unused")
TestDictionaryBasedBreakIterator td = new TestDictionaryBasedBreakIterator();
errln("DictionaryBasedBreakIterator constructor is suppose to return an " +
"exception for an empty string.");
} catch(Exception e){}
// The following class allows the testing of the constructor
// public DictionaryBasedBreakIterator(InputStream compiledRules, ...
class TestDictionaryBasedBreakIterator1 extends DictionaryBasedBreakIterator{
public TestDictionaryBasedBreakIterator1() throws IOException{
super((InputStream)null,null);
}
}
try{
@SuppressWarnings("unused")
TestDictionaryBasedBreakIterator1 td1 = new TestDictionaryBasedBreakIterator1();
errln("DictionaryBasedBreakIterator constructor is suppose to return an " +
"exception for an null input stream.");
} catch(Exception e){}
}
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2000-2008, International Business Machines Corporation and *
* Copyright (C) 2000-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -885,6 +885,17 @@ public class SearchTest extends TestFmwk {
if (!assertEqualWithStringSearch(strsrch, COLLATOR[0])) {
errln("Error searching collator test");
}
/* Tests the method
* public void setCollator(RuleBasedCollator collator)
*/
// Tests when "if (collator == null)" is true
try{
StringSearch ss = new StringSearch(CONTRACTIONRULE, CONTRACTIONRULE);
ss.setCollator(null);
errln("StringSearch.setCollator(RuleBasedCollator collator) was " +
"suppose to return an exception for a null RuleBasedCollator");
} catch(Exception e){}
}
public void TestCollatorCanonical() {
@ -1648,6 +1659,22 @@ public class SearchTest extends TestFmwk {
if (strsrch != null) {
strsrch = null;
}
/* Tests the method
* public void setPattern(String pattern)
*/
// Tests when "if (pattern == null || pattern.length() <= 0)" is true
StringSearch ss = new StringSearch(IGNORABLERULE, IGNORABLERULE);
try{
ss.setPattern(null);
errln("StringSearch.setPattern(String pattern) is suppose to " +
"return an exception for a null parameter.");
} catch(Exception e){}
try{
ss.setPattern("");
errln("StringSearch.setPattern(String pattern) is suppose to " +
"return an exception for an empty string parameter.");
} catch(Exception e){}
}
public void TestPatternCanonical() {