ICU-4530 Change serialization tests to use TestFmwk

X-SVN-Rev: 18712
This commit is contained in:
Eric Mader 2005-10-25 00:05:45 +00:00
parent c18d067895
commit 123c068c1d
39 changed files with 766 additions and 137 deletions

31
.gitattributes vendored
View File

@ -72,6 +72,37 @@ icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_SerbianSR.txt -text
icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_Simplified_Chinese.txt -text
icu4j/src/com/ibm/icu/dev/test/perf/data/collation/TestNames_Thai.txt -text
icu4j/src/com/ibm/icu/dev/test/rbbi/rbbitst.txt -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.impl.JDKTimeZone.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.impl.OlsonTimeZone.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.impl.TimeZoneAdapter.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.math.BigDecimal.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.math.MathContext.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.ArabicShapingException.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.ChineseDateFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.ChineseDateFormatSymbols.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.DateFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.DateFormatSymbols.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.DecimalFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.DecimalFormatSymbols.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.MessageFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.NumberFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.RuleBasedNumberFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.SimpleDateFormat.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.text.StringPrepParseException.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.BuddhistCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.Calendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.ChineseCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.CopticCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.Currency.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.EthiopicCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.GregorianCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.HebrewCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.IslamicCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.JapaneseCalendar.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.SimpleTimeZone.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.TimeZone.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.ULocale.dat -text
icu4j/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.util.UResourceTypeMismatchException.dat -text
icu4j/src/com/ibm/icu/dev/tool/docs/icu4j28.api.gz -text
icu4j/src/com/ibm/icu/dev/tool/docs/icu4j30.api.gz -text
icu4j/src/com/ibm/icu/dev/tool/docs/icu4j32.api.gz -text

View File

