1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*************************************************************************
/* Test.java -- Test java.text.DateFormatSymbols
/*
/* Copyright (c) 1998, 2001 Free Software Foundation, Inc.
/* Written by Aaron M. Renn (arenn@urbanophile.com)
/*
/* This program is free software; you can redistribute it and/or modify
/* it under the terms of the GNU General Public License as published
/* by the Free Software Foundation, either version 2 of the License, or
/* (at your option) any later version.
/*
/* This program is distributed in the hope that it will be useful, but
/* WITHOUT ANY WARRANTY; without even the implied warranty of
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/* GNU General Public License for more details.
/*
/* You should have received a copy of the GNU General Public License
/* along with this program; if not, write to the Free Software Foundation
/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
/*************************************************************************/
// Tags: JDK1.1
package gnu.testlet.java.text.DateFormatSymbols;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.text.*;
import java.util.Locale;
import java.util.MissingResourceException;
public class Test implements Testlet
{
private String[] my_eras = { "XX", "YY" };
private String[] my_months = { "A", "B", "C", "D" };
private String[] my_short_months = { "a", "a", "b", "c" };
private String[] my_weekdays = { "S", "M", "T" };
private String[] my_short_weekdays = { "s", "m", "t" };
private String[] my_ampms = { "aa", "pp" };
private String[][] my_zonestrings = {{ "A", "B" }};
private String my_patternchars = "123456789012345678";
private static boolean
arrayEquals(Object[] o1, Object[] o2)
{
if (o1 == null)
{
if (o2 != null)
return(false);
}
else
if (o2 == null)
return(true);
// We assume ordering is important.
for (int i = 0; i < o1.length; i++)
if (o1[i] instanceof Object[])
{
if (o2[i] instanceof Object[])
{
if (!arrayEquals((Object[])o1[i], (Object[])o2[i]))
return(false);
}
else
return(false);
}
else
if (!o1[i].equals(o2[i]))
return(false);
return(true);
}
private static void
arrayDump(TestHarness harness, Object[] o, String desc)
{
harness.debug("Dumping Object Array: " + desc);
if (o == null)
{
harness.debug("null");
return;
}
for (int i = 0; i < o.length; i++)
if (o[i] instanceof Object[])
arrayDump(harness, (Object[])o[i], desc + " element " + i);
else
harness.debug(" Element " + i + ": " + o[i]);
}
public void
test(TestHarness harness)
{
try
{
DateFormatSymbols dfs = new DateFormatSymbols(Locale.US);
harness.debug("Dumping default symbol information");
arrayDump(harness, dfs.getEras(), "eras");
arrayDump(harness, dfs.getMonths(), "months");
arrayDump(harness, dfs.getShortMonths(), "short months");
arrayDump(harness, dfs.getWeekdays(), "weekdays");
arrayDump(harness, dfs.getShortWeekdays(), "short weekdays");
arrayDump(harness, dfs.getAmPmStrings(), "am/pm strings");
arrayDump(harness, dfs.getZoneStrings(), "zone string array");
harness.debug("local pattern chars: " + dfs.getLocalPatternChars());
dfs.setEras(my_eras);
harness.check(arrayEquals(dfs.getEras(), my_eras), "eras");
dfs.setMonths(my_months);
harness.check(arrayEquals(dfs.getMonths(), my_months), "months");
dfs.setShortMonths(my_short_months);
harness.check(arrayEquals(dfs.getShortMonths(), my_short_months),
"short months");
dfs.setWeekdays(my_weekdays);
harness.check(arrayEquals(dfs.getWeekdays(), my_weekdays), "weekdays");
dfs.setShortWeekdays(my_short_weekdays);
harness.check(arrayEquals(dfs.getShortWeekdays(), my_short_weekdays),
"short weekdays");
dfs.setAmPmStrings(my_ampms);
harness.check(arrayEquals(dfs.getAmPmStrings(), my_ampms), "am/pm");
dfs.setLocalPatternChars(my_patternchars);
harness.check(dfs.getLocalPatternChars(), my_patternchars, "patterns");
/* Invalid Argument */
boolean fail = false;
try {
dfs.setZoneStrings(my_zonestrings);
} catch (IllegalArgumentException e) {
fail = true;
}
harness.check(fail, true, "InvalidArgumentException is thrown.");
}
catch(MissingResourceException e)
{
harness.debug(e);
harness.check(false);
}
}
} // class Test
|