From 77f7720c7533cf7d04cc1c60662dc1faf23c11a9 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Thu, 23 Feb 2006 00:35:19 +0000 Subject: [PATCH] ICU-5077 Make ICU4J Tests work on JDK 1.3 X-SVN-Rev: 19240 --- icu4j/src/com/ibm/icu/dev/test/TestFmwk.java | 16 ++++++++++++-- icu4j/src/com/ibm/icu/dev/test/TestUtil.java | 22 +++++++++++++++++-- .../test/charsetdet/TestCharsetDetector.java | 16 ++++++++++++++ .../ibm/icu/dev/test/cldr/TestCLDRVsICU.java | 7 ++++-- .../icu/dev/test/collator/RandomCollator.java | 8 ++++--- .../ibm/icu/dev/test/collator/TestAll.java | 5 ++++- .../format/GlobalizationPreferencesTest.java | 3 +-- .../dev/test/timezone/TimeZoneAliasTest.java | 6 ++++- icu4j/src/com/ibm/icu/dev/test/util/BNF.java | 5 ++++- .../ibm/icu/dev/test/util/BagFormatter.java | 5 ++++- .../dev/test/util/CollectionUtilities.java | 7 ++++-- .../dev/test/util/DataInputCompressor.java | 7 ++++-- .../dev/test/util/DataOutputCompressor.java | 8 +++++-- .../ibm/icu/dev/test/util/FileUtilities.java | 11 +++++++--- .../icu/dev/test/util/ICUPropertyFactory.java | 8 ++++--- .../com/ibm/icu/dev/test/util/TestBNF.java | 8 +++++-- .../icu/dev/test/util/TestBagFormatter.java | 7 ++++-- .../ibm/icu/dev/test/util/TestUtilities.java | 7 ++++-- .../com/ibm/icu/dev/test/util/Tokenizer.java | 8 +++++-- .../test/util/TransliteratorUtilities.java | 16 ++++++++++++-- 20 files changed, 143 insertions(+), 37 deletions(-) diff --git a/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java b/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java index e6ecfad699..ba31c44dcd 100755 --- a/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java +++ b/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java @@ -1,6 +1,7 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -26,7 +27,9 @@ import java.util.Comparator; import java.util.Locale; import java.util.MissingResourceException; import java.util.Random; - +//#ifdef FOUNDATION +//## import com.ibm.icu.impl.Utility; +//#endif /** * TestFmwk is a base class for tests that can be run conveniently from the * command line as well as under the Java test harness. @@ -60,7 +63,11 @@ public class TestFmwk extends AbstractTestLog { } } protected void handleException(Throwable e){ +//#ifndef FOUNDATION Throwable ex = e.getCause(); +//#else +//## Throwable ex = null; +//#endif if(ex==null){ ex = e; } @@ -1008,7 +1015,12 @@ public class TestFmwk extends AbstractTestLog { } public static TestParams create(String arglist, PrintWriter log) { +//#ifndef FOUNDATION return create(arglist.split("\\s"), log); +//#else +//## return create(Utility.split(arglist, '\u0020'), log); +//#endif + } /** diff --git a/icu4j/src/com/ibm/icu/dev/test/TestUtil.java b/icu4j/src/com/ibm/icu/dev/test/TestUtil.java index 6558aefe0e..a8edb77b60 100644 --- a/icu4j/src/com/ibm/icu/dev/test/TestUtil.java +++ b/icu4j/src/com/ibm/icu/dev/test/TestUtil.java @@ -1,6 +1,7 @@ +//##header /** ******************************************************************************* - * Copyright (C) 2001-2004, International Business Machines Corporation and * + * Copyright (C) 2001-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -11,6 +12,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.File; public final class TestUtil { /** @@ -61,9 +63,13 @@ public final class TestUtil { } catch (Throwable t) { IOException ex = new IOException("data resource '" + name + "' not found"); +//#ifndef FOUNDATION //initCause API was introduced in JDK 1.4 ex.initCause(t); - //t.printStackTrace(); +//#else +//## t.printStackTrace(); +//#endif + throw ex; } } @@ -231,4 +237,16 @@ public final class TestUtil { lock.go(); } + public static BufferedReader openUTF8Reader(String dir, String filename) throws IOException { + return openReader(dir,filename,"UTF-8"); + } + public static BufferedReader openReader(String dir, String filename, String encoding) throws IOException { + File file = new File(dir + filename); + return new BufferedReader( + new InputStreamReader( + new FileInputStream(file), + encoding), + 4*1024); + } + } diff --git a/icu4j/src/com/ibm/icu/dev/test/charsetdet/TestCharsetDetector.java b/icu4j/src/com/ibm/icu/dev/test/charsetdet/TestCharsetDetector.java index f32ad7af6b..21ce5be396 100644 --- a/icu4j/src/com/ibm/icu/dev/test/charsetdet/TestCharsetDetector.java +++ b/icu4j/src/com/ibm/icu/dev/test/charsetdet/TestCharsetDetector.java @@ -1,3 +1,4 @@ +//##header /** ******************************************************************************* * Copyright (C) 2005-2006, International Business Machines Corporation and * @@ -16,6 +17,9 @@ import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.impl.UTF32; import com.ibm.icu.text.*; import com.ibm.icu.util.VersionInfo; +//#ifdef FOUNDATION +//##import com.ibm.icu.impl.Utility; +//#endif import javax.xml.parsers.*; import org.w3c.dom.*; @@ -56,9 +60,13 @@ public class TestCharsetDetector extends TestFmwk throw new Exception(); } catch (Exception e) { +//#ifndef FOUNDATION StackTraceElement failPoint = e.getStackTrace()[1]; msg = "Test failure in file " + failPoint.getFileName() + " at line " + failPoint.getLineNumber(); +//#else +//## msg = "Test failure " + e.getMessage() ; +//#endif } errln(msg); } @@ -117,7 +125,11 @@ public class TestCharsetDetector extends TestFmwk private void checkEncoding(String testString, String encoding, String id) { String enc = null, lang = null; +//#ifndef FOUNDATION String[] split = encoding.split("/"); +//#else +//## String[] split = Utility.split(encoding,'/'); +//#endif enc = split[0]; @@ -343,7 +355,11 @@ public class TestCharsetDetector extends TestFmwk // Process test text with each encoding / language pair. String testString = testText.toString(); +//#ifndef FOUNDATION String[] encodingList = encodings.split(" "); +//#else +//## String[] encodingList = Utility.split(encodings, ' '); +//#endif for (int e = 0; e < encodingList.length; e += 1) { checkEncoding(testString, encodingList[e], id); diff --git a/icu4j/src/com/ibm/icu/dev/test/cldr/TestCLDRVsICU.java b/icu4j/src/com/ibm/icu/dev/test/cldr/TestCLDRVsICU.java index 20cf0e92a3..83c6126882 100644 --- a/icu4j/src/com/ibm/icu/dev/test/cldr/TestCLDRVsICU.java +++ b/icu4j/src/com/ibm/icu/dev/test/cldr/TestCLDRVsICU.java @@ -1,11 +1,13 @@ +//##header /* ********************************************************************** -* Copyright (c) 2002-2005, International Business Machines +* Copyright (c) 2002-2006, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Mark Davis ********************************************************************** */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.cldr; import java.io.File; @@ -559,4 +561,5 @@ public class TestCLDRVsICU extends TestFmwk { } }; -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/collator/RandomCollator.java b/icu4j/src/com/ibm/icu/dev/test/collator/RandomCollator.java index 64f430350a..01ccd60b4b 100644 --- a/icu4j/src/com/ibm/icu/dev/test/collator/RandomCollator.java +++ b/icu4j/src/com/ibm/icu/dev/test/collator/RandomCollator.java @@ -1,11 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ - - +//#ifndef FOUNDATION package com.ibm.icu.dev.test.collator; @@ -292,3 +292,5 @@ public class RandomCollator extends TestFmwk { }; */ } +//#endif + diff --git a/icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java b/icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java index 1a1a14e51e..f4f970dc59 100644 --- a/icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java +++ b/icu4j/src/com/ibm/icu/dev/test/collator/TestAll.java @@ -1,6 +1,7 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -40,7 +41,9 @@ public class TestAll extends TestGroup { "CollationMiscTest", "CollationChineseTest", "CollationServiceTest", +//#ifndef FOUNDATION "RandomCollator", +//#endif "UCAConformanceTest", // don't test Search API twice! //"com.ibm.icu.dev.test.search.SearchTest" diff --git a/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java b/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java index 55ee127ac7..0ac6c685de 100644 --- a/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java @@ -1,7 +1,7 @@ //##header /* ******************************************************************************* - * Copyright (C) 2004-2005, International Business Machines Corporation and * + * Copyright (C) 2004-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -14,7 +14,6 @@ import java.io.PrintWriter; import java.util.Arrays; import java.util.Date; -import com.ibm.icu.dev.test.util.BagFormatter; import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.DateFormatSymbols; import com.ibm.icu.text.SimpleDateFormat; diff --git a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java index f8d87e3a2e..d5b294dff3 100644 --- a/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/timezone/TimeZoneAliasTest.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2004, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.timezone; import java.util.ArrayList; @@ -416,3 +418,5 @@ public class TimeZoneAliasTest extends TestFmwk { } } } + +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/BNF.java b/icu4j/src/com/ibm/icu/dev/test/util/BNF.java index 685949f45c..d23edab2dc 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/BNF.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/BNF.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.util.ArrayList; @@ -320,3 +322,4 @@ public class BNF { return result; } } +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/BagFormatter.java b/icu4j/src/com/ibm/icu/dev/test/util/BagFormatter.java index 95b8677fd6..33db19b74c 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/BagFormatter.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/BagFormatter.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.io.BufferedReader; @@ -1083,3 +1085,4 @@ public class BagFormatter { this.fixName = fixName; } } +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/CollectionUtilities.java b/icu4j/src/com/ibm/icu/dev/test/util/CollectionUtilities.java index 125d07359e..7e7eba94be 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/CollectionUtilities.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/CollectionUtilities.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.util.Collection; @@ -502,4 +504,5 @@ public final class CollectionUtilities { } } -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/DataInputCompressor.java b/icu4j/src/com/ibm/icu/dev/test/util/DataInputCompressor.java index b007179ec5..8544f51284 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/DataInputCompressor.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/DataInputCompressor.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.io.DataInput; @@ -229,4 +231,5 @@ public final class DataInputCompressor implements ObjectInput { } return valuesList; } -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/DataOutputCompressor.java b/icu4j/src/com/ibm/icu/dev/test/util/DataOutputCompressor.java index e244fa35ad..544e186680 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/DataOutputCompressor.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/DataOutputCompressor.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.io.DataOutput; @@ -208,4 +210,6 @@ public final class DataOutputCompressor implements ObjectOutput { if (object_index != null) object_index.put(s, new Integer(i++)); } } -} \ No newline at end of file +} + +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/FileUtilities.java b/icu4j/src/com/ibm/icu/dev/test/util/FileUtilities.java index f338f985fc..96cd8b03f1 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/FileUtilities.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/FileUtilities.java @@ -1,10 +1,14 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ -package com.ibm.icu.dev.test.util;import java.io.BufferedReader; +//#ifndef FOUNDATION +package com.ibm.icu.dev.test.util; + +import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; @@ -71,4 +75,5 @@ public class FileUtilities { public static String anchorize(String source) { return source.toLowerCase(Locale.ENGLISH).replaceAll("\\P{L}", "_"); } -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/ICUPropertyFactory.java b/icu4j/src/com/ibm/icu/dev/test/util/ICUPropertyFactory.java index 6fc1ed7f02..c577248914 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/ICUPropertyFactory.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/ICUPropertyFactory.java @@ -1,10 +1,11 @@ - +//##header /* ******************************************************************************* - * Copyright (C) 2002-2004, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.util.ArrayList; @@ -412,4 +413,5 @@ public class ICUPropertyFactory extends UnicodeProperty.Factory { return Arrays.asList(names); } } -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TestBNF.java b/icu4j/src/com/ibm/icu/dev/test/util/TestBNF.java index 8ad6c1e4f0..e323c855cf 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TestBNF.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TestBNF.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2004, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.util.Random; @@ -237,4 +239,6 @@ public class TestBNF { } } -} \ No newline at end of file +} + +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TestBagFormatter.java b/icu4j/src/com/ibm/icu/dev/test/util/TestBagFormatter.java index 57379f3525..1d99666815 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TestBagFormatter.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TestBagFormatter.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2004, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; // TODO integrate this into the test framework @@ -240,4 +242,5 @@ public class TestBagFormatter { System.out.println(bf.showSetNames(propAlias + "with " + pattern, stuff)); } */ -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java b/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java index ce69cd987a..377e3d0471 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TestUtilities.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 1996-2005, International Business Machines Corporation and * + * Copyright (C) 1996-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.text.NumberFormat; @@ -464,4 +466,5 @@ public class TestUtilities extends TestFmwk { } } -} \ No newline at end of file +} +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/Tokenizer.java b/icu4j/src/com/ibm/icu/dev/test/util/Tokenizer.java index 0721568470..71d6ab7305 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/Tokenizer.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/Tokenizer.java @@ -1,9 +1,11 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2004, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ +//#ifndef FOUNDATION package com.ibm.icu.dev.test.util; import java.text.ParsePosition; @@ -315,4 +317,6 @@ public class Tokenizer { } } -} \ No newline at end of file +} + +//#endif diff --git a/icu4j/src/com/ibm/icu/dev/test/util/TransliteratorUtilities.java b/icu4j/src/com/ibm/icu/dev/test/util/TransliteratorUtilities.java index af60380ac7..116d28db21 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/TransliteratorUtilities.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/TransliteratorUtilities.java @@ -1,6 +1,7 @@ +//##header /* ******************************************************************************* - * Copyright (C) 2002-2005, International Business Machines Corporation and * + * Copyright (C) 2002-2006, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -11,6 +12,8 @@ import java.io.IOException; import com.ibm.icu.text.Transliterator; +import com.ibm.icu.dev.test.TestUtil; + public class TransliteratorUtilities { public static boolean DEBUG = false; @@ -42,7 +45,11 @@ public class TransliteratorUtilities { Transliterator.registerInstance(t); if (DEBUG) System.out.println("Registered new Transliterator: " + id + ", " + rid); } catch (IOException e) { +//#ifndef FOUNDATION throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id).initCause(e); +//#else +//## throw (IllegalArgumentException) new IllegalArgumentException("Can't open " + dir + ", " + id+" "+ e.getMessage()); +//#endif } } @@ -50,7 +57,11 @@ public class TransliteratorUtilities { * */ public static String getFileContents(String dir, String filename) throws IOException { +//#ifndef FOUNDATION BufferedReader br = BagFormatter.openUTF8Reader(dir, filename); +//#else +//## BufferedReader br = TestUtil.openUTF8Reader(dir, filename); +//#endif StringBuffer buffer = new StringBuffer(); while (true) { String line = br.readLine(); @@ -60,6 +71,7 @@ public class TransliteratorUtilities { } br.close(); return buffer.toString(); + } private static final String BASE_RULES = @@ -137,4 +149,4 @@ the double-quote character (") as """. "any-html", HTML_RULES_ASCII, Transliterator.FORWARD); public static final Transliterator fromHTML = Transliterator.createFromRules( "html-any", HTML_RULES, Transliterator.REVERSE); -} \ No newline at end of file +}