@ -32,7 +32,7 @@ import com.ibm.icu.util.TimeZone;
*/
public class CalendarTests
{
static class CalendarTest implements SerializableTest.Handler
static class CalendarHandler implements SerializableTest.Handler
{
public Object[] getTestObjects()
{
@ -63,7 +63,7 @@ public class CalendarTests
}
}
static class BuddhistCalendarTest extends CalendarTest
static class BuddhistCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -79,7 +79,7 @@ public class CalendarTests
}
}
static class ChineseCalendarTest extends CalendarTest
static class ChineseCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -95,7 +95,7 @@ public class CalendarTests
}
}
static class CopticCalendarTest extends CalendarTest
static class CopticCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -111,7 +111,7 @@ public class CalendarTests
}
}
static class EthiopicCalendarTest extends CalendarTest
static class EthiopicCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -127,7 +127,7 @@ public class CalendarTests
}
}
static class GregorianCalendarTest extends CalendarTest
static class GregorianCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -143,7 +143,7 @@ public class CalendarTests
}
}
static class HebrewCalendarTest extends CalendarTest
static class HebrewCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{
@ -159,7 +159,7 @@ public class CalendarTests
}
}
static class IslamicCalendarTest extends CalendarTest
static class IslamicCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects() {
Locale locales[] = SerializableTest.getLocales();
@ -174,7 +174,7 @@ public class CalendarTests
}
}
static class JapaneseCalendarTest extends CalendarTest
static class JapaneseCalendarHandler extends CalendarHandler
{
public Object[] getTestObjects()
{

View File

@ -0,0 +1,239 @@
/*
*******************************************************************************
* Copyright (C) 1996-2005, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
*/
package com.ibm.icu.dev.test.serializable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.dev.test.TestFmwk.Target;
//import com.ibm.icu.dev.test.serializable.SerializableTest;
/**
* @author emader
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CompatibilityTest extends TestFmwk
{
public class FolderTarget extends Target
{
private Target head = new Target(null);
private Target tail = head;
public FolderTarget(String name)
{
super(name);
}
public void add(String className, InputStream is)
{
HandlerTarget newTarget = new HandlerTarget(className, is);
tail.setNext(newTarget);
tail = newTarget;
}
protected boolean validate()
{
return true;
}
protected void execute() throws Exception
{
params.indentLevel += 1;
for (Target target = head.getNext(); target != null; target = target.getNext())
{
target.run();
}
params.indentLevel -= 1;
}
}
public class HandlerTarget extends Target
{
protected SerializableTest.Handler handler = null;
protected InputStream inputStream = null;
public HandlerTarget(String name, InputStream is)
{
super(name);
inputStream = is;
}
protected boolean validate()
{
handler = SerializableTest.getHandler(name);
return handler != null;
}
protected void execute() throws Exception
{
params.testCount += 1;
try {
ObjectInputStream in = new ObjectInputStream(inputStream);
Object inputObjects[] = (Object[]) in.readObject();
Object testObjects[] = handler.getTestObjects();
boolean passed = true;
in.close();
inputStream.close();
// TODO: add equality test...
// The commented out code below does that,
// but some test objects don't define an equals() method,
// and the default method is the same as the "==" operator...
for (int i = 0; i < testObjects.length; i += 1) {
// if (! inputObjects[i].equals(testObjects[i])) {
// errln("Input object " + i + " failed equality test.");
// }
if (! handler.hasSameBehavior(inputObjects[i], testObjects[i])) {
errln("Input object " + i + " failed behavior test.");
}
}
} catch (Exception e) {
errln("Exception: " + e.toString());
}
}
}
private Target getFileTargets(URL fileURL)
{
File topDir = new File(fileURL.getPath());
File dataDirs[] = topDir.listFiles();
FolderTarget target = null;
for (int d = 0; d < dataDirs.length; d += 1) {
File dataDir = dataDirs[d];
if (dataDir.isDirectory()) {
FolderTarget newTarget = new FolderTarget(dataDir.getName());
File files[] = dataDir.listFiles();
newTarget.setNext(target);
target = newTarget;
for (int i = 0; i < files.length; i += 1) {
File file = files[i];
String filename = file.getName();
int ix = filename.indexOf(".dat");
if (ix > 0) {
String className = filename.substring(0, ix);
InputStream is;
try {
is = new FileInputStream(file);
target.add(className, is);
} catch (FileNotFoundException e) {
errln("Exception: " + e.toString());
}
}
}
}
}
return target;
}
private Target getJarTargets(URL jarURL)
{
String prefix = jarURL.getPath();
String currentDir = null;
int ix = prefix.indexOf("!/");
JarFile jarFile;
FolderTarget target = null;
if (ix >= 0) {
prefix = prefix.substring(ix + 2);
}
try {
JarURLConnection conn = (JarURLConnection) jarURL.openConnection();
jarFile = conn.getJarFile();
Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry)entries.nextElement();
String name = entry.getName();
if (name.startsWith(prefix)) {
name = name.substring(prefix.length());
if (! entry.isDirectory()) {
int dx = name.lastIndexOf("/");
String dirName = name.substring(1, dx);
String filename = name.substring(dx + 1);
if (! dirName.equals(currentDir)) {
currentDir = dirName;
FolderTarget newTarget = new FolderTarget(currentDir);
newTarget.setNext(target);
target = newTarget;
}
int xx = filename.indexOf(".dat");
if (xx > 0) {
String className = filename.substring(0, xx);
target.add(className, jarFile.getInputStream(entry));
}
}
}
}
} catch (Exception e) {
errln("jar error: " + e.getMessage());
}
return target;
}
protected Target getTargets(String targetName)
{
URL dataURL = getClass().getResource("data");
String protocol = dataURL.getProtocol();
if (protocol.equals("jar")) {
return getJarTargets(dataURL);
} else if (protocol.equals("file")) {
return getFileTargets(dataURL);
} else {
errln("Don't know how to test " + dataURL.getPath());
return null;
}
}
public static void main(String[] args)
{
CompatibilityTest test = new CompatibilityTest();
test.run(args);
}
}

View File

@ -0,0 +1,197 @@
/*
*******************************************************************************
* Copyright (C) 1996-2005, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
*/
package com.ibm.icu.dev.test.serializable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
import com.ibm.icu.dev.test.TestFmwk.Target;
import com.ibm.icu.dev.test.serializable.CompatibilityTest.HandlerTarget;
import com.ibm.icu.impl.URLHandler;
/**
* @author emader
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CoverageTest extends CompatibilityTest implements URLHandler.URLVisitor
{
private static Class serializable;
static {
try {
serializable = Class.forName("java.io.Serializable");
} catch (Exception e) {
// we're in deep trouble...
System.out.println("Woops! Can't get class info for Serializable.");
}
}
private Target head = new Target(null);
private Target tail = head;
private String path;
public CoverageTest()
{
this(null);
}
public CoverageTest(String path)
{
this.path = path;
if (path != null) {
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
}
}
private void writeFile(String className, byte bytes[])
{
File file = new File(path + File.separator + className + ".dat");
FileOutputStream stream;
try {
stream = new FileOutputStream(file);
stream.write(bytes);
stream.close();
} catch (Exception e) {
System.out.print(" - can't write file!");
}
}
private void add(String className, int classModifiers, byte bytes[])
{
CoverageTarget newTarget = new CoverageTarget(className, classModifiers, bytes);
tail.setNext(newTarget);
tail = newTarget;
}
public class CoverageTarget extends HandlerTarget
{
private byte bytes[];
private int modifiers;
public CoverageTarget(String className, int classModifiers, byte bytes[])
{
super(className, bytes == null? null : new ByteArrayInputStream(bytes));
this.bytes = bytes;
modifiers = classModifiers;
}
public boolean validate()
{
return super.validate() || Modifier.isAbstract(modifiers);
}
public void execute() throws Exception
{
if (inputStream == null) {
params.testCount += 1;
} else {
Class c = Class.forName(name);
try {
Field uid = c.getDeclaredField("serialVersionUID");
} catch (Exception e) {
errln("No serialVersionUID");
}
if (path != null) {
writeFile(name, bytes);
}
super.execute();
}
}
}
public void visit(String str)
{
int ix = str.lastIndexOf(".class");
if (ix >= 0) {
String className = "com.ibm.icu" + str.substring(0, ix).replace('/', '.');
// Skip things in com.ibm.icu.dev; they're not relevant.
if (className.startsWith("com.ibm.icu.dev.")) {
return;
}
try {
Class c = Class.forName(className);
int m = c.getModifiers();
if (serializable.isAssignableFrom(c)) {
if (Modifier.isPublic(m)) {
SerializableTest.Handler handler = SerializableTest.getHandler(className);
if (handler != null) {
Object objectsOut[] = handler.getTestObjects();
Object objectsIn[];
boolean passed = true;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
try {
out.writeObject(objectsOut);
out.close();
byteOut.close();
} catch (IOException e) {
System.out.println("Eror writing test objects: " + e.toString());
return;
}
add(className, m, byteOut.toByteArray());
} else {
add(className, m, null);
}
}
}
} catch (Exception e) {
System.out.println("Error processing " + className + ": " + e.toString());
}
}
}
protected Target getTargets(String targetName)
{
URL url = getClass().getResource("/com/ibm/icu");
URLHandler handler = URLHandler.get(url);
handler.guide(this, true, false);
return head.getNext();
}
public static void main(String[] args)
{
CoverageTest test = new CoverageTest();
test.run(args);
}
}

View File

@ -22,7 +22,7 @@ import com.ibm.icu.util.UResourceTypeMismatchException;
*/
public class ExceptionTests
{
static abstract class ExceptionTest implements SerializableTest.Handler
static abstract class ExceptionHandler implements SerializableTest.Handler
{
abstract public Object[] getTestObjects();
@ -35,7 +35,7 @@ public class ExceptionTests
}
}
static class ArabicShapingExceptionTest extends ExceptionTest
static class ArabicShapingExceptionHandler extends ExceptionHandler
{
public Object[] getTestObjects()
{
@ -50,7 +50,7 @@ public class ExceptionTests
}
}
static class StringPrepParseExceptionTest extends ExceptionTest
static class StringPrepParseExceptionHandler extends ExceptionHandler
{
public Object[] getTestObjects()
{
@ -66,7 +66,7 @@ public class ExceptionTests
}
}
static class UResourceTypeMismatchExceptionTest extends ExceptionTest
static class UResourceTypeMismatchExceptionHandler extends ExceptionHandler
{
public Object[] getTestObjects()
{

View File

@ -33,7 +33,7 @@ import com.ibm.icu.util.ULocale;
public class FormatTests
{
public static class NumberFormatTest implements SerializableTest.Handler
public static class NumberFormatHandler implements SerializableTest.Handler
{
public Object[] getTestObjects()
{
@ -58,7 +58,7 @@ public class FormatTests
}
}
public static class DecimalFormatTest extends NumberFormatTest
public static class DecimalFormatHandler extends NumberFormatHandler
{
public Object[] getTestObjects()
{
@ -73,7 +73,7 @@ public class FormatTests
}
}
public static class RuleBasedNumberFormatTest extends NumberFormatTest
public static class RuleBasedNumberFormatHandler extends NumberFormatHandler
{
int types[] = {RuleBasedNumberFormat.SPELLOUT, RuleBasedNumberFormat.ORDINAL, RuleBasedNumberFormat.DURATION};
@ -93,7 +93,7 @@ public class FormatTests
}
}
public static class DecimalFormatSymbolsTest implements SerializableTest.Handler
public static class DecimalFormatSymbolsHandler implements SerializableTest.Handler
{
private char[] getCharSymbols(DecimalFormatSymbols dfs)
{
@ -153,7 +153,7 @@ public class FormatTests
}
}
public static class MessageFormatTest implements SerializableTest.Handler
public static class MessageFormatHandler implements SerializableTest.Handler
{
public Object[] getTestObjects()
{
@ -172,7 +172,7 @@ public class FormatTests
}
}
public static class DateFormatTest implements SerializableTest.Handler
public static class DateFormatHandler implements SerializableTest.Handler
{
public Object[] getTestObjects()
{
@ -197,7 +197,7 @@ public class FormatTests
}
public static class DateFormatSymbolsTest implements SerializableTest.Handler
public static class DateFormatSymbolsHandler implements SerializableTest.Handler
{
public Object[] getTestObjects()
{
@ -222,7 +222,7 @@ public class FormatTests
}
}
public static class SimpleDateFormatTest extends DateFormatTest
public static class SimpleDateFormatHandler extends DateFormatHandler
{
String patterns[] = {
"EEEE, yyyy MMMM dd",
@ -247,7 +247,7 @@ public class FormatTests
}
}
public static class ChineseDateFormatTest extends DateFormatTest
public static class ChineseDateFormatHandler extends DateFormatHandler
{
String patterns[] = {
"EEEE y'x'G-Ml-d",
@ -274,7 +274,7 @@ public class FormatTests
}
}
public static class ChineseDateFormatSymbolsTest extends DateFormatSymbolsTest
public static class ChineseDateFormatSymbolsHandler extends DateFormatSymbolsHandler
{
public Object[] getTestObjects()
{

View File

@ -8,16 +8,13 @@
package com.ibm.icu.dev.test.serializable;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.HashMap;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.impl.JDKTimeZone;
import com.ibm.icu.impl.OlsonTimeZone;
import com.ibm.icu.impl.TimeZoneAdapter;
import com.ibm.icu.math.BigDecimal;
import com.ibm.icu.math.MathContext;
import com.ibm.icu.util.Currency;
@ -31,7 +28,7 @@ import com.ibm.icu.util.ULocale;
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SerializableTest
public class SerializableTest extends TestFmwk.TestGroup
{
public interface Handler
{
@ -45,7 +42,7 @@ public class SerializableTest
return (Handler) map.get(className);
}
private static class TimeZoneTest implements Handler
private static class TimeZoneHandler implements Handler
{
String[] ZONES = { "GMT", "MET", "IST" };
@ -120,7 +117,7 @@ public class SerializableTest
return true;
}
private static class SimpleTimeZoneTest extends TimeZoneTest
private static class SimpleTimeZoneHandler extends TimeZoneHandler
{
public Object[] getTestObjects()
{
@ -150,7 +147,7 @@ public class SerializableTest
}
}
private static class ULocaleTest implements Handler
private static class ULocaleHandler implements Handler
{
public Object[] getTestObjects()
{
@ -172,7 +169,7 @@ public class SerializableTest
}
}
private static class CurrencyTest implements Handler
private static class CurrencyHandler implements Handler
{
public Object[] getTestObjects()
{
@ -195,7 +192,7 @@ public class SerializableTest
}
}
private static class OlsonTimeZoneTest implements Handler
private static class OlsonTimeZoneHandler implements Handler
{
String zoneIDs[] = {
"Pacific/Honolulu", "America/Anchorage", "America/Los_Angeles", "America/Denver",
@ -233,7 +230,77 @@ public class SerializableTest
}
}
private static class BigDecimalTest implements Handler
private static class JDKTimeZoneHandler implements Handler
{
String zoneIDs[] = {
"Pacific/Honolulu", "America/Anchorage", "America/Los_Angeles", "America/Denver",
"America/Chicago", "America/New_York", "Africa/Cairo", "Africa/Addis_Ababa", "Africa/Dar_es_Salaam",
"Africa/Freetown", "Africa/Johannesburg", "Africa/Nairobi", "Asia/Bangkok", "Asia/Baghdad",
"Asia/Calcutta", "Asia/Hong_Kong", "Asia/Jakarta", "Asia/Jerusalem", "Asia/Manila", "Asia/Tokyo",
"Europe/Amsterdam", "Europe/Athens", "Europe/Berlin", "Europe/London", "Europe/Malta", "Europe/Moscow",
"Europe/Paris", "Europe/Rome"
};
public Object[] getTestObjects()
{
JDKTimeZone timeZones[] = new JDKTimeZone[zoneIDs.length];
for (int i = 0; i < zoneIDs.length; i += 1) {
timeZones[i] = new JDKTimeZone(java.util.TimeZone.getTimeZone(zoneIDs[i]));
}
return timeZones;
}
public boolean hasSameBehavior(Object a, Object b)
{
JDKTimeZone jtz_a = (JDKTimeZone) a;
JDKTimeZone jtz_b = (JDKTimeZone) b;
long now = System.currentTimeMillis();
int a_offsets[] = {0, 0};
int b_offsets[] = {0, 0};
jtz_a.getOffset(now, false, a_offsets);
jtz_b.getOffset(now, false, b_offsets);
return a_offsets[0] == b_offsets[0] && a_offsets[1] == b_offsets[1];
}
}
private static class TimeZoneAdapterHandler implements Handler
{
String zoneIDs[] = {
"Pacific/Honolulu", "America/Anchorage", "America/Los_Angeles", "America/Denver",
"America/Chicago", "America/New_York", "Africa/Cairo", "Africa/Addis_Ababa", "Africa/Dar_es_Salaam",
"Africa/Freetown", "Africa/Johannesburg", "Africa/Nairobi", "Asia/Bangkok", "Asia/Baghdad",
"Asia/Calcutta", "Asia/Hong_Kong", "Asia/Jakarta", "Asia/Jerusalem", "Asia/Manila", "Asia/Tokyo",
"Europe/Amsterdam", "Europe/Athens", "Europe/Berlin", "Europe/London", "Europe/Malta", "Europe/Moscow",
"Europe/Paris", "Europe/Rome"
};
public Object[] getTestObjects()
{
TimeZoneAdapter timeZones[] = new TimeZoneAdapter[zoneIDs.length];
for (int i = 0; i < zoneIDs.length; i += 1) {
timeZones[i] = new TimeZoneAdapter(TimeZone.getTimeZone(zoneIDs[i]));
}
return timeZones;
}
public boolean hasSameBehavior(Object a, Object b)
{
TimeZoneAdapter tza_a = (TimeZoneAdapter) a;
TimeZoneAdapter tza_b = (TimeZoneAdapter) b;
return tza_a.hasSameRules(tza_b);
}
}
private static class BigDecimalHandler implements Handler
{
String values[] = {
"1234567890.",
@ -267,7 +334,7 @@ public class SerializableTest
}
}
private static class MathContextTest implements Handler
private static class MathContextHandler implements Handler
{
int forms[] = {MathContext.PLAIN, MathContext.ENGINEERING, MathContext.SCIENTIFIC};
int rounds[] = {
@ -305,117 +372,58 @@ public class SerializableTest
private static HashMap map = new HashMap();
static {
map.put("com.ibm.icu.util.TimeZone", new TimeZoneTest());
map.put("com.ibm.icu.util.SimpleTimeZone", new SimpleTimeZoneTest());
map.put("com.ibm.icu.util.ULocale", new ULocaleTest());
map.put("com.ibm.icu.util.Currency", new CurrencyTest());
map.put("com.ibm.icu.impl.OlsonTimeZone", new OlsonTimeZoneTest());
map.put("com.ibm.icu.math.BigDecimal", new BigDecimalTest());
map.put("com.ibm.icu.math.MathContext", new MathContextTest());
map.put("com.ibm.icu.util.TimeZone", new TimeZoneHandler());
map.put("com.ibm.icu.util.SimpleTimeZone", new SimpleTimeZoneHandler());
map.put("com.ibm.icu.util.ULocale", new ULocaleHandler());
map.put("com.ibm.icu.util.Currency", new CurrencyHandler());
map.put("com.ibm.icu.impl.JDKTimeZone", new JDKTimeZoneHandler());
map.put("com.ibm.icu.impl.OlsonTimeZone", new OlsonTimeZoneHandler());
map.put("com.ibm.icu.impl.TimeZoneAdapter", new TimeZoneAdapterHandler());
map.put("com.ibm.icu.math.BigDecimal", new BigDecimalHandler());
map.put("com.ibm.icu.math.MathContext", new MathContextHandler());
map.put("com.ibm.icu.text.NumberFormat", new FormatTests.NumberFormatTest());
map.put("com.ibm.icu.text.DecimalFormat", new FormatTests.DecimalFormatTest());
map.put("com.ibm.icu.text.RuleBasedNumberFormat", new FormatTests.RuleBasedNumberFormatTest());
map.put("com.ibm.icu.text.DecimalFormatSymbols", new FormatTests.DecimalFormatSymbolsTest());
map.put("com.ibm.icu.text.MessageFormat", new FormatTests.MessageFormatTest());
map.put("com.ibm.icu.text.DateFormat", new FormatTests.DateFormatTest());
map.put("com.ibm.icu.text.DateFormatSymbols", new FormatTests.DateFormatSymbolsTest());
map.put("com.ibm.icu.text.SimpleDateFormat", new FormatTests.SimpleDateFormatTest());
map.put("com.ibm.icu.text.ChineseDateFormat", new FormatTests.ChineseDateFormatTest());
map.put("com.ibm.icu.text.ChineseDateFormatSymbols", new FormatTests.ChineseDateFormatSymbolsTest());
map.put("com.ibm.icu.text.NumberFormat", new FormatTests.NumberFormatHandler());
map.put("com.ibm.icu.text.DecimalFormat", new FormatTests.DecimalFormatHandler());
map.put("com.ibm.icu.text.RuleBasedNumberFormat", new FormatTests.RuleBasedNumberFormatHandler());
map.put("com.ibm.icu.text.DecimalFormatSymbols", new FormatTests.DecimalFormatSymbolsHandler());
map.put("com.ibm.icu.text.MessageFormat", new FormatTests.MessageFormatHandler());
map.put("com.ibm.icu.text.DateFormat", new FormatTests.DateFormatHandler());
map.put("com.ibm.icu.text.DateFormatSymbols", new FormatTests.DateFormatSymbolsHandler());
map.put("com.ibm.icu.text.SimpleDateFormat", new FormatTests.SimpleDateFormatHandler());
map.put("com.ibm.icu.text.ChineseDateFormat", new FormatTests.ChineseDateFormatHandler());
map.put("com.ibm.icu.text.ChineseDateFormatSymbols", new FormatTests.ChineseDateFormatSymbolsHandler());
map.put("com.ibm.icu.util.Calendar", new CalendarTests.CalendarTest());
map.put("com.ibm.icu.util.BuddhistCalendar", new CalendarTests.BuddhistCalendarTest());
map.put("com.ibm.icu.util.ChineseCalendar", new CalendarTests.ChineseCalendarTest());
map.put("com.ibm.icu.util.CopticCalendar", new CalendarTests.CopticCalendarTest());
map.put("com.ibm.icu.util.EthiopicCalendar", new CalendarTests.EthiopicCalendarTest());
map.put("com.ibm.icu.util.GregorianCalendar", new CalendarTests.GregorianCalendarTest());
map.put("com.ibm.icu.util.HebrewCalendar", new CalendarTests.HebrewCalendarTest());
map.put("com.ibm.icu.util.IslamicCalendar", new CalendarTests.IslamicCalendarTest());
map.put("com.ibm.icu.util.JapaneseCalendar", new CalendarTests.JapaneseCalendarTest());
map.put("com.ibm.icu.util.Calendar", new CalendarTests.CalendarHandler());
map.put("com.ibm.icu.util.BuddhistCalendar", new CalendarTests.BuddhistCalendarHandler());
map.put("com.ibm.icu.util.ChineseCalendar", new CalendarTests.ChineseCalendarHandler());
map.put("com.ibm.icu.util.CopticCalendar", new CalendarTests.CopticCalendarHandler());
map.put("com.ibm.icu.util.EthiopicCalendar", new CalendarTests.EthiopicCalendarHandler());
map.put("com.ibm.icu.util.GregorianCalendar", new CalendarTests.GregorianCalendarHandler());
map.put("com.ibm.icu.util.HebrewCalendar", new CalendarTests.HebrewCalendarHandler());
map.put("com.ibm.icu.util.IslamicCalendar", new CalendarTests.IslamicCalendarHandler());
map.put("com.ibm.icu.util.JapaneseCalendar", new CalendarTests.JapaneseCalendarHandler());
map.put("com.ibm.icu.text.ArabicShapingException", new ExceptionTests.ArabicShapingExceptionTest());
map.put("com.ibm.icu.text.StringPrepParseException", new ExceptionTests.StringPrepParseExceptionTest());
map.put("com.ibm.icu.util.UResourceTypeMismatchException", new ExceptionTests.UResourceTypeMismatchExceptionTest());
map.put("com.ibm.icu.text.ArabicShapingException", new ExceptionTests.ArabicShapingExceptionHandler());
map.put("com.ibm.icu.text.StringPrepParseException", new ExceptionTests.StringPrepParseExceptionHandler());
map.put("com.ibm.icu.util.UResourceTypeMismatchException", new ExceptionTests.UResourceTypeMismatchExceptionHandler());
}
public void testDirectory(File dir)
public SerializableTest()
{
File files[] = dir.listFiles();
for (int i = 0; i < files.length; i += 1) {
check(files[i]);
}
super(
new String[] {
"com.ibm.icu.dev.test.serializable.CoverageTest",
"com.ibm.icu.dev.test.serializable.CompatibilityTest"},
"All Serializable Tests"
);
}
public void check(File file)
{
String filename = file.getName();
int ix = filename.lastIndexOf(".dat");
if (ix < 0) {
return;
}
String className = filename.substring(0, ix);
Handler handler = getHandler(className);
System.out.print(className + " - ");
if (handler == null) {
System.out.println("no test.");
return;
}
try {
FileInputStream fs = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fs);
Object inputObjects[] = (Object[]) in.readObject();
Object testObjects[] = handler.getTestObjects();
boolean passed = true;
in.close();
fs.close();
// TODO: add equality test...
for (int i = 0; i < testObjects.length; i += 1) {
if (! handler.hasSameBehavior(inputObjects[i], testObjects[i])) {
passed = false;
System.out.println("Input object " + i + " failed behavior test.");
}
}
if (passed) {
System.out.println("test passed.");
}
} catch (Exception e) {
System.out.println("Error processing test object: " + e.toString());
}
}
public static final String CLASS_TARGET_NAME = "Serializable";
public static void main(String[] args)
{
SerializableTest test = new SerializableTest();
List argList = Arrays.asList(args);
boolean write = false;
for (Iterator it = argList.iterator(); it.hasNext(); /*anything?*/) {
String arg = (String) it.next();
try {
File dir = new File(arg);
if (! dir.isDirectory()) {
System.out.println(dir + " is not a directory.");
continue;
}
System.out.println("Checking test data from " + arg + ":");
test.testDirectory(dir);
} catch (Exception e) {
System.out.println("Error processing " + arg + ": " + e.getMessage());
}
}
test.run(args);
}
}

View File

@ -0,0 +1,61 @@
/*
*******************************************************************************
* Copyright (C) 1996-2005, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
*/
package com.ibm.icu.dev.test.serializable;
import com.ibm.icu.util.VersionInfo;
import java.net.URL;
/**
* This class writes the test objects for each class to a file. The work is
* actually done by the superclass, CoverageTest. This class just constructs
* a CoverageTest w/ a non-null path, which tells it to write the data.
*
*/
public class SerializableWriter extends CoverageTest
{
public SerializableWriter(String path)
{
super(path);
}
private static String folderName()
{
int major = VersionInfo.ICU_VERSION.getMajor();
int minor = VersionInfo.ICU_VERSION.getMinor();
int milli = VersionInfo.ICU_VERSION.getMilli();
int micro = VersionInfo.ICU_VERSION.getMicro();
StringBuffer result = new StringBuffer("ICU_");
result.append(major);
result.append(".");
result.append(minor);
if (milli != 0 || micro != 0) {
result.append(".");
result.append(milli);
if (micro != 0) {
result.append(".");
result.append(micro);
}
}
return result.toString();
}
public static void main(String[] args)
{
URL dataURL = SerializableWriter.class.getResource("data");
CoverageTest test = new SerializableWriter(dataURL.getPath() + "/" + folderName());
test.run(args);
}
}

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:82d7e3bd7e5134fabbe563ab807e70aedbf820dbaaf21449be924106adcdf49e
size 977

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:50cb755d73d0fa27e12e5bfdd8aa9dfde44647aeaf07c8c5ba378ebdd2550c15
size 12143

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b512c132f5e16a02192f3d2d01802cc3e3a36527cc47c0d674393ce4ff9c0d4a
size 12576

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f98076a5c5a606c20e2a049bdcf0ab2e615c54ee8e54d5757fb5c098b90d1273
size 520

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:57a0769d52aeb561113d877592e03a42106ea2a80ec7b59ebb812deb7788c170
size 595

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:85080987b76bbe950592d735125d1526dd68d2b538466bdcf06d827ba0fcf31d
size 6733

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d9652c40edd317bc72f21786b61ee7e37137957a861ad8f5c51af7b26da3c760
size 181997

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:026cebad3937dacb0f55f6efd24a3d7db7cfa412900a21530b2e09c3104fe987
size 26103

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8a09e5c6db4fe2deddf184cbc1698a9e4e1c00974faf7aba54b51834ee40e456
size 48391

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:779e20204f5f6a3b379465e335a75d0cff6ade0d77f0fbee1f12b43488c8c25a
size 25664

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2122124de82ddc63b662abbcd0b3b8c18c04b775550578a574fe696d0e978b7c
size 6664

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:26aef5c5eda1e07b967f08d00060f00b07a34b6a4829014ed0f33ae7663d1c21
size 3173

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7fb0b44db5ed3fee64df4250fbe550115d24c24494e905504788cb1979e48dd4
size 641

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c7920d829dfcd660cf5d3e8d3be3f9f96d646cd0348b13abd80c4f133989a63a
size 2822

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c0ade9d61c148a1dc9d4a728f01d10c94c151ef7954f1435f9fc0703d5490f20
size 53989

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1b9187f3594a6b31451e6958c13151bb24c49b5340db2bc33b95dd74f5c44fb4
size 177272

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:11ce2fd0fee67d510bc04f081133d34d056e822ad53508f2ed7ba6b2d6816551
size 11226

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8269df16e1ed47a906513af71d8615b3e710ae007492c34d015e273a583ac485
size 2344

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:03427060a858cb7d1f1b70a175eeab2e0a0546c898d3bd1d444eb0b253c069c2
size 3103

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cef07a4abc3ee47d6da1e30c2eb54cbad3e3f084b855ad6a1ab2ccbcea8738fd
size 2195

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5b31c664b0585e2b6fe5f69da79d5d3292db2578fd9227c90b656c30636059bb
size 2921

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:98726d41fcbe24957d2b69a66f20887ad757821d691d48e971851d9c64aa7972
size 351

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0c189482b312576a0b4f64c38d6f7d52bf4cd68a510c3c628ba5222e0e1b7c0f
size 2256

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7978895b08a129ed44893098667516d73d47b7e3544912dcf3b9f2649ecec396
size 3112

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f6fb84376defe00eea8afb1753fe3f164f24172dc90a5eeb1287ab67905f6978
size 2827

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:21baa9be235dc50cc2207e0a286d923de00274dcb014fec783cb1de60a809f07
size 2968

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4748b787fbf6babcc3e3681bf8235098bdb23055f87c23ac11281294e834d783
size 2342

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:65cd4b0a2e8937adea292066c6f63b0a33027b5b3c74b9b75b5eb915ee7cd569
size 1186

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:66d227beeaba3cd9e9b974d4296f4c25cd6eef579c7b290927cd1e52b4a23f44
size 1245

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2d95304fb413153d2d62a811ad7e4d11a95017a50e627fce7c60336ecbc0ba26
size 392

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b3c90e8f037a12ebc528117d98370fbc97a342335fc71c861d79c1d569c1c2d0
size 6798