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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
// Tags: JDK1.4
// Uses: DecoderTestHelper EqualityChecker IntArrayChecker PointArrayChecker DoubleArrayChecker
//Copyright (C) 2004 Robert Schuster <theBohemian@gmx.net>
//This file is part of Mauve.
//Mauve 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, or (at your option)
//any later version.
//Mauve 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 Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.
package gnu.testlet.java.beans.XMLDecoder;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.Point;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/** Tests the main decoding functionality of java.beans.XMLDecoder.
*
* @author Robert Schuster
*
*/
public class jdk14 implements Testlet
{
private List testHelpers = new LinkedList();
public jdk14()
{
/* The following lines repeatedly create a DecoderTestHelper instance, initialize it with
* a specific object sequence and add it to the list of known DecoderTestHelpers. This
* sets up all the testcases for the XMLDecoder.
*/
DecoderTestHelper testHelper;
testHelper = new DecoderTestHelper("booleanTest",
"gnu#testlet#java#beans#XMLDecoder#data#boolean.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Boolean(true));
testHelper.addObject(new Boolean(false));
addHelper(testHelper);
// Tests decoding of characteristic byte values.
testHelper = new DecoderTestHelper("byteTest",
"gnu#testlet#java#beans#XMLDecoder#data#byte.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Byte((byte) -120));
testHelper.addObject(new Byte((byte) 0));
testHelper.addObject(new Byte(Byte.MIN_VALUE));
testHelper.addObject(new Byte(Byte.MAX_VALUE));
addHelper(testHelper);
// Tests decoding of characteristic short values.
testHelper = new DecoderTestHelper("shortTest",
"gnu#testlet#java#beans#XMLDecoder#data#short.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Short((short) 16000));
testHelper.addObject(new Short((short) -16000));
testHelper.addObject(new Short(Short.MIN_VALUE));
testHelper.addObject(new Short(Short.MAX_VALUE));
addHelper(testHelper);
// Tests decoding of characteristic int values.
testHelper = new DecoderTestHelper("intTest",
"gnu#testlet#java#beans#XMLDecoder#data#int.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Integer(54321));
testHelper.addObject(new Integer(-54321));
testHelper.addObject(new Integer(Integer.MIN_VALUE));
testHelper.addObject(new Integer(Integer.MAX_VALUE));
addHelper(testHelper);
// Tests decoding of characteristic long values.
testHelper = new DecoderTestHelper("longTest",
"gnu#testlet#java#beans#XMLDecoder#data#long.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Long(5432154321L));
testHelper.addObject(new Long(-5432154321L));
testHelper.addObject(new Long(Long.MIN_VALUE));
testHelper.addObject(new Long(Long.MAX_VALUE));
addHelper(testHelper);
// Tests decoding of characteristic float values.
testHelper = new DecoderTestHelper("floatTest",
"gnu#testlet#java#beans#XMLDecoder#data#float.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Float((float) Math.PI));
testHelper.addObject(new Float((float) Math.E));
testHelper.addObject(new Float((float) Math.pow(2, -16)));
testHelper.addObject(new Float(0f));
testHelper.addObject(new Float(Float.NaN));
testHelper.addObject(new Float(Float.POSITIVE_INFINITY));
testHelper.addObject(new Float(Float.NEGATIVE_INFINITY));
addHelper(testHelper);
// Tests decoding of characteristic double values.
testHelper = new DecoderTestHelper("doubleTest",
"gnu#testlet#java#beans#XMLDecoder#data#double.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Double(Math.PI));
testHelper.addObject(new Double(Math.E));
testHelper.addObject(new Double(Math.pow(2, -16)));
testHelper.addObject(new Double(Double.MIN_VALUE));
testHelper.addObject(new Double(Double.MAX_VALUE));
testHelper.addObject(new Double(Double.NaN));
testHelper.addObject(new Double(Double.POSITIVE_INFINITY));
testHelper.addObject(new Double(Double.NEGATIVE_INFINITY));
addHelper(testHelper);
// Tests decoding of elements that cannot contain sub elements or have IDs.
testHelper = new DecoderTestHelper("simpleElementsTest",
"gnu#testlet#java#beans#XMLDecoder#data#simpleElements.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Boolean(true));
testHelper.addObject(new Boolean(false));
testHelper.addObject(new Character('j'));
testHelper.addObject(new Character('a'));
testHelper.addObject(new Character('v'));
testHelper.addObject(new Character('a'));
testHelper.addObject(new Byte((byte) 8));
testHelper.addObject(new Short((short) 16));
testHelper.addObject(new Integer(32));
testHelper.addObject(new Long(64));
testHelper.addObject(new Float(32.0f));
testHelper.addObject(new Double(64.0));
testHelper.addObject("Hello World");
testHelper.addObject(Object.class);
testHelper.addObject(null);
addHelper(testHelper);
// Tests decoding of two lists and their comparison result which is
// computed while decoding.
testHelper = new DecoderTestHelper("listTest",
"gnu#testlet#java#beans#XMLDecoder#data#list.xml");
// keep the following synchronized with the XML file!
List expectedList = new ArrayList();
expectedList.add(new Integer(100));
expectedList.add("Hello World");
expectedList.add(WeakReference.class);
// XML data contains an ArrayList and a LinkedList with the same content
testHelper.addObject(expectedList);
testHelper.addObject(expectedList);
// comparison result of the two lists it contains
testHelper.addObject(new Boolean(true));
addHelper(testHelper);
// Tests decoding a fixed-size int array.
testHelper = new DecoderTestHelper("intArray",
"gnu#testlet#java#beans#XMLDecoder#data#intArray.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new int[] { 1, 2, 3 }, new IntArrayChecker());
// Tests decoding a growable int array (the growing is performed while decoding).
testHelper = new DecoderTestHelper("growableIntArray",
"gnu#testlet#java#beans#XMLDecoder#data#growableIntArray.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new int[] { 0, 1, 2, 3, 4, 5 }, new IntArrayChecker());
addHelper(testHelper);
/* Tests decoding a growable int array that has non-int subelements (that is byte and
* short).
*/
testHelper = new DecoderTestHelper("growableIntArray2",
"gnu#testlet#java#beans#XMLDecoder#data#growableIntArray2.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new int[] { 0, 1, 2 }, new IntArrayChecker());
addHelper(testHelper);
// Tests decoding a growable int array (the growing is performed while decoding).
testHelper = new DecoderTestHelper("growableDoubleArray",
"gnu#testlet#java#beans#XMLDecoder#data#growableDoubleArray.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new double[] { 0, 1, 2, 3, 4, 5 }, new DoubleArrayChecker());
addHelper(testHelper);
// Tests decoding a fixed-size java.awt.Point array.
testHelper = new DecoderTestHelper("pointArrayTest",
"gnu#testlet#java#beans#XMLDecoder#data#pointArray.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Point[]
{
new Point(0, 0), new Point(1, 1), new Point(2, 2)
}, new PointArrayChecker());
addHelper(testHelper);
// Tests decoding a growable java.awt.Point array (the growing is
// performed while decoding).
testHelper = new DecoderTestHelper("growablePointArrayTest",
"gnu#testlet#java#beans#XMLDecoder#data#growablePointArray.xml");
// keep the following synchronized with the XML file!
testHelper.addObject(new Point[]
{
new Point(0, 0), new Point(1, 1), new Point(2, 2),
new Point(3, 3), new Point(4, 4), new Point(5, 5)
}, new PointArrayChecker());
addHelper(testHelper);
}
private void addHelper(DecoderTestHelper helper)
{
testHelpers.add(helper);
}
public void test(TestHarness harness)
{
// simply iterates over all DecoderTestHelper instances
// and does their comparison
Iterator ite = testHelpers.iterator();
while (ite.hasNext())
((DecoderTestHelper) ite.next()).doComparison(harness);
}
}
|