harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r412641 [23/32] - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/java/beans/beancontext/ test/java-internal/java/beans/beancontext/ test/java/org/apache/harmony/beans/tests/ test/java/org/ap...
Date Thu, 08 Jun 2006 03:40:30 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VisibilityTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VisibilityTest.java?rev=412641&r1=412640&r2=412641&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VisibilityTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VisibilityTest.java Wed Jun  7 20:40:24 2006
@@ -1,49 +1,49 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.beans.tests.java.beans;
-
-import java.beans.Visibility;
-
-import junit.framework.TestCase;
-
-/**
- * Test the signature of the interface Visibility.
- */
-public class VisibilityTest extends TestCase {
-
-	public void testSignature() {
-		DummyVisibility o = new DummyVisibility();
-		assertTrue(o instanceof Visibility);
-	}
-
-	static class DummyVisibility implements Visibility {
-
-		public boolean avoidingGui() {
-			return false;
-		}
-
-		public void dontUseGui() {
-		}
-
-		public boolean needsGui() {
-			return false;
-		}
-
-		public void okToUseGui() {
-		}
-	}
-
-}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.beans.tests.java.beans;
+
+import java.beans.Visibility;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the signature of the interface Visibility.
+ */
+public class VisibilityTest extends TestCase {
+
+	public void testSignature() {
+		DummyVisibility o = new DummyVisibility();
+		assertTrue(o instanceof Visibility);
+	}
+
+	static class DummyVisibility implements Visibility {
+
+		public boolean avoidingGui() {
+			return false;
+		}
+
+		public void dontUseGui() {
+		}
+
+		public boolean needsGui() {
+			return false;
+		}
+
+		public void okToUseGui() {
+		}
+	}
+
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java?rev=412641&r1=412640&r2=412641&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java Wed Jun  7 20:40:24 2006
@@ -1,373 +1,373 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.beans.tests.java.beans;
-
-import java.beans.ExceptionListener;
-import java.beans.XMLDecoder;
-import java.beans.XMLEncoder;
-import java.beans.Introspector;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
-import org.apache.harmony.beans.tests.java.beans.XMLEncoderTest.DependencyBean;
-import org.apache.harmony.beans.tests.java.beans.mock.MockBean4Codec;
-import org.apache.harmony.beans.tests.java.beans.mock.MockExceptionListener;
-
-/**
- * Tests XMLDecoder
- */
-public class XMLDecoderTest extends TestCase {
-
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(XMLDecoderTest.class);
-	}
-
-	static byte xml123bytes[] = null;
-
-	static {
-		ByteArrayOutputStream byteout = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(byteout);
-		enc.writeObject(Integer.valueOf("1"));
-		enc.writeObject(Integer.valueOf("2"));
-		enc.writeObject(Integer.valueOf("3"));
-		enc.close();
-		xml123bytes = byteout.toByteArray();
-	}
-
-	public void testClose() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertEquals(Integer.valueOf("1"), dec.readObject());
-
-		dec.close();
-
-		assertEquals(Integer.valueOf("2"), dec.readObject());
-		assertEquals(Integer.valueOf("3"), dec.readObject());
-	}
-
-	public void testGetExceptionListener() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertNotNull(dec.getExceptionListener());
-	}
-
-	public void testGetOwner() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertNull(dec.getOwner());
-	}
-
-	public void testReadObject_ArrayOutOfBounds() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertEquals(Integer.valueOf("1"), dec.readObject());
-		assertEquals(Integer.valueOf("2"), dec.readObject());
-		assertEquals(Integer.valueOf("3"), dec.readObject());
-
-		try {
-			dec.readObject();
-			fail();
-		} catch (ArrayIndexOutOfBoundsException e) {
-			// expected
-		}
-	}
-
-	public void testReadObject_Null() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/null.xml"));
-		Object obj = dec.readObject();
-		assertNull(obj);
-	}
-
-	public void testReadObject_Integer() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/int.xml"));
-		Object obj = dec.readObject();
-		assertEquals(Integer.valueOf("3"), obj);
-	}
-
-	public void testReadObject_StringCodec() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/SampleBean_StringCodec.xml"));
-		SampleBean obj = (SampleBean) dec.readObject();
-		assertEquals("<Li Yang> & \"liyang'", obj.getMyid());
-		assertEquals("a child", obj.getRef().getMyid());
-	}
-
-	public void testReadObject_IntArray() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/IntArray.xml"));
-		int ints[] = (int[]) dec.readObject();
-		assertEquals(1, ints[0]);
-		assertEquals(2, ints[1]);
-		assertEquals(3, ints[2]);
-	}
-
-	public void testReadObject_PropertyDependency() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/DependencyBean.xml"));
-		DependencyBean b = (DependencyBean) dec.readObject();
-		assertEquals(888, b.getInts()[0]);
-		assertSame(b.getInts(), b.getRef());
-	}
-
-	public void testReadObject_NoChange() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4Codec_NoChange.xml"));
-		MockBean4Codec b = (MockBean4Codec) dec.readObject();
-	}
-
-	public void testReadObject_BornFriendChange() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4Codec_BornFriendChange.xml"));
-		MockBean4Codec b = (MockBean4Codec) dec.readObject();
-		assertEquals(888, b.getBornFriend().getZarr()[0]);
-		assertEquals(b.getBornFriend(), b.getNill());
-	}
-
-	public void testReadObject_ManyChanges() {
-		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4Codec_ManyChanges.xml"));
-		MockBean4Codec b = (MockBean4Codec) dec.readObject();
-		assertEquals(127, b.getB());
-		assertSame(b, b.getBackRef());
-		assertEquals(new Byte((byte) 127), b.getBobj());
-		assertEquals(false, b.isBool());
-		assertEquals(Boolean.TRUE, b.getBoolobj());
-		assertEquals(Exception.class, b.getBornFriend().getClazz());
-		assertEquals(888, b.getBornFriend().getZarr()[0]);
-		assertEquals('Z', b.getC());
-		assertEquals(String.class, b.getClazz());
-		assertEquals(new Character('z'), b.getCobj());
-		assertEquals(123.456, b.getD(), 0);
-		assertEquals(new Double(123.456), b.getDobj());
-		assertEquals(12.34F, b.getF(), 0);
-		assertEquals(new Float(12.34F), b.getFobj());
-		assertEquals(MockBean4Codec.class, b.getFriend().getClazz());
-		assertEquals(999, b.getI());
-		assertEquals(new Integer(999), b.getIobj());
-		assertEquals(8888888, b.getL());
-		assertEquals(new Long(8888888), b.getLobj());
-		assertEquals("Li Yang", b.getName());
-		assertNull(b.getNill());
-		assertEquals(55, b.getS());
-		assertEquals(new Short((short) 55), b.getSobj());
-		assertEquals(3, b.getZarr().length);
-		assertEquals(3, b.getZarr()[0]);
-		assertEquals(2, b.getZarr()[1]);
-		assertEquals(1, b.getZarr()[2]);
-		assertEquals(1, b.getZarrarr().length);
-		assertEquals(3, b.getZarrarr()[0].length);
-		assertEquals("6", b.getZarrarr()[0][0]);
-		assertEquals("6", b.getZarrarr()[0][1]);
-		assertEquals("6", b.getZarrarr()[0][2]);
-	}
-
-	public void testReadObject_StaticField() {
-		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4StaticField_Original.xml"));
-		MockBean4StaticField o1 = (MockBean4StaticField) dec1.readObject();
-
-		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4StaticField.xml"));
-		MockBean4StaticField o2 = (MockBean4StaticField) dec2.readObject();
-
-		if (!o1.equals(o2)) {
-			System.out
-					.println("Loading object with static field, original xml: "
-							+ o1.getV());
-			System.out.println("Loading object with static field, field xml: "
-					+ o2.getV());
-		}
-
-		assertEquals(o1, o2);
-	}
-
-	public void testReadObject_Owner() {
-		MockBean4Owner_Owner o1 = new MockBean4Owner_Owner();
-		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4Owner_SetOwner.xml"), o1);
-		MockBean4Owner_Target t1 = (MockBean4Owner_Target) dec1.readObject();
-
-		assertEquals(o1.getV(), 1);
-		assertEquals(o1, t1.getV());
-	}
-
-	public void testReadObject_Owner_WithWriteStatement() {
-		MockBean4Owner_Owner o2 = new MockBean4Owner_Owner();
-		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
-				"/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml"), o2);
-		MockBean4Owner_Target t2 = (MockBean4Owner_Target) dec2.readObject();
-
-		assertEquals(o2.getV(), 999);
-		assertEquals(o2, t2.getV());
-	}
-
-	public void testSetExceptionListener() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		Object defaultL = dec.getExceptionListener();
-
-		dec.setExceptionListener(null);
-		assertSame(defaultL, dec.getExceptionListener());
-
-		ExceptionListener newL = new MockExceptionListener();
-		dec.setExceptionListener(newL);
-		assertSame(newL, dec.getExceptionListener());
-	}
-
-	public void testSetExceptionListener_CatchException() {
-		MockExceptionListener l = new MockExceptionListener();
-		XMLDecoder dec = new XMLDecoder(XMLDecoderTest.class
-				.getResourceAsStream("/xml/bad_int.xml"), null, l);
-		assertTrue(l.size() > 0);
-	}
-
-	public void testSetOwner() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertNull(dec.getOwner());
-
-		String owner = "owner";
-		dec.setOwner(owner);
-		assertSame(owner, dec.getOwner());
-
-		dec.setOwner(null);
-		assertNull(dec.getOwner());
-	}
-
-	/*
-	 * Class under test for void XMLDecoder(java.io.InputStream)
-	 */
-	public void testXMLDecoderInputStream() {
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
-		assertNull(dec.getOwner());
-		assertNotNull(dec.getExceptionListener());
-	}
-
-	/*
-	 * Class under test for void XMLDecoder(java.io.InputStream,
-	 * java.lang.Object)
-	 */
-	public void testXMLDecoderInputStreamObject() {
-		String owner = "owner";
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
-				owner);
-		assertSame(owner, dec.getOwner());
-		assertNotNull(dec.getExceptionListener());
-	}
-
-	/*
-	 * Class under test for void XMLDecoder(java.io.InputStream,
-	 * java.lang.Object, java.beans.ExceptionListener)
-	 */
-	public void testXMLDecoderInputStreamObjectExceptionListener() {
-		String owner = "owner";
-		MockExceptionListener l = new MockExceptionListener();
-		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
-				owner, l);
-		assertSame(owner, dec.getOwner());
-		assertSame(l, dec.getExceptionListener());
-	}
-    
-    
-    /**
-     * The test checks the code generation for XML from Test1.xml
-     */
-    public void testDecodeLinkedList() {
-        decode("xml/Test1.xml");
-    }
-
-    /**
-     * The test checks the code generation for XML from Test2.xml
-     */
-    public void testDecodePrimitiveArrayByLength() {
-        decode("xml/Test2.xml");
-    }
-    
-    /**
-     * The test checks the code generation for XML from Test3.xml
-     */
-    public void testDecodePrimitiveArrayByElements() {
-        decode("xml/Test3.xml");
-    }
-    
-    /**
-     * The test checks the code generation for XML from Test4.xml
-     */
-    public void testDecodeObjectArrayByLength() {
-        decode("xml/Test4.xml");
-    }
-    
-    /**
-     * The test checks the code generation for XML from Test5.xml
-     */
-    public void testDecodeObjectArrayByElements() {
-        decode("xml/Test5.xml");
-    }
-    
-    /**
-     * The test checks the code generation for XML from Test6.xml
-     */
-    public void testDecodeReference() {
-        decode("xml/Test6.xml");
-    }
-    
-    /**
-     * The test checks the code generation for XML from Test7.xml
-     */
-    public void testDecodeStringArray() {
-        decode("xml/Test7.xml");
-    }
-
-    /*
-     * The test checks the code generation for XML from MainTest.xml
-     * 
-    public void testMain() {
-        decode("xml/MainTest.xml");
-    }
-    */
-
-    /**
-     * 
-     */
-    public static Test suite() {
-        return new TestSuite(XMLDecoderTest.class);
-    }
-    
-    /**
-     * 
-     */
-    private void decode(String resourceName) {
-        XMLDecoder d = null;
-        try {
-            Introspector.setBeanInfoSearchPath(new String[] {});
-            d = new XMLDecoder(new BufferedInputStream(
-                                                       ClassLoader.getSystemClassLoader().getResourceAsStream(resourceName)));
-            while(true) {
-                Object obj = d.readObject();
-            }
-        } catch (ArrayIndexOutOfBoundsException aibe) {
-            assertTrue(true);
-        } catch (Exception e) {
-            System.out.println(e.getClass() + " :" + e.getMessage());
-            fail("Exception " + e.getClass() + " is thrown");
-        } finally {
-            if(d != null) {
-                d.close();
-            }
-        }
-    }
-}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.beans.tests.java.beans;
+
+import java.beans.ExceptionListener;
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.beans.Introspector;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
+import org.apache.harmony.beans.tests.java.beans.XMLEncoderTest.DependencyBean;
+import org.apache.harmony.beans.tests.java.beans.mock.MockBean4Codec;
+import org.apache.harmony.beans.tests.java.beans.mock.MockExceptionListener;
+
+/**
+ * Tests XMLDecoder
+ */
+public class XMLDecoderTest extends TestCase {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(XMLDecoderTest.class);
+	}
+
+	static byte xml123bytes[] = null;
+
+	static {
+		ByteArrayOutputStream byteout = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(byteout);
+		enc.writeObject(Integer.valueOf("1"));
+		enc.writeObject(Integer.valueOf("2"));
+		enc.writeObject(Integer.valueOf("3"));
+		enc.close();
+		xml123bytes = byteout.toByteArray();
+	}
+
+	public void testClose() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertEquals(Integer.valueOf("1"), dec.readObject());
+
+		dec.close();
+
+		assertEquals(Integer.valueOf("2"), dec.readObject());
+		assertEquals(Integer.valueOf("3"), dec.readObject());
+	}
+
+	public void testGetExceptionListener() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	public void testGetOwner() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+	}
+
+	public void testReadObject_ArrayOutOfBounds() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertEquals(Integer.valueOf("1"), dec.readObject());
+		assertEquals(Integer.valueOf("2"), dec.readObject());
+		assertEquals(Integer.valueOf("3"), dec.readObject());
+
+		try {
+			dec.readObject();
+			fail();
+		} catch (ArrayIndexOutOfBoundsException e) {
+			// expected
+		}
+	}
+
+	public void testReadObject_Null() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/null.xml"));
+		Object obj = dec.readObject();
+		assertNull(obj);
+	}
+
+	public void testReadObject_Integer() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/int.xml"));
+		Object obj = dec.readObject();
+		assertEquals(Integer.valueOf("3"), obj);
+	}
+
+	public void testReadObject_StringCodec() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/SampleBean_StringCodec.xml"));
+		SampleBean obj = (SampleBean) dec.readObject();
+		assertEquals("<Li Yang> & \"liyang'", obj.getMyid());
+		assertEquals("a child", obj.getRef().getMyid());
+	}
+
+	public void testReadObject_IntArray() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/IntArray.xml"));
+		int ints[] = (int[]) dec.readObject();
+		assertEquals(1, ints[0]);
+		assertEquals(2, ints[1]);
+		assertEquals(3, ints[2]);
+	}
+
+	public void testReadObject_PropertyDependency() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/DependencyBean.xml"));
+		DependencyBean b = (DependencyBean) dec.readObject();
+		assertEquals(888, b.getInts()[0]);
+		assertSame(b.getInts(), b.getRef());
+	}
+
+	public void testReadObject_NoChange() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4Codec_NoChange.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+	}
+
+	public void testReadObject_BornFriendChange() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4Codec_BornFriendChange.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+		assertEquals(888, b.getBornFriend().getZarr()[0]);
+		assertEquals(b.getBornFriend(), b.getNill());
+	}
+
+	public void testReadObject_ManyChanges() {
+		XMLDecoder dec = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4Codec_ManyChanges.xml"));
+		MockBean4Codec b = (MockBean4Codec) dec.readObject();
+		assertEquals(127, b.getB());
+		assertSame(b, b.getBackRef());
+		assertEquals(new Byte((byte) 127), b.getBobj());
+		assertEquals(false, b.isBool());
+		assertEquals(Boolean.TRUE, b.getBoolobj());
+		assertEquals(Exception.class, b.getBornFriend().getClazz());
+		assertEquals(888, b.getBornFriend().getZarr()[0]);
+		assertEquals('Z', b.getC());
+		assertEquals(String.class, b.getClazz());
+		assertEquals(new Character('z'), b.getCobj());
+		assertEquals(123.456, b.getD(), 0);
+		assertEquals(new Double(123.456), b.getDobj());
+		assertEquals(12.34F, b.getF(), 0);
+		assertEquals(new Float(12.34F), b.getFobj());
+		assertEquals(MockBean4Codec.class, b.getFriend().getClazz());
+		assertEquals(999, b.getI());
+		assertEquals(new Integer(999), b.getIobj());
+		assertEquals(8888888, b.getL());
+		assertEquals(new Long(8888888), b.getLobj());
+		assertEquals("Li Yang", b.getName());
+		assertNull(b.getNill());
+		assertEquals(55, b.getS());
+		assertEquals(new Short((short) 55), b.getSobj());
+		assertEquals(3, b.getZarr().length);
+		assertEquals(3, b.getZarr()[0]);
+		assertEquals(2, b.getZarr()[1]);
+		assertEquals(1, b.getZarr()[2]);
+		assertEquals(1, b.getZarrarr().length);
+		assertEquals(3, b.getZarrarr()[0].length);
+		assertEquals("6", b.getZarrarr()[0][0]);
+		assertEquals("6", b.getZarrarr()[0][1]);
+		assertEquals("6", b.getZarrarr()[0][2]);
+	}
+
+	public void testReadObject_StaticField() {
+		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4StaticField_Original.xml"));
+		MockBean4StaticField o1 = (MockBean4StaticField) dec1.readObject();
+
+		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4StaticField.xml"));
+		MockBean4StaticField o2 = (MockBean4StaticField) dec2.readObject();
+
+		if (!o1.equals(o2)) {
+			System.out
+					.println("Loading object with static field, original xml: "
+							+ o1.getV());
+			System.out.println("Loading object with static field, field xml: "
+					+ o2.getV());
+		}
+
+		assertEquals(o1, o2);
+	}
+
+	public void testReadObject_Owner() {
+		MockBean4Owner_Owner o1 = new MockBean4Owner_Owner();
+		XMLDecoder dec1 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4Owner_SetOwner.xml"), o1);
+		MockBean4Owner_Target t1 = (MockBean4Owner_Target) dec1.readObject();
+
+		assertEquals(o1.getV(), 1);
+		assertEquals(o1, t1.getV());
+	}
+
+	public void testReadObject_Owner_WithWriteStatement() {
+		MockBean4Owner_Owner o2 = new MockBean4Owner_Owner();
+		XMLDecoder dec2 = new XMLDecoder(this.getClass().getResourceAsStream(
+				"/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml"), o2);
+		MockBean4Owner_Target t2 = (MockBean4Owner_Target) dec2.readObject();
+
+		assertEquals(o2.getV(), 999);
+		assertEquals(o2, t2.getV());
+	}
+
+	public void testSetExceptionListener() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		Object defaultL = dec.getExceptionListener();
+
+		dec.setExceptionListener(null);
+		assertSame(defaultL, dec.getExceptionListener());
+
+		ExceptionListener newL = new MockExceptionListener();
+		dec.setExceptionListener(newL);
+		assertSame(newL, dec.getExceptionListener());
+	}
+
+	public void testSetExceptionListener_CatchException() {
+		MockExceptionListener l = new MockExceptionListener();
+		XMLDecoder dec = new XMLDecoder(XMLDecoderTest.class
+				.getResourceAsStream("/xml/bad_int.xml"), null, l);
+		assertTrue(l.size() > 0);
+	}
+
+	public void testSetOwner() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+
+		String owner = "owner";
+		dec.setOwner(owner);
+		assertSame(owner, dec.getOwner());
+
+		dec.setOwner(null);
+		assertNull(dec.getOwner());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream)
+	 */
+	public void testXMLDecoderInputStream() {
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes));
+		assertNull(dec.getOwner());
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream,
+	 * java.lang.Object)
+	 */
+	public void testXMLDecoderInputStreamObject() {
+		String owner = "owner";
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
+				owner);
+		assertSame(owner, dec.getOwner());
+		assertNotNull(dec.getExceptionListener());
+	}
+
+	/*
+	 * Class under test for void XMLDecoder(java.io.InputStream,
+	 * java.lang.Object, java.beans.ExceptionListener)
+	 */
+	public void testXMLDecoderInputStreamObjectExceptionListener() {
+		String owner = "owner";
+		MockExceptionListener l = new MockExceptionListener();
+		XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes),
+				owner, l);
+		assertSame(owner, dec.getOwner());
+		assertSame(l, dec.getExceptionListener());
+	}
+    
+    
+    /**
+     * The test checks the code generation for XML from Test1.xml
+     */
+    public void testDecodeLinkedList() {
+        decode("xml/Test1.xml");
+    }
+
+    /**
+     * The test checks the code generation for XML from Test2.xml
+     */
+    public void testDecodePrimitiveArrayByLength() {
+        decode("xml/Test2.xml");
+    }
+    
+    /**
+     * The test checks the code generation for XML from Test3.xml
+     */
+    public void testDecodePrimitiveArrayByElements() {
+        decode("xml/Test3.xml");
+    }
+    
+    /**
+     * The test checks the code generation for XML from Test4.xml
+     */
+    public void testDecodeObjectArrayByLength() {
+        decode("xml/Test4.xml");
+    }
+    
+    /**
+     * The test checks the code generation for XML from Test5.xml
+     */
+    public void testDecodeObjectArrayByElements() {
+        decode("xml/Test5.xml");
+    }
+    
+    /**
+     * The test checks the code generation for XML from Test6.xml
+     */
+    public void testDecodeReference() {
+        decode("xml/Test6.xml");
+    }
+    
+    /**
+     * The test checks the code generation for XML from Test7.xml
+     */
+    public void testDecodeStringArray() {
+        decode("xml/Test7.xml");
+    }
+
+    /*
+     * The test checks the code generation for XML from MainTest.xml
+     * 
+    public void testMain() {
+        decode("xml/MainTest.xml");
+    }
+    */
+
+    /**
+     * 
+     */
+    public static Test suite() {
+        return new TestSuite(XMLDecoderTest.class);
+    }
+    
+    /**
+     * 
+     */
+    private void decode(String resourceName) {
+        XMLDecoder d = null;
+        try {
+            Introspector.setBeanInfoSearchPath(new String[] {});
+            d = new XMLDecoder(new BufferedInputStream(
+                                                       ClassLoader.getSystemClassLoader().getResourceAsStream(resourceName)));
+            while(true) {
+                Object obj = d.readObject();
+            }
+        } catch (ArrayIndexOutOfBoundsException aibe) {
+            assertTrue(true);
+        } catch (Exception e) {
+            System.out.println(e.getClass() + " :" + e.getMessage());
+            fail("Exception " + e.getClass() + " is thrown");
+        } finally {
+            if(d != null) {
+                d.close();
+            }
+        }
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=412641&r1=412640&r2=412641&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java Wed Jun  7 20:40:24 2006
@@ -1,750 +1,750 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.beans.tests.java.beans;
-
-import java.beans.DefaultPersistenceDelegate;
-import java.beans.Encoder;
-import java.beans.Expression;
-import java.beans.ExceptionListener;
-import java.beans.PersistenceDelegate;
-import java.beans.Statement;
-import java.beans.XMLEncoder;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-
-import junit.framework.TestCase;
-import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
-import org.apache.harmony.beans.tests.java.beans.mock.MockBean4Codec;
-
-import org.apache.harmony.beans.tests.java.beans.auxiliary.StandardBean;
-import org.apache.harmony.beans.tests.java.beans.auxiliary.AType;
-
-/**
- * Tests for XMLEncoder
- */
-public class XMLEncoderTest extends TestCase {
-
-	public static void main(String[] args) {
-
-		// VerboseEncoder enc = new VerboseEncoder();
-		//
-		// MockBean4Codec b = new MockBean4Codec();
-		// b.getBornFriend().getZarr()[0] = 888;
-		// b.setNill(b.getBornFriend());
-		//
-		// enc.writeObject(b);
-		// enc.flush();
-
-		junit.textui.TestRunner.run(XMLEncoderTest.class);
-	}
-
-	public static class DependencyBean {
-		private int ints[] = new int[] { 1 };
-
-		private Object ref;
-
-		public int[] getInts() {
-			return ints;
-		}
-
-		public void setInts(int[] ints) {
-			this.ints = ints;
-		}
-
-		public Object getRef() {
-			return ref;
-		}
-
-		public void setRef(Object ref) {
-			this.ref = ref;
-		}
-	}
-
-	public static class VerboseEncoder extends XMLEncoder {
-
-		private PrintWriter out;
-
-		private boolean ident;
-
-		public VerboseEncoder() {
-			this(new PrintWriter(System.out, true), true);
-		}
-
-		public VerboseEncoder(PrintWriter out, boolean ident) {
-			super(System.out);
-			this.out = out;
-			this.ident = ident;
-		}
-
-		public Object get(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "get()> " + arg0);
-			Object result = super.get(arg0);
-			out.println(identStr + "get()< " + result);
-			return result;
-		}
-
-		public PersistenceDelegate getPersistenceDelegate(Class type) {
-			PersistenceDelegate result = super.getPersistenceDelegate(type);
-			return result;
-		}
-
-		public Object remove(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "remove()> " + arg0);
-			Object result = super.remove(arg0);
-			out.println(identStr + "remove()< " + result);
-			return result;
-		}
-
-		public void writeExpression(Expression arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeExpression()> " + string(arg0));
-			super.writeExpression(arg0);
-			out.println(identStr + "writeExpression()< ");
-		}
-
-		public void writeStatement(Statement arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeStatement()> " + string(arg0));
-			super.writeStatement(arg0);
-			out.println(identStr + "writeStatement()< ");
-		}
-
-		public void writeObject(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeObject()> " + arg0);
-			super.writeObject(arg0);
-			out.println(identStr + "writeObject()< ");
-		}
-	}
-
-	public static String ident() {
-		Exception ex = new Exception();
-		int level = ex.getStackTrace().length;
-		StringBuffer buf = new StringBuffer();
-		for (int i = 0; i < level; i++) {
-			buf.append("  ");
-		}
-		return buf.toString();
-	}
-
-	public static String string(Statement stat) {
-		String str = "(" + stat.getTarget() + ")." + stat.getMethodName() + "(";
-		Object args[] = stat.getArguments();
-		for (int i = 0; i < args.length; i++) {
-			if (i > 0) {
-				str += ", ";
-			}
-			str += args[i];
-		}
-		str = str + ")";
-		return str;
-	}
-
-	public static String string(Expression exp) {
-		String str = "";
-		try {
-			str += str + exp.getValue();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		str += "=" + string((Statement) exp);
-		return str;
-	}
-
-	public void testWriteExpression() {
-		// covered by testWriteObject
-	}
-
-	public void testWriteStatement() {
-		// coverd by testWriteStatement
-	}
-
-	public void testWriteObject_Null() throws IOException {
-		assertCodedXML(null, "/xml/null.xml");
-	}
-
-	public void testWriteObject_Integer() throws IOException {
-		assertCodedXML(new Integer(3), "/xml/int.xml");
-	}
-
-	public void testWriteObject_StringCodec() throws IOException {
-		SampleBean b = new SampleBean();
-		b.setMyid("<Li Yang> & \"liyang'");
-		SampleBean c = new SampleBean();
-		c.setMyid("a child");
-		b.setRef(c);
-		assertCodedXML(b, "/xml/SampleBean_StringCodec.xml");
-	}
-
-	public void testWriteObject_IntArray() throws IOException {
-		assertCodedXML(new int[] { 1, 2, 3 }, "/xml/IntArray.xml");
-	}
-
-	public void testWriteObject_PropertyDependency() throws IOException {
-		DependencyBean b = new DependencyBean();
-		b.getInts()[0] = 888;
-		b.setRef(b.getInts());
-		assertCodedXML(b, "/xml/DependencyBean.xml");
-	}
-
-	public void testWriteObject_NoChange() throws IOException {
-		assertCodedXML(new MockBean4Codec(), "/xml/MockBean4Codec_NoChange.xml");
-	}
-
-	public void testWriteObject_BornFriendChange() throws IOException {
-		MockBean4Codec b = new MockBean4Codec();
-		b.getBornFriend().getZarr()[0] = 888;
-		b.setNill(b.getBornFriend());
-
-		assertCodedXML(b, "/xml/MockBean4Codec_BornFriendChange.xml");
-	}
-
-	public void testWriteObject_ManyChanges() throws IOException {
-		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges(),
-				"/xml/MockBean4Codec_ManyChanges.xml");
-	}
-
-	public void testWriteObject_ManyChanges_2() throws IOException {
-		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges2(),
-				"/xml/MockBean4Codec_ManyChanges_2.xml");
-	}
-
-	public void testWriteObject_SetOwner() throws IOException {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		MockBean4Owner_Target t = new MockBean4Owner_Target();
-		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
-		t.setV(o);
-		enc.setOwner(o);
-
-		assertCodedXML(t, "/xml/MockBean4Owner_SetOwner.xml", temp, enc);
-
-	}
-
-	public void testWriteObject_SetOwnerWithWriteStatement() throws IOException {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		MockBean4Owner_Target t = new MockBean4Owner_Target();
-		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
-		t.setV(o);
-		enc.setOwner(o);
-
-		enc.writeStatement(new Statement(o, "loading", new Object[] {}));
-
-		assertCodedXML(t, "/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml",
-				temp, enc);
-
-	}
-
-	public void testWriteObject_StaticField() throws IOException {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		enc.setPersistenceDelegate(MockBean4StaticField.class,
-				new MockBean4StaticField_PD());
-
-		assertCodedXML(MockBean4StaticField.inst, "/xml/MockBean4StaticField.xml",
-				temp, enc);
-
-	}
-
-	public void testClose() {
-		ByteArrayOutputStream out = new ByteArrayOutputStream() {
-			boolean closeCalled = false;
-
-			public void close() throws IOException {
-				if (closeCalled) {
-					throw new IOException("close already called!");
-				} else {
-					closeCalled = true;
-					super.close();
-				}
-			}
-		};
-		XMLEncoder enc = new XMLEncoder(out);
-		enc.writeObject(new Integer(3));
-		assertTrue(out.size() == 0);
-
-		enc.close();
-
-		assertTrue(out.size() > 0);
-		try {
-			out.close();
-			fail();
-		} catch (IOException e) {
-			assertEquals("close already called!", e.getMessage());
-		}
-	}
-
-	public void testFlush() {
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(out);
-		Integer i = new Integer(3);
-		enc.writeObject(i);
-		assertTrue(out.size() == 0);
-		assertNotNull(enc.get(i));
-
-		enc.flush();
-
-		assertTrue(out.size() > 0);
-		assertNull(enc.get(i));
-	}
-
-	public void testXMLEncoder_Null() {
-		try {
-			XMLEncoder enc = new XMLEncoder(null);
-		} catch (NullPointerException e) {
-			// expected
-		}
-	}
-
-	public void testGetOwner() {
-		XMLEncoder enc = new XMLEncoder(System.out);
-		assertNull(enc.getOwner());
-	}
-
-	public void testSetOwner() {
-		XMLEncoder enc = new XMLEncoder(System.out);
-		Object owner = Boolean.FALSE;
-
-		enc.setOwner(owner);
-		assertSame(owner, enc.getOwner());
-
-		enc.setOwner(null);
-		assertNull(enc.getOwner());
-	}
-
-	private void assertCodedXML(Object obj, String xmlFile) throws IOException {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		assertCodedXML(obj, xmlFile, temp, enc);
-	}
-
-	private void assertCodedXML(Object obj, String xmlFile,
-			ByteArrayOutputStream temp, XMLEncoder enc) throws IOException {
-		if (enc == null || temp == null) {
-			temp = new ByteArrayOutputStream();
-			enc = new XMLEncoder(temp);
-		}
-		enc.writeObject(obj);
-		enc.close();
-		byte bytes[] = temp.toByteArray();
-
-		InputStream refIn = XMLEncoderTest.class.getResourceAsStream(xmlFile);
-		if (refIn == null) {
-			FileOutputStream file = new FileOutputStream(xmlFile);
-			file.write(bytes);
-			file.close();
-			throw new Error("resource " + xmlFile + " not exist in "
-					+ XMLEncoderTest.class.getPackage()
-					+ ", write in current dir!");
-		}
-		BufferedReader xml = new BufferedReader(new InputStreamReader(
-				new ByteArrayInputStream(bytes), "UTF-8"));
-		BufferedReader refXml = new BufferedReader(new InputStreamReader(refIn,
-				"UTF-8"));
-
-		String line = null, refLine = null;
-		int lineNum = 0;
-		while (true) {
-			lineNum++;
-			line = xml.readLine();
-			refLine = refXml.readLine();
-			if (line == null && refLine == null) {
-				break;
-			}
-			if (line == null) {
-				throw new RuntimeException("line " + lineNum
-						+ ", xml ends, but ref line is: " + refLine);
-			}
-			if (refLine == null) {
-				throw new RuntimeException("line " + lineNum
-						+ ", ref xml ends, but line is: " + line);
-			}
-			if (lineNum == 2) {
-				String trim = line.trim();
-				assertTrue(trim.startsWith("<java version=\""));
-				assertTrue(trim.endsWith("\" class=\"java.beans.XMLDecoder\">"));
-			} else {
-				String trim = line.trim();
-				String refTrim = refLine.trim();
-				if (trim.endsWith(" />") && refTrim.endsWith("/>")
-						&& trim.length() == refTrim.length() + 1) {
-					trim = trim.substring(0, trim.length() - 3);
-					refTrim = refTrim.substring(0, refTrim.length() - 2);
-				}
-				if (!trim.equals(refTrim)) {
-					System.out.println("---- Bad xml ----");
-					BufferedReader reader = new BufferedReader(
-							new InputStreamReader(new ByteArrayInputStream(
-									bytes), "UTF-8"));
-					String l = null;
-					while ((l = reader.readLine()) != null) {
-						System.out.println(l);
-					}
-					throw new RuntimeException("line " + lineNum
-							+ ", expected: " + refLine + ", but was: " + line);
-				}
-			}
-		}
-	}
-
-    
-    /**
-     * The test checks that java.lang.Boolean exemplar store is correct
-     */
-    public void testEncodeBoolean() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Boolean(true));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Byte exemplar store is correct
-     */
-    public void testEncodeByte() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Byte((byte) 123));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Character exemplar store is correct
-     */
-    public void testEncodeCharacter() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Character('a'));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Class exemplar store is correct
-     */
-    public void testEncodeClass() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(Object.class);
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Double exemplar store is correct
-     */
-    public void testEncodeDouble() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Double((double) 0.01));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Float exemplar store is correct
-     */
-    public void testEncodeFloat() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Float((float) 0.01));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Integer exemplar store is correct
-     */
-    public void testEncodeInteger() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Integer(1));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Long exemplar store is correct
-     */
-    public void testEncodeLong() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Long(1));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.Short exemplar store is correct
-     */
-    public void testEncodeShort() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new Short((short) 1));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that java.lang.String exemplar store is correct
-     */
-    public void testEncodeString() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new String("hello"));
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that array exemplar store is correct
-     */
-    public void testEncodeArray() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(new int[] {1, 2, 3});
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that null exemplar store is correct
-     */
-    public void testEncodeNull() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            e.writeObject(null);
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that complex scenario store is correct
-     */
-    public void testEncodingScenario() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-
-        StandardBean bean1 = new StandardBean("bean1");
-        
-        StandardBean bean2 = new StandardBean();
-        bean2.setText(null);
-        
-        bean1.setPeer(bean2);
-        bean2.setPeer(bean1);
-        
-        try {
-            e.writeObject(bean1);
-            e.writeObject(bean2);
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-    
-    /**
-     * The test checks that encoder can handle writeExpression in initialize
-     */
-    public void testEncodeExpressionAsStatement() {
-        XMLEncoder e = new XMLEncoder(System.out);
-        e.setExceptionListener(new ExceptionListener() {
-            public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
-                        + e.getMessage());
-            }
-        });
-        
-        try {
-            final Object object = new Object();
-            e.setPersistenceDelegate(AType.class,
-                    new DefaultPersistenceDelegate() {
-                        protected void initialize(
-                                Class type,
-                                Object oldInstance,
-                                Object newInstance,
-                                Encoder out) {
-                            out.writeExpression(new Expression(
-                                    object, oldInstance, "go", new Object[] {}
-                                    ));
-                        }
-                    });
-            AType a = new AType();
-
-            //e.writeObject(object);
-            e.writeObject(a);
-            e.writeObject(object);
-        } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
-                    + excp.getMessage());
-        } finally {
-            e.close();
-        }
-    }
-}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.beans.tests.java.beans;
+
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.Expression;
+import java.beans.ExceptionListener;
+import java.beans.PersistenceDelegate;
+import java.beans.Statement;
+import java.beans.XMLEncoder;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+
+import junit.framework.TestCase;
+import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
+import org.apache.harmony.beans.tests.java.beans.mock.MockBean4Codec;
+
+import org.apache.harmony.beans.tests.java.beans.auxiliary.StandardBean;
+import org.apache.harmony.beans.tests.java.beans.auxiliary.AType;
+
+/**
+ * Tests for XMLEncoder
+ */
+public class XMLEncoderTest extends TestCase {
+
+	public static void main(String[] args) {
+
+		// VerboseEncoder enc = new VerboseEncoder();
+		//
+		// MockBean4Codec b = new MockBean4Codec();
+		// b.getBornFriend().getZarr()[0] = 888;
+		// b.setNill(b.getBornFriend());
+		//
+		// enc.writeObject(b);
+		// enc.flush();
+
+		junit.textui.TestRunner.run(XMLEncoderTest.class);
+	}
+
+	public static class DependencyBean {
+		private int ints[] = new int[] { 1 };
+
+		private Object ref;
+
+		public int[] getInts() {
+			return ints;
+		}
+
+		public void setInts(int[] ints) {
+			this.ints = ints;
+		}
+
+		public Object getRef() {
+			return ref;
+		}
+
+		public void setRef(Object ref) {
+			this.ref = ref;
+		}
+	}
+
+	public static class VerboseEncoder extends XMLEncoder {
+
+		private PrintWriter out;
+
+		private boolean ident;
+
+		public VerboseEncoder() {
+			this(new PrintWriter(System.out, true), true);
+		}
+
+		public VerboseEncoder(PrintWriter out, boolean ident) {
+			super(System.out);
+			this.out = out;
+			this.ident = ident;
+		}
+
+		public Object get(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "get()> " + arg0);
+			Object result = super.get(arg0);
+			out.println(identStr + "get()< " + result);
+			return result;
+		}
+
+		public PersistenceDelegate getPersistenceDelegate(Class type) {
+			PersistenceDelegate result = super.getPersistenceDelegate(type);
+			return result;
+		}
+
+		public Object remove(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "remove()> " + arg0);
+			Object result = super.remove(arg0);
+			out.println(identStr + "remove()< " + result);
+			return result;
+		}
+
+		public void writeExpression(Expression arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeExpression()> " + string(arg0));
+			super.writeExpression(arg0);
+			out.println(identStr + "writeExpression()< ");
+		}
+
+		public void writeStatement(Statement arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeStatement()> " + string(arg0));
+			super.writeStatement(arg0);
+			out.println(identStr + "writeStatement()< ");
+		}
+
+		public void writeObject(Object arg0) {
+			String identStr = ident ? ident() : "";
+			out.println(identStr + "writeObject()> " + arg0);
+			super.writeObject(arg0);
+			out.println(identStr + "writeObject()< ");
+		}
+	}
+
+	public static String ident() {
+		Exception ex = new Exception();
+		int level = ex.getStackTrace().length;
+		StringBuffer buf = new StringBuffer();
+		for (int i = 0; i < level; i++) {
+			buf.append("  ");
+		}
+		return buf.toString();
+	}
+
+	public static String string(Statement stat) {
+		String str = "(" + stat.getTarget() + ")." + stat.getMethodName() + "(";
+		Object args[] = stat.getArguments();
+		for (int i = 0; i < args.length; i++) {
+			if (i > 0) {
+				str += ", ";
+			}
+			str += args[i];
+		}
+		str = str + ")";
+		return str;
+	}
+
+	public static String string(Expression exp) {
+		String str = "";
+		try {
+			str += str + exp.getValue();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		str += "=" + string((Statement) exp);
+		return str;
+	}
+
+	public void testWriteExpression() {
+		// covered by testWriteObject
+	}
+
+	public void testWriteStatement() {
+		// coverd by testWriteStatement
+	}
+
+	public void testWriteObject_Null() throws IOException {
+		assertCodedXML(null, "/xml/null.xml");
+	}
+
+	public void testWriteObject_Integer() throws IOException {
+		assertCodedXML(new Integer(3), "/xml/int.xml");
+	}
+
+	public void testWriteObject_StringCodec() throws IOException {
+		SampleBean b = new SampleBean();
+		b.setMyid("<Li Yang> & \"liyang'");
+		SampleBean c = new SampleBean();
+		c.setMyid("a child");
+		b.setRef(c);
+		assertCodedXML(b, "/xml/SampleBean_StringCodec.xml");
+	}
+
+	public void testWriteObject_IntArray() throws IOException {
+		assertCodedXML(new int[] { 1, 2, 3 }, "/xml/IntArray.xml");
+	}
+
+	public void testWriteObject_PropertyDependency() throws IOException {
+		DependencyBean b = new DependencyBean();
+		b.getInts()[0] = 888;
+		b.setRef(b.getInts());
+		assertCodedXML(b, "/xml/DependencyBean.xml");
+	}
+
+	public void testWriteObject_NoChange() throws IOException {
+		assertCodedXML(new MockBean4Codec(), "/xml/MockBean4Codec_NoChange.xml");
+	}
+
+	public void testWriteObject_BornFriendChange() throws IOException {
+		MockBean4Codec b = new MockBean4Codec();
+		b.getBornFriend().getZarr()[0] = 888;
+		b.setNill(b.getBornFriend());
+
+		assertCodedXML(b, "/xml/MockBean4Codec_BornFriendChange.xml");
+	}
+
+	public void testWriteObject_ManyChanges() throws IOException {
+		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges(),
+				"/xml/MockBean4Codec_ManyChanges.xml");
+	}
+
+	public void testWriteObject_ManyChanges_2() throws IOException {
+		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges2(),
+				"/xml/MockBean4Codec_ManyChanges_2.xml");
+	}
+
+	public void testWriteObject_SetOwner() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		MockBean4Owner_Target t = new MockBean4Owner_Target();
+		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+		t.setV(o);
+		enc.setOwner(o);
+
+		assertCodedXML(t, "/xml/MockBean4Owner_SetOwner.xml", temp, enc);
+
+	}
+
+	public void testWriteObject_SetOwnerWithWriteStatement() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		MockBean4Owner_Target t = new MockBean4Owner_Target();
+		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+		t.setV(o);
+		enc.setOwner(o);
+
+		enc.writeStatement(new Statement(o, "loading", new Object[] {}));
+
+		assertCodedXML(t, "/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml",
+				temp, enc);
+
+	}
+
+	public void testWriteObject_StaticField() throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		enc.setPersistenceDelegate(MockBean4StaticField.class,
+				new MockBean4StaticField_PD());
+
+		assertCodedXML(MockBean4StaticField.inst, "/xml/MockBean4StaticField.xml",
+				temp, enc);
+
+	}
+
+	public void testClose() {
+		ByteArrayOutputStream out = new ByteArrayOutputStream() {
+			boolean closeCalled = false;
+
+			public void close() throws IOException {
+				if (closeCalled) {
+					throw new IOException("close already called!");
+				} else {
+					closeCalled = true;
+					super.close();
+				}
+			}
+		};
+		XMLEncoder enc = new XMLEncoder(out);
+		enc.writeObject(new Integer(3));
+		assertTrue(out.size() == 0);
+
+		enc.close();
+
+		assertTrue(out.size() > 0);
+		try {
+			out.close();
+			fail();
+		} catch (IOException e) {
+			assertEquals("close already called!", e.getMessage());
+		}
+	}
+
+	public void testFlush() {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(out);
+		Integer i = new Integer(3);
+		enc.writeObject(i);
+		assertTrue(out.size() == 0);
+		assertNotNull(enc.get(i));
+
+		enc.flush();
+
+		assertTrue(out.size() > 0);
+		assertNull(enc.get(i));
+	}
+
+	public void testXMLEncoder_Null() {
+		try {
+			XMLEncoder enc = new XMLEncoder(null);
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	public void testGetOwner() {
+		XMLEncoder enc = new XMLEncoder(System.out);
+		assertNull(enc.getOwner());
+	}
+
+	public void testSetOwner() {
+		XMLEncoder enc = new XMLEncoder(System.out);
+		Object owner = Boolean.FALSE;
+
+		enc.setOwner(owner);
+		assertSame(owner, enc.getOwner());
+
+		enc.setOwner(null);
+		assertNull(enc.getOwner());
+	}
+
+	private void assertCodedXML(Object obj, String xmlFile) throws IOException {
+		ByteArrayOutputStream temp = new ByteArrayOutputStream();
+		XMLEncoder enc = new XMLEncoder(temp);
+
+		assertCodedXML(obj, xmlFile, temp, enc);
+	}
+
+	private void assertCodedXML(Object obj, String xmlFile,
+			ByteArrayOutputStream temp, XMLEncoder enc) throws IOException {
+		if (enc == null || temp == null) {
+			temp = new ByteArrayOutputStream();
+			enc = new XMLEncoder(temp);
+		}
+		enc.writeObject(obj);
+		enc.close();
+		byte bytes[] = temp.toByteArray();
+
+		InputStream refIn = XMLEncoderTest.class.getResourceAsStream(xmlFile);
+		if (refIn == null) {
+			FileOutputStream file = new FileOutputStream(xmlFile);
+			file.write(bytes);
+			file.close();
+			throw new Error("resource " + xmlFile + " not exist in "
+					+ XMLEncoderTest.class.getPackage()
+					+ ", write in current dir!");
+		}
+		BufferedReader xml = new BufferedReader(new InputStreamReader(
+				new ByteArrayInputStream(bytes), "UTF-8"));
+		BufferedReader refXml = new BufferedReader(new InputStreamReader(refIn,
+				"UTF-8"));
+
+		String line = null, refLine = null;
+		int lineNum = 0;
+		while (true) {
+			lineNum++;
+			line = xml.readLine();
+			refLine = refXml.readLine();
+			if (line == null && refLine == null) {
+				break;
+			}
+			if (line == null) {
+				throw new RuntimeException("line " + lineNum
+						+ ", xml ends, but ref line is: " + refLine);
+			}
+			if (refLine == null) {
+				throw new RuntimeException("line " + lineNum
+						+ ", ref xml ends, but line is: " + line);
+			}
+			if (lineNum == 2) {
+				String trim = line.trim();
+				assertTrue(trim.startsWith("<java version=\""));
+				assertTrue(trim.endsWith("\" class=\"java.beans.XMLDecoder\">"));
+			} else {
+				String trim = line.trim();
+				String refTrim = refLine.trim();
+				if (trim.endsWith(" />") && refTrim.endsWith("/>")
+						&& trim.length() == refTrim.length() + 1) {
+					trim = trim.substring(0, trim.length() - 3);
+					refTrim = refTrim.substring(0, refTrim.length() - 2);
+				}
+				if (!trim.equals(refTrim)) {
+					System.out.println("---- Bad xml ----");
+					BufferedReader reader = new BufferedReader(
+							new InputStreamReader(new ByteArrayInputStream(
+									bytes), "UTF-8"));
+					String l = null;
+					while ((l = reader.readLine()) != null) {
+						System.out.println(l);
+					}
+					throw new RuntimeException("line " + lineNum
+							+ ", expected: " + refLine + ", but was: " + line);
+				}
+			}
+		}
+	}
+
+    
+    /**
+     * The test checks that java.lang.Boolean exemplar store is correct
+     */
+    public void testEncodeBoolean() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Boolean(true));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Byte exemplar store is correct
+     */
+    public void testEncodeByte() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Byte((byte) 123));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Character exemplar store is correct
+     */
+    public void testEncodeCharacter() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Character('a'));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Class exemplar store is correct
+     */
+    public void testEncodeClass() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(Object.class);
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Double exemplar store is correct
+     */
+    public void testEncodeDouble() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Double((double) 0.01));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Float exemplar store is correct
+     */
+    public void testEncodeFloat() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Float((float) 0.01));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Integer exemplar store is correct
+     */
+    public void testEncodeInteger() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Integer(1));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Long exemplar store is correct
+     */
+    public void testEncodeLong() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Long(1));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.Short exemplar store is correct
+     */
+    public void testEncodeShort() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new Short((short) 1));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that java.lang.String exemplar store is correct
+     */
+    public void testEncodeString() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new String("hello"));
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that array exemplar store is correct
+     */
+    public void testEncodeArray() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(new int[] {1, 2, 3});
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that null exemplar store is correct
+     */
+    public void testEncodeNull() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            e.writeObject(null);
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that complex scenario store is correct
+     */
+    public void testEncodingScenario() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+
+        StandardBean bean1 = new StandardBean("bean1");
+        
+        StandardBean bean2 = new StandardBean();
+        bean2.setText(null);
+        
+        bean1.setPeer(bean2);
+        bean2.setPeer(bean1);
+        
+        try {
+            e.writeObject(bean1);
+            e.writeObject(bean2);
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+    
+    /**
+     * The test checks that encoder can handle writeExpression in initialize
+     */
+    public void testEncodeExpressionAsStatement() {
+        XMLEncoder e = new XMLEncoder(System.out);
+        e.setExceptionListener(new ExceptionListener() {
+            public void exceptionThrown(Exception e) {
+                fail("Exception " + e.getClass() +" is thrown: "
+                        + e.getMessage());
+            }
+        });
+        
+        try {
+            final Object object = new Object();
+            e.setPersistenceDelegate(AType.class,
+                    new DefaultPersistenceDelegate() {
+                        protected void initialize(
+                                Class type,
+                                Object oldInstance,
+                                Object newInstance,
+                                Encoder out) {
+                            out.writeExpression(new Expression(
+                                    object, oldInstance, "go", new Object[] {}
+                                    ));
+                        }
+                    });
+            AType a = new AType();
+
+            //e.writeObject(object);
+            e.writeObject(a);
+            e.writeObject(object);
+        } catch (Exception excp) {
+            fail("Exception " + excp.getClass() +" is thrown: "
+                    + excp.getMessage());
+        } finally {
+            e.close();
+        }
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java?rev=412641&r1=412640&r2=412641&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java Wed Jun  7 20:40:24 2006
@@ -1,45 +1,45 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.beans.tests.java.beans.beancontext;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test for java.beans.beancontext.
- */
-public class AllTests {
-
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(suite());
-	}
-
-	public static Test suite() {
-		TestSuite suite = new TestSuite(
-                "Suite for org.apache.harmony.beans.tests.java.beans.beancontext");
-		// $JUnit-BEGIN$
-		suite.addTestSuite(BeanContextChildSupportTest.class);
-		suite.addTestSuite(BeanContextEventTest.class);
-		suite.addTestSuite(BeanContextMembershipEventTest.class);
-		suite.addTestSuite(BeanContextServiceAvailableEventTest.class);
-		suite.addTestSuite(BeanContextServiceRevokedEventTest.class);
-		suite.addTestSuite(BeanContextServicesSupportTest.class);
-		suite.addTestSuite(BeanContextSupportTest.class);
-		suite.addTestSuite(InterfacesTest.class);
-		// $JUnit-END$
-		return suite;
-	}
-}
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.beans.tests.java.beans.beancontext;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test for java.beans.beancontext.
+ */
+public class AllTests {
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(suite());
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(
+                "Suite for org.apache.harmony.beans.tests.java.beans.beancontext");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(BeanContextChildSupportTest.class);
+		suite.addTestSuite(BeanContextEventTest.class);
+		suite.addTestSuite(BeanContextMembershipEventTest.class);
+		suite.addTestSuite(BeanContextServiceAvailableEventTest.class);
+		suite.addTestSuite(BeanContextServiceRevokedEventTest.class);
+		suite.addTestSuite(BeanContextServicesSupportTest.class);
+		suite.addTestSuite(BeanContextSupportTest.class);
+		suite.addTestSuite(InterfacesTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}



Mime
View raw message