abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r419720 [5/5] - in /incubator/abdera/java/trunk/build: ./ tools/ tools/retroweaver/ tools/retroweaver/docs/ tools/retroweaver/docs/guide/ tools/retroweaver/docs/images/ tools/retroweaver/lib/ tools/retroweaver/release/ tools/retroweaver/src...
Date Thu, 06 Jul 2006 22:08:33 GMT
Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/EnumTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/EnumTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/EnumTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/EnumTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,370 @@
+package com.rc.retroweaver.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+
+/**
+ * Tests support for the new 1.5 enum language feature.
+ */
+
+public class EnumTest extends AbstractTest {
+
+	public void testConcatenation() {
+		String s = "";
+		for (LetterEnum t : LetterEnum.values()) {
+			s = s + t + ':';
+		}
+		assertEquals("values", s, "A:B:C:");
+	}
+
+	public void testValueOf() {
+		LetterEnum et = Enum.valueOf(LetterEnum.class, "A");
+		assertSame("valueOf", et, LetterEnum.A);
+
+		CMYK color = Enum.valueOf(CMYK.class, "Magenta");
+		assertSame("valueOf", color, CMYK.Magenta);
+		assertFalse("isCyan", color.isCyan());
+
+		// test with inner class CMYK$1
+		color = Enum.valueOf(CMYK.class, "Cyan");
+		assertSame("valueOf", color, CMYK.Cyan);
+		assertTrue("isCyan", color.isCyan());
+	}
+
+	public void testNullValueOf() {
+		try {
+			Class<Color> c = null;
+			Enum.valueOf(c, "B");
+			fail("Should raise a NullPointerException");
+		} catch (NullPointerException e) {
+			success("null valueOf");
+		}
+	}
+
+	public void testIsEnum() {		
+		assertTrue("Color is enum", Color.class.isEnum());
+		assertFalse("Object is not enum", Object.class.isEnum());
+	}
+
+	public void testGetEnumConstants() {
+		Color v1[] = Color.values();
+		Color v2[] = Color.class.getEnumConstants();
+		assertArraySameItems("getEnumConstants", v1, v2);
+		
+		assertNull("null getEnumConstants", Object.class.getEnumConstants());
+	}
+
+	public void testInvalidValueOf() {
+		try {
+			Class clazz	= Object.class;
+			Enum.valueOf(clazz, "foo");
+			fail("Should raise an IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+			success("IllegalArgumentException");			
+		}
+		try {
+			Class clazz	= this.getClass();
+			Enum.valueOf(clazz, "foo");
+			fail("Should raise an IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+			success("IllegalArgumentException");			
+		}
+	}
+
+	public void testInvalidName() {
+		try {
+			// Should fail with IllegalArgumentException, because
+			// D isn't part of the enum.
+			Enum.valueOf(LetterEnum.class, "D");
+
+			fail("Should raise an IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+			success("testInvalidName");
+		}
+	}
+
+	public void testNullClass() {
+		try {
+			Class<LetterEnum> clazz = null;
+			Enum.valueOf(clazz, "A");
+
+			fail("Should raise a NullPointerException");
+		} catch (NullPointerException e) {
+			success("testNullClass");
+		}
+	}
+
+	public void testNullName() {
+		try {
+			Enum.valueOf(LetterEnum.class, null);
+
+			fail("Should raise an NullPointerException");
+		} catch (NullPointerException e) {
+			success("testNullName");
+		}
+	}
+
+	public void testBasicSerializable() throws Exception {
+		// Store "Red" object
+		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+		ObjectOutputStream os = new ObjectOutputStream(bytes);
+
+		EnumExample ex = new EnumExample(Color.Red);
+
+		os.writeObject(ex);
+		os.close();
+
+		// read "Red" from stream
+		EnumExample resolved = (EnumExample) new ObjectInputStream(
+				new ByteArrayInputStream(bytes.toByteArray())).readObject();
+
+		// test retrieved object
+		assertSame("serialization", resolved.color, Color.Red);
+	}
+
+	public void testSerializableVersion() throws Exception {
+		// test retrieved object from different LetterEnum version
+
+		// check that A can be retrieved
+		ObjectInputStream ois = new ObjectInputStream(getClass().getResourceAsStream("data/LetterEnum_A.ser"));
+		LetterEnum l = (LetterEnum) ois.readObject();
+		ois.close();
+		
+		assertSame("serialization LetterEnum_A.ser", l, LetterEnum.A);
+
+		// check that D raises an InvalidObjectException
+		try {
+	        ois = new ObjectInputStream(getClass().getResourceAsStream("data/LetterEnum_D.ser"));
+			l = (LetterEnum) ois.readObject();
+			ois.close();
+			
+			fail("serialization LetterEnum_D.ser: should raise InvalidObjectException");
+		} catch (InvalidObjectException ioe) {
+			success("serialization LetterEnum_D.ser");
+		}
+	}
+	
+	public void testInnerClassSerialization() throws Exception {
+		// test enum inner class serialization
+		ByteArrayOutputStream bytes;
+		ObjectOutputStream os;
+
+		CMYK color;
+		color = CMYK.Magenta;
+		bytes = new ByteArrayOutputStream();
+		os = new ObjectOutputStream(bytes);
+		os.writeObject(color);
+		os.close();
+
+		color = (CMYK) new ObjectInputStream(
+				new ByteArrayInputStream(bytes.toByteArray())).readObject();
+
+		// test retrieved object
+		assertSame("serialization", color, CMYK.Magenta);
+		assertFalse("isCyan", color.isCyan());
+
+		color = CMYK.Cyan;
+		bytes = new ByteArrayOutputStream();
+		os = new ObjectOutputStream(bytes);
+		os.writeObject(color);
+		os.close();
+
+		color = (CMYK) new ObjectInputStream(
+				new ByteArrayInputStream(bytes.toByteArray())).readObject();
+
+		// test retrieved object
+		assertSame("serialization", color, CMYK.Cyan);
+		assertTrue("isCyan", color.isCyan());
+	}
+
+	public void testDeclaringClass() {
+		assertEquals("Color", Color.Red.getDeclaringClass().getName(),
+				"com.rc.retroweaver.tests.Color");
+		assertEquals("CMYK", CMYK.Cyan.getDeclaringClass().getName(),
+				"com.rc.retroweaver.tests.CMYK");
+		assertEquals("declaringClass", LetterEnum.A.getDeclaringClass()
+				.getName(), "com.rc.retroweaver.tests.LetterEnum");
+	}
+
+	public void testCompareTo() {
+		LetterEnum l1 = LetterEnum.A;
+		LetterEnum l2 = LetterEnum.B;
+		LetterEnum l3 = LetterEnum.C;
+		LetterEnum l4 = LetterEnum.C;
+
+		assertTrue("compareTo negative", l1.compareTo(l2) < 0);
+		assertEquals("compareTo null", l3.compareTo(l4), 0);
+		assertTrue("compareTo positive", l3.compareTo(l2) > 0);
+
+		try {
+			Comparable c1 = l1;
+			Comparable c2 = Color.Red;
+			int i = c1.compareTo(c2);
+			System.out.println("\n\nCompare " + i + " " + c1 + " " + c2
+					+ "\n\n");
+			fail("Should raise a ClassCastException");
+		} catch (ClassCastException e) {
+			success("compareTo ClassCastException");
+		}
+	}
+
+	public void testFields() {
+		LetterEnum e = LetterEnum.A;
+
+		assertEquals("name", e.name(), "A");
+		assertEquals("ordinal", e.ordinal(), 0);
+	}
+
+	public void testMethodCalls() {
+		CMYK c1 = CMYK.Cyan;
+		assertTrue("Cyan", c1.isCyan());
+		CMYK c2 = CMYK.Magenta;
+		assertFalse("Magenta", c2.isCyan());
+	}
+
+	public void testClassLoader() {
+		try {
+			String className = "com.rc.retroweaver.tests.Number";
+			String fieldName = "Two";
+
+			ClassLoader cl = EnumTest.class.getClassLoader();
+			
+			Class enumClass = Enum.class;
+			Class numberClass = cl.loadClass(className);
+
+			Class[] paramTypes = { Class.class, String.class };
+			Object[] args = { numberClass, fieldName };
+			Method m = enumClass.getMethod("valueOf", paramTypes);
+			Enum two = (Enum)m.invoke(null, args);
+			assertEquals("testClassLoader valueOf", two.name(), fieldName);
+
+			Field field = numberClass.getField(fieldName);
+			two = (Enum) field.get(null);
+			assertEquals("testClassLoader getField", two.name(), fieldName);
+
+		} catch (Exception e) {
+			fail("testClassLoader exception: " + e.getMessage());
+		}
+	}
+
+	public void testCoverage() {
+		assertNotSame("hashcode", Color.Red.hashCode(), Color.Black.hashCode());
+
+		EmptyEnum values[] = EmptyEnum.values();
+		assertEquals("emty values", values.length, 0);
+
+		// coverage of "equals(Object): boolean"
+		LetterEnum et = Enum.valueOf(LetterEnum.class, "A");
+		assertEquals("valueOf", et, LetterEnum.A);
+
+		try {
+			Enum.valueOf(EmptyEnum.class, "foo");
+			fail("Should raise an IllegalArgumentException");
+		} catch (IllegalArgumentException e) {
+			success("missing values array in Enum_");
+		}
+
+		Class c = CMYK.Cyan.getDeclaringClass();
+		assertNotNull("getDeclaringClass", c);
+
+		try {
+			CMYK.Cyan.testClone();
+			fail("Should raise a CloneNotSupportedException");
+		} catch (CloneNotSupportedException e) {
+			success("clone");
+		}
+
+		LetterEnum l = LetterEnum.A;
+		assertFalse("equals", l.equals(null));
+		assertFalse("equals", l.equals(Color.Red));
+		
+		Comparable c1 = LetterEnum.A;
+		Comparable c2 = LetterEnum.A;
+		assertEquals("compareTo", c1.compareTo(c2), 0);
+	}
+
+	public static void main(String[] args) {
+		/*
+		 * Serialize "A" and "D" into LetterEnum_A.set and LetterEnum_D.ser
+		 * 
+		 * Before running this code, uncomment "D" in LetterEnum so that a
+		 * missing enum value can be tested in readResolve().
+		 */
+		LetterEnum l1 = LetterEnum.A;
+		LetterEnum l2 = null;
+		try {
+			l2 = LetterEnum.valueOf("D");
+		} catch (IllegalArgumentException iae) {
+			System.err.println("Uncomment D in LetterEnum to generate the correct files.");
+			System.exit(1);
+		}
+
+		try {
+			FileOutputStream fos = new FileOutputStream("LetterEnum_A.ser");
+	        ObjectOutputStream oos = new ObjectOutputStream(fos);
+			oos.writeObject(l1);
+			oos.close();
+
+			fos = new FileOutputStream("LetterEnum_D.ser");
+	        oos = new ObjectOutputStream(fos);
+			oos.writeObject(l2);
+			oos.close();
+		} catch (IOException ioe) {
+			ioe.printStackTrace();
+			System.exit(1);
+		}
+	}
+
+}
+
+enum LetterEnum {
+	A, B, C
+	//,D	// uncomment only when generating .ser files
+}
+
+enum Color {
+	Black, Red, Green, Blue, White;
+}
+
+enum CMYK {
+	Cyan {
+		public boolean isCyan() {
+			return true;
+		}
+	},
+	Magenta, Yellow, Black;
+
+	public boolean isCyan() {
+		return false;
+	}
+
+	public CMYK testClone() throws CloneNotSupportedException {
+		return (CMYK) (this.clone());
+	}
+}
+
+enum Number {
+	One, Two
+}
+
+enum EmptyEnum {
+}
+
+class EnumExample implements Serializable {
+
+	Color color;
+
+	EnumExample(Color c) {
+		color = c;
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/FullCoverageTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/FullCoverageTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/FullCoverageTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/FullCoverageTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,28 @@
+package com.rc.retroweaver.tests;
+
+import com.rc.retroweaver.runtime.Autobox;
+import com.rc.retroweaver.runtime.ClassMethods;
+import com.rc.retroweaver.runtime.IterableMethods;
+
+/**
+ * Ensures that the entire retroweaver code is tested. Note: this is the only
+ * test class that should import the retroweaver classes directly.
+ */
+
+public class FullCoverageTest extends AbstractTest {
+
+	public void testFullCoverage() {
+		Autobox box = new Autobox();
+		assertNotNull("Autoboxing", box);
+
+		ClassMethods c = new ClassMethods();
+		assertNotNull("ClassMethods", c);
+
+		try {
+			IterableMethods.iterator("");
+			fail("IterableMethods should raise an UnsupportedOperationException");
+		} catch (UnsupportedOperationException e) {
+		}
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InnerClassTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InnerClassTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InnerClassTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InnerClassTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,72 @@
+package com.rc.retroweaver.tests;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * Ensures that Retroweaver can handle inner classes ok.
+ */
+
+public class InnerClassTest extends AbstractTest {
+
+	public void testAnonymous() {
+		String name = new InnerClass().getAnonymousClassName();
+		assertEquals("testAnonymous", name,
+				"com.rc.retroweaver.tests.InnerClass$1");
+	}
+
+	public void testNamedInnerClass() {
+		String name = new InnerClass().namedInnerClassName;
+		assertEquals("testNamedInnerClass", name,
+				"com.rc.retroweaver.tests.InnerClass$NamedInnerClass");
+		name = new InnerClass().namedInnerClass.getClass().getName();
+		assertEquals("testNamedInnerClass2", name,
+				"com.rc.retroweaver.tests.InnerClass$NamedInnerClass");
+	}
+
+	public void testStaticInnerClass() {
+		String name = new InnerClass().staticInnerClass.getClass().getName();
+		assertEquals("testStaticInnerClass", name,
+				"com.rc.retroweaver.tests.InnerClass$StaticInnerClass");
+		name = InnerClass.staticInnerClassName;
+		assertEquals("testStaticInnerClass2", name,
+				"com.rc.retroweaver.tests.InnerClass$StaticInnerClass");
+	}
+
+}
+
+class InnerClass {
+	String anonymousClassName;
+
+	String namedInnerClassName;
+
+	NamedInnerClass namedInnerClass = new NamedInnerClass();
+
+	static String staticInnerClassName;
+
+	StaticInnerClass staticInnerClass = new StaticInnerClass();
+
+	public String getAnonymousClassName() {
+		ActionListener a = new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				anonymousClassName = getClass().getName();
+			}
+		};
+		a.actionPerformed(null);
+
+		return anonymousClassName;
+	}
+
+	public class NamedInnerClass {
+		public NamedInnerClass() {
+			namedInnerClassName = getClass().getName();
+		}
+	}
+
+	static class StaticInnerClass {
+		public StaticInnerClass() {
+			staticInnerClassName = getClass().getName();
+		}
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InterfaceFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InterfaceFieldTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InterfaceFieldTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/InterfaceFieldTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,16 @@
+package com.rc.retroweaver.tests;
+
+public class InterfaceFieldTest extends AbstractTest {
+
+	public void testInterfaceField() {
+		assertEquals("NAMES length", ConstImpl.NAMES.length, 3);
+	}
+
+	interface Const {
+		String[] NAMES = new String[] { "A", "B", "C" };
+	}
+
+	static class ConstImpl implements Const {
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/IterableTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/IterableTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/IterableTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/IterableTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,92 @@
+package com.rc.retroweaver.tests;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+/**
+ * Demonstrates Retroweaver's support for java.lang.Iterable.
+ */
+public class IterableTest extends AbstractTest {
+
+	public void testCollection() {
+		// The following code works for all Iterable classes in the JDK
+		// inheriting from Collection as the iterator() call is weaved into
+		// its IterableMethods static equivalent.
+
+		Iterable<Integer> itConversion = Arrays.asList(new Integer[] { 1, 2, 3 });
+
+		String s = "";
+		for (Integer i : itConversion) {
+			s = s + i + ':';
+		}
+		assertEquals("testCollection", s, "1:2:3:");
+	}
+	
+	public void testNull() {
+		String s = "";
+		try {
+			Iterable<Integer> iterable = null;
+			for(Integer i: iterable) {
+				s = s + i + ':';
+			}
+			fail("testNull Collection");
+		} catch (NullPointerException npe) {
+			success("testNull Collection");
+		}
+
+		try {
+			Integer[] ia = null;
+			for (Integer i : ia) {
+				s = s + i + ':';
+			}
+			fail("testNull Array");
+		} catch (NullPointerException npe) {
+			success("testNull Array");
+		}
+	}
+
+	public void testArray() {
+		Integer[] ia = new Integer[] { 1, 2, 3 };
+
+		String s = "";
+		for (Integer i : ia) {
+			s = s + i + ':';
+		}
+		assertEquals("testArray", s, "1:2:3:");		
+	}
+
+	public void testWeavedIterable() {
+		// This test works just fine, because the anonymous class is weaved
+		// by Retroweaver.
+
+		Iterable<Integer> it = new MyIterable();
+
+		String s = "";
+		for (Integer i : it) {
+			s = s + i + ':';
+		}
+		assertEquals("testWeavedIterable", s, "1:2:3:");
+	}
+
+	
+	public void testIterableMethod() {
+		try {
+			// regression test
+			MyIterable.getIteratable(new MyIterable());
+
+			success("testIterableMethod");
+		} catch (NoClassDefFoundError e) {
+			fail("NoClassDefFoundError: " + e.getMessage());
+		}
+	}
+
+	private static class MyIterable implements Iterable<Integer> {
+		public Iterator<Integer> iterator() {
+			return Arrays.asList(new Integer[] { 1, 2, 3 }).iterator();
+		}
+		
+		public static Iterable<Integer> getIteratable(MyIterable i) {
+			return i;
+		}
+	}
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/MapTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/MapTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/MapTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/MapTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,15 @@
+package com.rc.retroweaver.tests;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class MapTest extends AbstractTest {
+
+	public void testEmptyMap() {
+		Map<Object, Object> m = Collections.emptyMap();
+		// replaced with Collections.EMPTY_MAP
+
+		assertEquals("testEmptyMap", m.size(), 0);
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RetroweaverTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RetroweaverTestSuite.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RetroweaverTestSuite.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RetroweaverTestSuite.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,76 @@
+package com.rc.retroweaver.tests;
+
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+public class RetroweaverTestSuite extends TestSuite {
+
+	public RetroweaverTestSuite() {
+		super();
+
+		// tests valid for all JVM versions
+
+		addTestSuite(EnumTest.class);
+		addTestSuite(ClassLiteralTest.class);
+		addTestSuite(StringBuilderTest.class);
+		addTestSuite(ClassMethodsTest.class);
+		addTestSuite(AutoboxTest.class);
+		addTestSuite(FullCoverageTest.class);
+		addTestSuite(IterableTest.class);
+		addTestSuite(CollectionsTest.class);
+		addTestSuite(BigDecimalTest.class);
+		addTestSuite(SystemTest.class);
+
+		// tests below are only supposed to be run for some JVM versions
+
+		String version = System.getProperty("java.version");
+		if (version.length() < 3)
+			throw new UnsupportedOperationException("Unsupported Java version: " + version);
+
+		int v = version.charAt(2) - '0';
+
+		if (v < 2 || v > 6)
+			throw new UnsupportedOperationException("Unsupported Java version: " + version);
+
+		if (v < 5) {
+			// test missing classes and methods. Test for 1.4 and below only
+			addTestSuite(VerifierTest.class);
+
+			if (v > 2) {
+				// AppendableTest crashes JVM 1.2 classloader
+				addTestSuite(AppendableTest.class);
+				
+				// EMPTY_MAP field is only in 1.3+
+				addTestSuite(MapTest.class);
+			}
+		}
+
+		if (v > 3) {
+			// Concurrent backport is only for 1.4+
+			addTestSuite(ConcurrentTest.class);
+
+			// CharSequence class was defined in 1.4
+			addTestSuite(StringBufferTest.class);
+		}
+
+		// tests below should probably work, with some byte code changes...
+		if (v > 2) {
+			// FIXME: error JVM 1.2 for NAMES field in interface
+			addTestSuite(InterfaceFieldTest.class);
+		}
+
+		if (v > 3) {
+			// FIXME: problem in JVM 1.2 and 1.3 with inner classes
+			addTestSuite(InnerClassTest.class);
+		}
+	}
+
+	public static TestSuite suite() {
+		return new RetroweaverTestSuite();
+	}
+
+	public static void main(String args[]) {
+		TestRunner.run(suite());
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RmicEnumTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RmicEnumTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RmicEnumTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/RmicEnumTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,15 @@
+package com.rc.retroweaver.tests;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+interface RmicEnum extends Remote {
+    Object callColor(Color c) throws RemoteException;
+}
+
+public class RmicEnumTest implements RmicEnum {
+
+    public Object callColor(Color c) throws RemoteException {
+        return null;
+    }
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBufferTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBufferTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBufferTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,56 @@
+package com.rc.retroweaver.tests;
+
+/**
+ * Ensures that Retroweaver can handle append, insert and trimToSize methods
+ * for StringBuffer and StringBuilder and the new CharSequence based
+ * constructors that are new to 1.5.
+ */
+public class StringBufferTest extends AbstractTest {
+
+	public void testStringBuilder() {
+		CharSequence cs = "cs";
+
+		StringBuilder sb = new StringBuilder(cs);
+		assertEquals("testStringBuilder constructor", sb.toString(), "cs");
+
+		sb.trimToSize();
+
+		cs = "AB";
+		sb.append(cs);
+		assertEquals("testStringBuilder append", sb.toString(), "csAB");
+		cs = "CD";
+		sb.append(cs, 0, 2);
+		assertEquals("testStringBuilder append", sb.toString(), "csABCD");
+
+		cs = "abcd";
+		sb.insert(4, cs);
+		assertEquals("testStringBuilder insert", sb.toString(), "csABabcdCD");
+		cs = "efgh";
+		sb.insert(4, cs, 0, 4);
+		assertEquals("testStringBuilder insert", sb.toString(), "csABefghabcdCD");
+	}
+
+	public void testStringBuffer() {
+		CharSequence cs = "cs";
+
+		StringBuffer sb = new StringBuffer(cs);
+		assertEquals("testStringBuffer constructor", sb.toString(), "cs");
+
+		sb.trimToSize();
+
+		cs = "AB";
+		sb.append(cs);
+		assertEquals("testStringBuffer append", sb.toString(), "csAB");
+		cs = "CD";
+		sb.append(cs, 0, 2);
+		assertEquals("testStringBuffer append", sb.toString(), "csABCD");
+
+		cs = "abcd";
+		sb.insert(4, cs);
+		assertEquals("testStringBuffer insert", sb.toString(), "csABabcdCD");
+		cs = "efgh";
+		sb.insert(4, cs, 0, 4);
+		assertEquals("testStringBuffer insert", sb.toString(), "csABefghabcdCD");
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBuilderTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBuilderTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/StringBuilderTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,20 @@
+package com.rc.retroweaver.tests;
+
+/**
+ * Ensures that Retroweaver can handle compiler-generated calls to StringBuilder
+ * that are new to 1.5.
+ */
+public class StringBuilderTest extends AbstractTest {
+
+	public void testSimple() {
+		String a = "Hello, ";
+		String b = "world!";
+		String c = a + b;
+		assertEquals("StringBuilder", c, "Hello, world!");
+
+		String s = "This is " + StringBuilderTest.class + " version " + 1;
+		assertEquals("StringBuilder", s,
+				"This is class com.rc.retroweaver.tests.StringBuilderTest version 1");
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/SystemTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/SystemTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/SystemTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/SystemTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,12 @@
+package com.rc.retroweaver.tests;
+
+public class SystemTest extends AbstractTest {
+
+	public void testNanoTime() {
+		Long t1 = System.nanoTime();
+		Long t2 = System.nanoTime();
+
+		assertTrue("testNanoTime", t2 >= t1);
+	}
+
+}

Added: incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/VerifierTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/VerifierTest.java?rev=419720&view=auto
==============================================================================
--- incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/VerifierTest.java
(added)
+++ incubator/abdera/java/trunk/build/tools/retroweaver/src/com/rc/retroweaver/tests/VerifierTest.java
Thu Jul  6 15:08:30 2006
@@ -0,0 +1,86 @@
+package com.rc.retroweaver.tests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Iterator;
+
+public class VerifierTest extends AbstractTest {
+
+	public void testVerifierNoWarnings() {
+		// Shouldn't generate warning, because Retroweaver handles Iterables
+		class It implements Iterable {
+			public Iterator iterator() {
+				return Arrays.asList(new int[] { 1, 2, 3 }).iterator();
+			}
+		}
+
+		// Shouldn't generate a warning, because Retroweaver handles
+		// StringBuilder
+		String s1 = "a" + 3;
+
+		// Shouldn't generate warnings, because Retroweaver handles autoboxing
+		// and autounboxing
+		Integer i = 3;
+		int i_ = i;
+
+		assertTrue("testVerifierNoWarnings", (i_ == 3) && (s1.equals("a3")));
+	}
+
+	/**
+	 * RefVerifier tests, shouldn't generate warnings
+	 * 
+	 * @author Guntis Ozols
+	 */
+	public void testVerifierNoWarnings2() throws IOException {
+		assertEquals("Class name", getCells().getClass().getName(),
+				"[[Lcom.rc.retroweaver.tests.VerifierTest$Cell;");
+
+		ByteArrayOutputStreamEx bout = new ByteArrayOutputStreamEx();
+		bout.write("Hello\n".getBytes());
+		bout.writeTo(new ByteArrayOutputStream());
+		Hello2 hello = new HelloImpl();
+		hello.hello();
+
+		success("testVerifierNoWarnings2");
+	}
+
+	interface Hello1 {
+		void hello();
+	}
+
+	interface Hello2 extends Hello1 {
+	}
+
+	static class HelloImpl implements Hello2 {
+		public void hello() {
+		}
+	}
+
+	static class Cell {
+	}
+
+	static class ByteArrayOutputStreamEx extends ByteArrayOutputStream {
+		public void writeTo(OutputStream out) throws IOException {
+			out.write(buf, 0, count);
+		}
+	}
+
+	static Cell[][] getCells() {
+		return new Cell[1][1];
+	}
+
+}
+
+interface Address {
+
+	int getZip();
+}
+
+abstract class AbstractAddress implements Address {
+
+	public void displayZip() {
+		System.out.println(getZip());
+	}
+}



Mime
View raw message