* tests/regression/resolving/test_return_subtype_violated.java:
authoredwin <none@none>
Sun, 4 Mar 2007 12:28:37 +0000 (12:28 +0000)
committeredwin <none@none>
Sun, 4 Mar 2007 12:28:37 +0000 (12:28 +0000)
New test.

* tests/regression/resolving/Makefile.am: Added new test.

src/mm/boehm.c
tests/regression/resolving/Makefile.am
tests/regression/resolving/classes2/BarPassFoo.java
tests/regression/resolving/test_return_subtype_violated.java [new file with mode: 0644]

index 81c028ccee63e69002df91493c4816ebbce3681b..cf9148d616fb224c844b38e666b455ae92494ee6 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: boehm.c 7355 2007-02-14 10:57:32Z twisti $
+   $Id: boehm.c 7309 2007-02-09 12:51:00Z twisti $
 
 */
 
index 6d6dbf07dca4db99323ed752623fa140ec04a824..96e553ed0f80e0e7e7a8abed848596f7f529e508 100644 (file)
@@ -17,6 +17,7 @@ TEST_SOURCE_FILES = \
        test_param_loading_constraint_violated.java \
        test_param_subtype_violated.java \
        test_retval_loading_constraint_violated.java \
+       test_return_subtype_violated.java \
        test_simple_lazy_load.java
 
 TEST_NAMES = \
@@ -25,6 +26,7 @@ TEST_NAMES = \
        test_param_loading_constraint_violated \
        test_param_subtype_violated \
        test_retval_loading_constraint_violated \
+       test_return_subtype_violated \
        test_simple_lazy_load
 
 EXTRA_DIST = $(HARNESS_SOURCE_FILES) $(TEST_SOURCE_FILES)
index 23c02c1de883a1e28fd47ac6b79abea918ab5d9d..f9a8fc97a8d660d32d04ed0508c44361074f39fd 100644 (file)
@@ -26,6 +26,28 @@ public class BarPassFoo {
     public Foo createFoo() {
         return new Foo();
     }
+
+    public DerivedFoo createDerivedFoo() {
+        return new DerivedFoo();
+    }
+
+    public Foo createDerivedFooReturnFoo() {
+        return new DerivedFoo();
+    }
+
+    public static String getDerivedFoo() {
+        BarPassFoo bar = new BarPassFoo();
+
+        bar.createDerivedFoo();
+        return "no exception";
+    }
+
+    public static String getDerivedFooAsFoo() {
+        BarPassFoo bar = new BarPassFoo();
+
+        bar.createDerivedFooReturnFoo();
+        return "no exception";
+    }
 }
 
 // vim: et sw=4
diff --git a/tests/regression/resolving/test_return_subtype_violated.java b/tests/regression/resolving/test_return_subtype_violated.java
new file mode 100644 (file)
index 0000000..f2dfb9c
--- /dev/null
@@ -0,0 +1,55 @@
+public class test_return_subtype_violated {
+
+    public static void main(String[] args) {
+        TestController ct = new TestController();
+
+        TestLoader ld1 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld1", ct);
+        TestLoader ld2 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld2", ct);
+
+        ld1.addClassfile("Foo", "classes1/Foo.class");
+        ld1.addClassfile("DerivedFoo", "classes2/DerivedFoo.class");
+        ld1.addParentDelegation("java.lang.Object");
+        ld1.addParentDelegation("java.lang.String");
+
+        ld2.addClassfile("BarPassFoo", "classes2/BarPassFoo.class");
+        ld2.addClassfile("Foo", "classes2/Foo.class");
+        ld2.addDelegation("DerivedFoo", ld1);
+        ld2.addParentDelegation("java.lang.Object");
+        ld2.addParentDelegation("java.lang.String");
+
+        // loading BarPassFoo
+        ct.expect("requested", ld2, "BarPassFoo");
+        ct.expect("defined", ld2, "<BarPassFoo>");
+        ct.expect("loaded", ld2, "<BarPassFoo>");
+
+        Class cls = ct.loadClass(ld2, "BarPassFoo");
+
+        // linking BarPassFoo
+        ct.expectLoadFromSystem(ld2, "java.lang.Object");
+
+        // executing createDerivedFoo
+        ct.expectDelegationAndDefinition(ld2, ld1, "DerivedFoo");
+        // ...linking (ld2, DerivedFoo)
+        ct.expect("requested", ld1, "Foo");
+        ct.expect("defined", ld1, "<Foo>");
+        ct.expectLoadFromSystem(ld1, "java.lang.Object");
+
+        ct.checkStringGetter(cls, "getDerivedFoo", "no exception");
+        ct.expectEnd();
+
+        // subtype check (DerivedFoo subtypeof Foo)
+        ct.expect("requested", ld2, "Foo");
+        ct.expect("defined", ld2, "<Foo>");
+        // ... linking (ld2, Foo), j.l.O is already loaded
+
+        // the subtype constraint ((ld2, DerivedFoo) subtypeof (ld2, Foo)) is violated
+        ct.expect("exception", "java.lang.LinkageError", "<BarPassFoo>");
+
+        ct.checkStringGetterMustFail(cls, "getDerivedFooAsFoo");
+
+        ct.exit();
+    }
+
+}
+
+// vim: et sw=4