* tests/regression/resolving/test_return_subtype_ok.java: New test.
authoredwin <none@none>
Sun, 4 Mar 2007 12:32:59 +0000 (12:32 +0000)
committeredwin <none@none>
Sun, 4 Mar 2007 12:32:59 +0000 (12:32 +0000)
* tests/regression/resolving/Makefile.am: Added new test.

tests/regression/resolving/Makefile.am
tests/regression/resolving/test_return_subtype_ok.java [new file with mode: 0644]

index 96e553ed0f80e0e7e7a8abed848596f7f529e508..560f993c61a1c985beffaeec04699e3651055bd2 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_ok.java \
        test_return_subtype_violated.java \
        test_simple_lazy_load.java
 
@@ -26,6 +27,7 @@ TEST_NAMES = \
        test_param_loading_constraint_violated \
        test_param_subtype_violated \
        test_retval_loading_constraint_violated \
+       test_return_subtype_ok \
        test_return_subtype_violated \
        test_simple_lazy_load
 
diff --git a/tests/regression/resolving/test_return_subtype_ok.java b/tests/regression/resolving/test_return_subtype_ok.java
new file mode 100644 (file)
index 0000000..cec4f66
--- /dev/null
@@ -0,0 +1,50 @@
+public class test_return_subtype_ok {
+
+    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.addDelegation("Foo", ld1);
+        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.expectDelegationAndFound(ld2, ld1, "Foo");
+
+        ct.checkStringGetter(cls, "getDerivedFooAsFoo", "no exception");
+
+        ct.exit();
+    }
+
+}
+
+// vim: et sw=4