commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r700710 - in /commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation: asm/RewriteBugsTestCase.java rewrite/RewriteBugs.java tests/AbstractRewriteBugsTestCase.java
Date Wed, 01 Oct 2008 08:08:24 GMT
Author: tcurdt
Date: Wed Oct  1 01:08:23 2008
New Revision: 700710

URL: http://svn.apache.org/viewvc?rev=700710&view=rev
Log:
https://issues.apache.org/jira/browse/SANDBOX-260

ASM rewriting testcases showing bugs in ASM transformer


Added:
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
  (with props)
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
  (with props)
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
  (with props)

Added: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java?rev=700710&view=auto
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
(added)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
Wed Oct  1 01:08:23 2008
@@ -0,0 +1,27 @@
+package org.apache.commons.javaflow.bytecode.transformation.asm;
+
+import org.apache.commons.javaflow.bytecode.transformation.AbstractTransformerTestCase;
+import org.apache.commons.javaflow.bytecode.transformation.ClassTransformerClassLoader;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class RewriteBugsTestCase extends TestCase
+{
+
+	public static Test suite() throws Exception {
+
+    	final ClassTransformerClassLoader classloader =
+            new ClassTransformerClassLoader(new AsmClassTransformer());
+        
+        final Class clazz = classloader.loadClass(
+        		AbstractTransformerTestCase.getTestCaseClassName(
+        				RewriteBugsTestCase.class));
+
+        final TestSuite suite = new TestSuite(classloader.createImplementationOf(clazz));
+        suite.setName("ASM " + clazz.getName());
+        return suite;
+    }
+	
+}

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/asm/RewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java?rev=700710&view=auto
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
(added)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
Wed Oct  1 01:08:23 2008
@@ -0,0 +1,150 @@
+package org.apache.commons.javaflow.bytecode.transformation.rewrite;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class RewriteBugs
+{
+
+	/**
+	 * 
+	 * ASM rewriting BUG!
+	 * 
+	 *  Calculate the cartesian product of parameters.
+	 *  Example: names = {"a", "b"}, values = {{"1", "2"}, {"3", "4"}}
+	 *  		 result = {{"a"="1", "b"="3"}, {"a"="2", "b"="3"}, {"a"="1", "b"="4"}, {"a=2", b="4"}}
+	 *  @param names The names.
+	 *  @param values The values (must be some form of collection, i.e. array, list, iterator
etc.)
+	 */
+	public static List calculateCartesianProduct(String[] names, Object[] values)
+	{
+		//ArrayList ret = SCollection.createArrayList();
+		ArrayList ret = new ArrayList();
+		if(names==null || values==null)
+			return ret;
+		if(names.length!=values.length)
+			throw new IllegalArgumentException("Must have same length: "+names.length+" "+values.length);
+		
+		//HashMap binding = SCollection.createHashMap();
+		HashMap binding = new HashMap();
+		Iterator[] iters = new Iterator[values.length];
+		
+		for(int i=0; i<values.length; i++)
+		{
+			// When one collection is empty -> no binding at all.
+			// First binding consists of all first elements.
+			//iters[i] = SReflect.getIterator(values[i]);
+			iters[i] = RewriteBugs.getIterator(values[i]);
+			if(!iters[i].hasNext())
+			{
+				return ret;
+			}
+			else
+			{
+				binding.put(names[i], iters[i].next());
+			}
+		}
+		ret.add(binding);
+		
+		// Iterate through binding sets for subsequent bindings.
+		while(true)
+		{
+			// Calculate next binding.
+			// Copy old binding and change one value.
+			binding = (HashMap)binding.clone();
+			int i = 0;
+			for(; i<values.length && !iters[i].hasNext(); i++)
+			{
+				// Overflow: Re-init iterator.
+				//iters[i] = SReflect.getIterator(values[i]);
+				iters[i] = RewriteBugs.getIterator(values[i]);
+				binding.put(names[i], iters[i].next());
+			}
+			if(i<iters.length)
+			{
+				binding.put(names[i], iters[i].next());
+			}
+			else
+			{
+				// Overflow in last iterator: done.
+				// Hack: Unnecessarily re-inits all iterators before break ?
+				break;
+			}
+			ret.add(binding);
+		}
+		
+		return ret;
+	}
+	
+	
+	
+	// 
+	// ---- helper methods -- copied from jadex utility classes -----
+	//
+	
+	/**
+	 *  Get an iterator for an arbitrary collection object.
+	 *  Supports iterators, enumerations, java.util.Collections,
+	 *  java.util.Maps, arrays. Null is converted to empty iterator.
+	 *  @param collection	The collection object.
+	 *  @return An iterator over the collection.
+	 *  @throws IllegalArgumentException when argument is not
+	 * 		one of (Iterator, Enumeration, Collection, Map, Array).
+	 */
+	public static Iterator	getIterator(Object collection)
+	{
+		if(collection==null)
+		{
+			return Collections.EMPTY_LIST.iterator();
+		}
+		else if(collection instanceof Iterator)
+		{
+			return (Iterator)collection;
+		}
+		else if(collection instanceof Enumeration)
+		{
+			// Return enumeration wrapper.
+			final Enumeration eoc	= (Enumeration)collection;
+			return new Iterator()
+			{
+				public boolean	hasNext()	{return eoc.hasMoreElements();}
+				public Object	next()	{return eoc.nextElement();}
+				public void	remove(){throw new UnsupportedOperationException(
+					"remove() not supported for enumerations");}
+			};
+		}
+		else if(collection instanceof Collection)
+		{
+			return ((Collection)collection).iterator();
+		}
+		else if(collection instanceof Map)
+		{
+			return ((Map)collection).values().iterator();
+		}
+		else if(collection!=null && collection.getClass().isArray())
+		{
+			// Return array wrapper.
+			final Object array	= collection;
+			return new Iterator()
+			{
+				int i=0;
+				public boolean	hasNext()	{return i<Array.getLength(array);}
+				public Object	next()	{return Array.get(array, i++);}
+				public void	remove()	{throw new UnsupportedOperationException(
+					"remove() not supported for arrays");}
+			};
+		}
+		else
+		{
+			throw new IllegalArgumentException("Cannot iterate over "+collection);
+		}
+	}
+	
+}
\ No newline at end of file

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/RewriteBugs.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java?rev=700710&view=auto
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
(added)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
Wed Oct  1 01:08:23 2008
@@ -0,0 +1,15 @@
+package org.apache.commons.javaflow.bytecode.transformation.tests;
+
+import org.apache.commons.javaflow.Continuation;
+import org.apache.commons.javaflow.bytecode.transformation.AbstractTransformerTestCase;
+import org.apache.commons.javaflow.bytecode.transformation.rewrite.RewriteBugs;
+import org.apache.commons.javaflow.bytecode.transformation.rewrite.Simple;
+
+public class AbstractRewriteBugsTestCase extends AbstractTransformerTestCase
+{
+
+	public void testASMRewriteBug() throws Exception {
+        //final RewriteBugs r = new RewriteBugs();
+        RewriteBugs.calculateCartesianProduct(new String[]{"a","b"}, new Object[]{"1","2"});
+    }
+}

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractRewriteBugsTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message