From f91e3e87f0cbb7facc3043c091db517758a93bc0 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Thu, 16 Jun 2005 23:03:01 +0000 Subject: [PATCH] ICU-2675 check no data X-SVN-Rev: 17928 --- .../dev/test/collator/CollationAPITest.java | 17 +++--- .../test/collator/CollationIteratorTest.java | 10 ++-- .../dev/test/collator/CollationMiscTest.java | 52 +++++++++++-------- .../test/shaping/ArabicShapingRegTest.java | 10 +++- .../dev/test/util/ICUServiceThreadTest.java | 12 ++++- icu4j/src/com/ibm/icu/text/ArabicShaping.java | 10 ++-- .../ibm/icu/text/BreakIteratorFactory.java | 4 +- .../com/ibm/icu/text/CollatorServiceShim.java | 13 ++++- .../ibm/icu/text/NumberFormatServiceShim.java | 6 ++- 9 files changed, 86 insertions(+), 48 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/collator/CollationAPITest.java b/icu4j/src/com/ibm/icu/dev/test/collator/CollationAPITest.java index ef2633d7bb4..f9f3e1fbe95 100644 --- a/icu4j/src/com/ibm/icu/dev/test/collator/CollationAPITest.java +++ b/icu4j/src/com/ibm/icu/dev/test/collator/CollationAPITest.java @@ -76,7 +76,7 @@ public class CollationAPITest extends TestFmwk { errln("Non-CollationKey comparison"); } catch (Exception e) { - logln("PASS: Non-CollationKey comparison failed as expected"); + logln("PASS: Non-CollationKey comparison failed as expected"); } if (sortk1.equals(fake)) { errln("Non-CollationKey comparison"); @@ -186,14 +186,14 @@ public class CollationAPITest extends TestFmwk { errln("Constructor taking an array and a size > array.length " + "expected to throw an exception"); } catch (IndexOutOfBoundsException e) { - logln("PASS: Constructor failed as expected"); + logln("PASS: Constructor failed as expected"); } try { key = new RawCollationKey(array, -1); errln("Constructor taking an array and a size < 0 " + "expected to throw an exception"); } catch (IndexOutOfBoundsException e) { - logln("PASS: Constructor failed as expected"); + logln("PASS: Constructor failed as expected"); } key = new RawCollationKey(array, array.length >> 1); if (key.bytes != array || key.size != (array.length >> 1)) { @@ -254,7 +254,7 @@ public class CollationAPITest extends TestFmwk { col.compare(die, test1); errln("Non-Strings should fail col.compare(Object, Object)"); } catch (Exception e) { - logln("PASS: Non-Strings comparison failed as expected"); + logln("PASS: Non-Strings comparison failed as expected"); } } @@ -572,7 +572,8 @@ public class CollationAPITest extends TestFmwk { try { col1 = new RuleBasedCollator(ruleset1); } catch (Exception e) { - errln("RuleBased Collator creation failed."); + // only first error needs to be a warning since we exit function + warnln("RuleBased Collator creation failed."); return; } @@ -588,8 +589,10 @@ public class CollationAPITest extends TestFmwk { col3 = new RuleBasedCollator(ruleset3); errln("Failure: Empty rules for the collator should fail"); return; + } catch (MissingResourceException e) { + warnln(e.getMessage()); } catch (Exception e) { - logln("PASS: Empty rules for the collator failed as expected"); + logln("PASS: Empty rules for the collator failed as expected"); } Locale locale = new Locale("aa", "AA"); @@ -737,7 +740,7 @@ public class CollationAPITest extends TestFmwk { } } } catch (Exception e) { - errln("Couldn't open collator with rules "+ rules[i]); + warnln("Couldn't open collator with rules "+ rules[i]); } } } diff --git a/icu4j/src/com/ibm/icu/dev/test/collator/CollationIteratorTest.java b/icu4j/src/com/ibm/icu/dev/test/collator/CollationIteratorTest.java index cb650457879..1ad5cf6ecc7 100644 --- a/icu4j/src/com/ibm/icu/dev/test/collator/CollationIteratorTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/collator/CollationIteratorTest.java @@ -38,7 +38,7 @@ public class CollationIteratorTest extends TestFmwk { try { c = new RuleBasedCollator("&a < b < c & ab = d"); } catch (Exception e) { - errln("Couldn't create a RuleBasedCollator."); + warnln("Couldn't create a RuleBasedCollator."); return; } @@ -95,7 +95,7 @@ public class CollationIteratorTest extends TestFmwk { try { coll = new RuleBasedCollator(rule); } catch (Exception e) { - errln("Fail to create RuleBasedCollator"); + warnln("Fail to create RuleBasedCollator"); return; } char ch = 0; @@ -609,7 +609,7 @@ public class CollationIteratorTest extends TestFmwk { } } catch (Exception e) { - errln("Error running discontiguous tests " + e.toString()); + warnln("Error running discontiguous tests " + e.toString()); } } @@ -631,7 +631,7 @@ public class CollationIteratorTest extends TestFmwk { coll = new RuleBasedCollator(rules); coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION); } catch (Exception e) { - errln("ERROR: in creation of collator using rules " + rules); + warnln("ERROR: in creation of collator using rules " + rules); return; } @@ -641,4 +641,4 @@ public class CollationIteratorTest extends TestFmwk { CollationTest.backAndForth(this, iter); } } -} \ No newline at end of file +} diff --git a/icu4j/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java b/icu4j/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java index 88f852593d1..1f59ad76126 100644 --- a/icu4j/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/collator/CollationMiscTest.java @@ -182,7 +182,7 @@ public class CollationMiscTest extends TestFmwk { // logln("Rules starter for " + rules); genericOrderingTestWithResult(coll, s, result); } catch (Exception e) { - errln("Unable to open collator with rules " + rules); + warnln("Unable to open collator with rules " + rules); } } @@ -317,7 +317,7 @@ public class CollationMiscTest extends TestFmwk { RuleBasedCollator coll = new RuleBasedCollator(string); logln("rule:" + coll.getRules()); } catch (Exception e) { - errln("Error open RuleBasedCollator rule = " + string); + warnln("Error open RuleBasedCollator rule = " + string); } } @@ -685,7 +685,7 @@ public class CollationMiscTest extends TestFmwk { try { myCollation = new RuleBasedCollator(gRules); } catch (Exception e) { - errln("ERROR: in creation of rule based collator"); + warnln("ERROR: in creation of rule based collator"); return; } // logln("Testing different case settings with custom rules"); @@ -785,7 +785,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(temp); } catch (Exception e) { - errln("fail to create RuleBasedCollator"); + warnln("fail to create RuleBasedCollator"); return; } @@ -802,7 +802,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(temp); } catch (Exception e) { - errln("fail to create RuleBasedCollator"); + warnln("fail to create RuleBasedCollator"); return; } @@ -1010,7 +1010,7 @@ public class CollationMiscTest extends TestFmwk { RuleBasedCollator coll = new RuleBasedCollator(rulez); logln("rule:" + coll.getRules()); } catch (Exception e) { - + warnln(e.getMessage()); } } @@ -1062,7 +1062,8 @@ public class CollationMiscTest extends TestFmwk { try { rbc = new RuleBasedCollator(rule[i]); } catch (Exception e) { - System.out.println(e.getMessage()); + warnln(e.getMessage()); + return; } iter1 = rbc.getCollationElementIterator("CH"); iter2 = rbc.getCollationElementIterator("\u0427"); @@ -1175,7 +1176,7 @@ public class CollationMiscTest extends TestFmwk { logln(" credundant Rule:" + ((RuleBasedCollator)credundant).getRules()); logln(" cresulting Rule:" + ((RuleBasedCollator)cresulting).getRules()); } catch (Exception e) { - errln("Cannot create RuleBasedCollator"); + warnln("Cannot create RuleBasedCollator"); } //testAgainstUCA(cresulting, credundant, "expected", TRUE, &status); // logln("testing using data\n"); @@ -1212,7 +1213,7 @@ public class CollationMiscTest extends TestFmwk { logln(" credundant Rule:" + ((RuleBasedCollator)credundant).getRules()); logln(" cresulting Rule:" + ((RuleBasedCollator)cresulting).getRules()); } catch (Exception e) { - + warnln(e.getMessage()); } // testAgainstUCA still doesn't handle expansions correctly, so this is not run // as a hard error test, but only in information mode @@ -1247,7 +1248,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(rlz); } catch (Exception e) { - errln("Unable to open collator with rules" + rules); + warnln("Unable to open collator with rules" + rules); return; } // logln("Using start of korean rules\n"); @@ -1447,7 +1448,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(rule); } catch (Exception e) { - errln("Collator creation failed " + testrules[i]); + warnln("Collator creation failed " + testrules[i]); return; } try { @@ -1555,7 +1556,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(rule); } catch (Exception e) { - errln("Collator creation failed " + testrules[i]); + warnln("Collator creation failed " + testrules[i]); return; } @@ -1575,7 +1576,7 @@ public class CollationMiscTest extends TestFmwk { try { coll = new RuleBasedCollator(rules); } catch (Exception e) { - errln("Collator creation failed " + rules); + warnln("Collator creation failed " + rules); return; } CollationTest.doTest(this, (RuleBasedCollator)coll, src, tgt, 1); @@ -1625,7 +1626,7 @@ public class CollationMiscTest extends TestFmwk { } prevrule = rule; } catch (Exception e) { - errln("Error retrieving resource bundle for testing: " + e.toString()); + warnln("Error retrieving resource bundle for testing: " + e.toString()); } } } @@ -1659,7 +1660,7 @@ public class CollationMiscTest extends TestFmwk { coll.setStrength(Collator.IDENTICAL); CollationTest.doTest(this, coll, strA, strB, 1); } catch (Exception e) { - errln(e.getMessage()); + warnln(e.getMessage()); } } @@ -1767,16 +1768,16 @@ public class CollationMiscTest extends TestFmwk { coll.setVariableTop(""); errln("Empty string should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { - logln("PASS: Empty string failed as expected"); + logln("PASS: Empty string failed as expected"); } try { coll.setVariableTop(null); errln("Null string should throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { - logln("PASS: null string failed as expected"); + logln("PASS: null string failed as expected"); } } catch (Exception e) { - errln("Error creating RuleBasedCollator"); + warnln("Error creating RuleBasedCollator"); } } @@ -1897,7 +1898,7 @@ public class CollationMiscTest extends TestFmwk { logln("Collator did not throw an exception"); } } catch (Exception e) { - errln("Error creating RuleBasedCollator with " + rule + " failed"); + warnln("Error creating RuleBasedCollator with " + rule + " failed"); } } @@ -1919,10 +1920,14 @@ public class CollationMiscTest extends TestFmwk { public void TestJ3347() { - Collator coll = Collator.getInstance(Locale.FRENCH); - ((RuleBasedCollator)coll).setAlternateHandlingShifted(true); - if (coll.compare("6", "!6") != 0) { - errln("Jitterbug 3347 failed"); + try { + Collator coll = Collator.getInstance(Locale.FRENCH); + ((RuleBasedCollator)coll).setAlternateHandlingShifted(true); + if (coll.compare("6", "!6") != 0) { + errln("Jitterbug 3347 failed"); + } + } catch (Exception e) { + warnln("Error creating UCA collator"); } } @@ -2035,6 +2040,7 @@ public class CollationMiscTest extends TestFmwk { show(MAX_INPUT, foo); } catch (Exception e) { e.printStackTrace(); + warnln(e.getMessage()); } finally { logln("End"); } diff --git a/icu4j/src/com/ibm/icu/dev/test/shaping/ArabicShapingRegTest.java b/icu4j/src/com/ibm/icu/dev/test/shaping/ArabicShapingRegTest.java index 63556cca9d8..fa5d1b0fc86 100755 --- a/icu4j/src/com/ibm/icu/dev/test/shaping/ArabicShapingRegTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/shaping/ArabicShapingRegTest.java @@ -13,6 +13,8 @@ import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.text.ArabicShaping; import com.ibm.icu.text.ArabicShapingException; +import java.util.MissingResourceException; + /** * Regression test for Arabic shaping. */ @@ -435,6 +437,9 @@ public class ArabicShapingRegTest extends TestFmwk { } public void reportTestFailure(int index, TestData test, ArabicShaping shaper, String result, Exception error) { + if (noData() && error != null && error instanceof MissingResourceException ) { + warnln(error.getMessage()); + } StringBuffer buf = new StringBuffer(); buf.append("*** test failure ***\n"); @@ -466,9 +471,10 @@ public class ArabicShapingRegTest extends TestFmwk { } private static String escapedString(String str) { - if(str==null){ - return str; + if (str == null) { + return null; } + StringBuffer buf = new StringBuffer(str.length() * 6); for (int i = 0; i < str.length(); ++i) { char ch = str.charAt(i); diff --git a/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java b/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java index 507eea939c9..629ac00c835 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2004, International Business Machines Corporation and * + * Copyright (C) 2001-2005, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.MissingResourceException; import java.util.Random; import java.util.Set; import java.util.SortedMap; @@ -81,7 +82,14 @@ public class ICUServiceThreadTest extends TestFmwk * sort the display names, and null for the matchID. */ public static SortedMap getDisplayNames(ICUService service, ULocale locale) { - Collator col = Collator.getInstance(locale); + Collator col; + try { + col = Collator.getInstance(locale); + } + catch (MissingResourceException e) { + // if no collator resources, we can't collate + col = null; + } return service.getDisplayNames(locale, col, null); } private static final Random r = new Random(); // this is a multi thread test, can't 'unrandomize' diff --git a/icu4j/src/com/ibm/icu/text/ArabicShaping.java b/icu4j/src/com/ibm/icu/text/ArabicShaping.java index fb41f53089c..63ea330c047 100755 --- a/icu4j/src/com/ibm/icu/text/ArabicShaping.java +++ b/icu4j/src/com/ibm/icu/text/ArabicShaping.java @@ -571,11 +571,11 @@ public final class ArabicShaping { char digitBase, boolean lastStrongWasAL) { UBiDiProps bdp; - try { - bdp=UBiDiProps.getSingleton(); - } catch (IOException e) { - throw new MissingResourceException(e.getMessage(),"",""); - } + try { + bdp=UBiDiProps.getSingleton(); + } catch (IOException e) { + throw new MissingResourceException(e.getMessage(), "(BidiProps)", ""); + } digitBase -= '0'; // move common adjustment out of loop for(int i = start + length; --i >= start;) { diff --git a/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java b/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java index 172e76a10ab..af07ae3fd65 100644 --- a/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java +++ b/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java @@ -119,6 +119,9 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim BreakIterator iter = null; ResourceBundle bundle = ICULocaleData.getResourceBundle("BreakIteratorRules", where); + if (bundle == null) { + throw new MissingResourceException("No ICU Data", "BreakIteratorRules", where.toString()); + } String[] classNames = bundle.getStringArray("BreakIteratorClasses"); String rules = bundle.getString(rulesName); if (classNames[kind].equals("RuleBasedBreakIterator")) { @@ -180,5 +183,4 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim iter.setLocale(uloc, uloc); return iter; } - } diff --git a/icu4j/src/com/ibm/icu/text/CollatorServiceShim.java b/icu4j/src/com/ibm/icu/text/CollatorServiceShim.java index 87ac49ea5d3..cdd8fc9c647 100644 --- a/icu4j/src/com/ibm/icu/text/CollatorServiceShim.java +++ b/icu4j/src/com/ibm/icu/text/CollatorServiceShim.java @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 2003-2004, International Business Machines Corporation and * +* Copyright (C) 2003-2005, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -8,6 +8,7 @@ package com.ibm.icu.text; import java.util.Locale; +import java.util.MissingResourceException; import java.util.Set; import com.ibm.icu.impl.ICULocaleService; @@ -31,6 +32,9 @@ final class CollatorServiceShim extends Collator.ServiceShim { try { ULocale[] actualLoc = new ULocale[1]; Collator coll = (Collator)service.get(locale, actualLoc); + if (coll == null) { + throw new MissingResourceException("Could not locate Collator data", "", ""); + } coll = (Collator) coll.clone(); coll.setLocale(actualLoc[0], actualLoc[0]); // services make no distinction between actual & valid return coll; @@ -119,7 +123,12 @@ final class CollatorServiceShim extends Collator.ServiceShim { if (actualIDReturn != null) { actualIDReturn[0] = "root"; } - return new RuleBasedCollator(ULocale.ROOT); + try { + return new RuleBasedCollator(ULocale.ROOT); + } + catch (MissingResourceException e) { + return null; + } } } private static ICULocaleService service = new CService(); diff --git a/icu4j/src/com/ibm/icu/text/NumberFormatServiceShim.java b/icu4j/src/com/ibm/icu/text/NumberFormatServiceShim.java index f35da917cca..6db62b76a30 100644 --- a/icu4j/src/com/ibm/icu/text/NumberFormatServiceShim.java +++ b/icu4j/src/com/ibm/icu/text/NumberFormatServiceShim.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2003-2004, International Business Machines Corporation and * + * Copyright (C) 2003-2005, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -9,6 +9,7 @@ package com.ibm.icu.text; import java.util.Locale; import java.util.Set; +import java.util.MissingResourceException; //import com.ibm.icu.impl.ICULocaleData; import com.ibm.icu.impl.ICUResourceBundle; @@ -86,6 +87,9 @@ class NumberFormatServiceShim extends NumberFormat.NumberFormatShim { ULocale[] actualLoc = new ULocale[1]; NumberFormat fmt = (NumberFormat)service.get(desiredLocale, choice, actualLoc); + if (fmt == null) { + throw new MissingResourceException("Unable to construct NumberFormat", "", ""); + } fmt = (NumberFormat)fmt.clone(); ULocale uloc = actualLoc[0];