You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2015/07/27 00:10:02 UTC
svn commit: r1692775 - in /commons/proper/bcel/trunk/src/test:
java/org/apache/bcel/verifier/ java/org/apache/bcel/verifier/tests/
resources/org/apache/bcel/verifier/tests/
Author: chas
Date: Sun Jul 26 22:10:02 2015
New Revision: 1692775
URL: http://svn.apache.org/r1692775
Log:
BCEL-220
No magic resource classes
Added:
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess03Creator.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn01Creator.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
Removed:
commons/proper/bcel/trunk/src/test/resources/org/apache/bcel/verifier/tests/TestArrayAccess02.class
commons/proper/bcel/trunk/src/test/resources/org/apache/bcel/verifier/tests/TestArrayAccess03.class
commons/proper/bcel/trunk/src/test/resources/org/apache/bcel/verifier/tests/TestArrayAccess04.class
commons/proper/bcel/trunk/src/test/resources/org/apache/bcel/verifier/tests/TestReturn01.class
commons/proper/bcel/trunk/src/test/resources/org/apache/bcel/verifier/tests/TestReturn03.class
Modified:
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java?rev=1692775&r1=1692774&r2=1692775&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java Sun Jul 26 22:10:02 2015
@@ -18,16 +18,24 @@
package org.apache.bcel.verifier;
+import java.io.IOException;
+
+import org.apache.bcel.verifier.tests.TestArrayAccess02Creator;
+import org.apache.bcel.verifier.tests.TestArrayAccess03Creator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04Creator;
public class VerifierArrayAccessTestCase extends AbstractVerifierTestCase {
- public void testInvalidArrayAccess() {
+ public void testInvalidArrayAccess() throws IOException {
+ new TestArrayAccess03Creator().create();
assertVerifyRejected("TestArrayAccess03", "Verification of an arraystore instruction on an object must fail.");
+ new TestArrayAccess04Creator().create();
assertVerifyRejected("TestArrayAccess04", "Verification of an arraystore instruction of an int on an array of references must fail.");
}
-
- public void testValidArrayAccess() {
+
+ public void testValidArrayAccess() throws IOException {
assertVerifyOK("TestArrayAccess01", "Verification of an arraystore instruction on an array that is not compatible with the stored element must pass.");
+ new TestArrayAccess02Creator().create();
assertVerifyOK("TestArrayAccess02", "Verification of an arraystore instruction on an array that is not compatible with the stored element must pass.");
}
Modified: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java?rev=1692775&r1=1692774&r2=1692775&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java Sun Jul 26 22:10:02 2015
@@ -17,10 +17,17 @@
package org.apache.bcel.verifier;
+import java.io.IOException;
+
+import org.apache.bcel.verifier.tests.TestReturn01Creator;
+import org.apache.bcel.verifier.tests.TestReturn03Creator;
+
public class VerifierReturnTestCase extends AbstractVerifierTestCase {
- public void testInvalidReturn() {
+ public void testInvalidReturn() throws IOException {
+ new TestReturn01Creator().create();
assertVerifyRejected("TestReturn01", "Verification of a void method that returns an object must fail.");
+ new TestReturn03Creator().create();
assertVerifyRejected("TestReturn03", "Verification of an int method that returns null must fail.");
}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess02Creator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.bcel.verifier.tests;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.PUSH;
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess02Creator extends TestCreator implements Constants {
+ private InstructionFactory _factory;
+ private ConstantPoolGen _cp;
+ private ClassGen _cg;
+
+ public TestArrayAccess02Creator() {
+ _cg = new ClassGen("org.apache.bcel.verifier.tests.TestArrayAccess02", "java.lang.Object", "TestArrayAccess02.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
+
+ _cp = _cg.getConstantPool();
+ _factory = new InstructionFactory(_cg, _cp);
+ }
+
+ public void create(OutputStream out) throws IOException {
+ createMethod_0();
+ createMethod_1();
+ _cg.getJavaClass().dump(out);
+ }
+
+ private void createMethod_0() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "org.apache.bcel.verifier.tests.TestArrayAccess02", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+
+ private void createMethod_1() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[] { }, "test", "org.apache.bcel.verifier.tests.TestArrayAccess02", il, _cp);
+
+ InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
+ il.append(_factory.createNewArray(new ObjectType("org.apache.bcel.verifier.tests.TestArrayAccess02"), (short) 1));
+ il.append(_factory.createStore(Type.OBJECT, 0));
+ InstructionHandle ih_5 = il.append(new PUSH(_cp, 1));
+ il.append(_factory.createNewArray(Type.STRING, (short) 1));
+ il.append(_factory.createStore(Type.OBJECT, 1));
+ InstructionHandle ih_10 = il.append(_factory.createLoad(Type.OBJECT, 1));
+ il.append(new PUSH(_cp, 0));
+ il.append(_factory.createNew("org.apache.bcel.verifier.tests.TestArrayAccess02"));
+ il.append(InstructionConstants.DUP);
+ il.append(_factory.createInvoke("org.apache.bcel.verifier.tests.TestArrayAccess02", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ il.append(InstructionConstants.AASTORE);
+ InstructionHandle ih_20 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess03Creator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess03Creator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess03Creator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess03Creator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.bcel.verifier.tests;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.ObjectType;
+import org.apache.bcel.generic.PUSH;
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess03Creator extends TestCreator implements Constants {
+ private InstructionFactory _factory;
+ private ConstantPoolGen _cp;
+ private ClassGen _cg;
+
+ public TestArrayAccess03Creator() {
+ _cg = new ClassGen("org.apache.bcel.verifier.tests.TestArrayAccess03", "java.lang.Object", "TestArrayAccess03.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
+
+ _cp = _cg.getConstantPool();
+ _factory = new InstructionFactory(_cg, _cp);
+ }
+
+ public void create(OutputStream out) throws IOException {
+ createMethod_0();
+ createMethod_1();
+ _cg.getJavaClass().dump(out);
+ }
+
+ private void createMethod_0() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "org.apache.bcel.verifier.tests.TestArrayAccess03", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+
+ private void createMethod_1() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, new Type[] { Type.OBJECT }, new String[] { "arg0" }, "test", "org.apache.bcel.verifier.tests.TestArrayAccess03", il, _cp);
+
+ InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
+ il.append(_factory.createNewArray(new ObjectType("org.apache.bcel.verifier.tests.TestArrayAccess03"), (short) 1));
+ il.append(_factory.createStore(Type.OBJECT, 1));
+ InstructionHandle ih_5 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(new PUSH(_cp, 0));
+ il.append(_factory.createNew("org.apache.bcel.verifier.tests.TestArrayAccess03"));
+ il.append(InstructionConstants.DUP);
+ il.append(_factory.createInvoke("org.apache.bcel.verifier.tests.TestArrayAccess03", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ il.append(InstructionConstants.AASTORE);
+ InstructionHandle ih_15 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+}
\ No newline at end of file
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.bcel.verifier.tests;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.PUSH;
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04Creator extends TestCreator implements Constants {
+ private InstructionFactory _factory;
+ private ConstantPoolGen _cp;
+ private ClassGen _cg;
+
+ public TestArrayAccess04Creator() {
+ _cg = new ClassGen("org.apache.bcel.verifier.tests.TestArrayAccess04", "java.lang.Object", "TestArrayAccess04.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
+
+ _cp = _cg.getConstantPool();
+ _factory = new InstructionFactory(_cg, _cp);
+ }
+
+ public void create(OutputStream out) throws IOException {
+ createMethod_0();
+ createMethod_1();
+ _cg.getJavaClass().dump(out);
+ }
+
+ private void createMethod_0() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "org.apache.bcel.verifier.tests.TestArrayAccess04", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+
+ private void createMethod_1() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, new Type[] { Type.OBJECT }, new String[] { "arg0" }, "test", "org.apache.bcel.verifier.tests.TestArrayAccess04", il, _cp);
+
+ InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
+ il.append(_factory.createNewArray(Type.OBJECT, (short) 1));
+ il.append(_factory.createStore(Type.OBJECT, 1));
+ InstructionHandle ih_5 = il.append(new PUSH(_cp, 1));
+ il.append(_factory.createStore(Type.INT, 2));
+ InstructionHandle ih_7 = il.append(_factory.createLoad(Type.OBJECT, 1));
+ il.append(new PUSH(_cp, 0));
+ il.append(_factory.createLoad(Type.INT, 2));
+ il.append(InstructionConstants.AASTORE);
+ InstructionHandle ih_11 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+}
\ No newline at end of file
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestCreator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,61 @@
+package org.apache.bcel.verifier.tests;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URISyntaxException;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+public abstract class TestCreator {
+
+ public void create() throws IOException {
+ File classFile = new File(getPackageFolder(), getClassName());
+ FileOutputStream out = new FileOutputStream(classFile);
+ try {
+ create(out);
+ }
+ finally {
+ out.close();
+ }
+ }
+
+ private String getClassName() {
+ String name = getClass().getName();
+ return name.substring(name.lastIndexOf('.')+1).replace("Creator", ".class");
+ }
+
+ private File getPackageFolder() throws IOException {
+ return new File(getClassesFolder(), getPackageName());
+ }
+
+ protected String getPackageName() {
+ return getClass().getPackage().getName().replace('.', '/');
+ }
+
+ private File getClassesFolder() throws IOException {
+ try {
+ return new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+ }
+
+ public abstract void create(OutputStream out) throws IOException;
+}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn01Creator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn01Creator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn01Creator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn01Creator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.bcel.verifier.tests;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.Type;
+
+public class TestReturn01Creator extends TestCreator implements Constants {
+ private InstructionFactory _factory;
+ private ConstantPoolGen _cp;
+ private ClassGen _cg;
+
+ public TestReturn01Creator() {
+ _cg = new ClassGen("org.apache.bcel.verifier.tests.TestReturn01", "java.lang.Object", "TestReturn01.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
+
+ _cp = _cg.getConstantPool();
+ _factory = new InstructionFactory(_cg, _cp);
+ }
+
+ public void create(OutputStream out) throws IOException {
+ createMethod_0();
+ createMethod_1();
+ _cg.getJavaClass().dump(out);
+ }
+
+ private void createMethod_0() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "org.apache.bcel.verifier.tests.TestReturn01", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+
+ private void createMethod_1() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, Type.NO_ARGS, new String[] { }, "foo", "org.apache.bcel.verifier.tests.TestReturn01", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createNew("java.lang.Object"));
+ il.append(InstructionConstants.DUP);
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ il.append(InstructionConstants.NOP);
+ InstructionHandle ih_8 = il.append(_factory.createReturn(Type.OBJECT));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java?rev=1692775&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java Sun Jul 26 22:10:02 2015
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.bcel.verifier.tests;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionConstants;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03Creator extends TestCreator implements Constants {
+ private InstructionFactory _factory;
+ private ConstantPoolGen _cp;
+ private ClassGen _cg;
+
+ public TestReturn03Creator() {
+ _cg = new ClassGen("org.apache.bcel.verifier.tests.TestReturn03", "java.lang.Object", "TestReturn03.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
+
+ _cp = _cg.getConstantPool();
+ _factory = new InstructionFactory(_cg, _cp);
+ }
+
+ public void create(OutputStream out) throws IOException {
+ createMethod_0();
+ createMethod_1();
+ _cg.getJavaClass().dump(out);
+ }
+
+ private void createMethod_0() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "org.apache.bcel.verifier.tests.TestReturn03", il, _cp);
+
+ InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
+ il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
+ InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+
+ private void createMethod_1() {
+ InstructionList il = new InstructionList();
+ MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] { }, "test3", "org.apache.bcel.verifier.tests.TestReturn03", il, _cp);
+
+ InstructionHandle ih_0 = il.append(InstructionConstants.ACONST_NULL);
+ il.append(_factory.createReturn(Type.OBJECT));
+ method.setMaxStack();
+ method.setMaxLocals();
+ _cg.addMethod(method.getMethod());
+ il.dispose();
+ }
+}