f2dfb9c13fa08b8bb5c478219a0d4411f6a1150d
[cacao.git] / tests / regression / resolving / test_return_subtype_violated.java
1 public class test_return_subtype_violated {
2
3     public static void main(String[] args) {
4         TestController ct = new TestController();
5
6         TestLoader ld1 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld1", ct);
7         TestLoader ld2 = new TestLoader(ClassLoader.getSystemClassLoader(), "ld2", ct);
8
9         ld1.addClassfile("Foo", "classes1/Foo.class");
10         ld1.addClassfile("DerivedFoo", "classes2/DerivedFoo.class");
11         ld1.addParentDelegation("java.lang.Object");
12         ld1.addParentDelegation("java.lang.String");
13
14         ld2.addClassfile("BarPassFoo", "classes2/BarPassFoo.class");
15         ld2.addClassfile("Foo", "classes2/Foo.class");
16         ld2.addDelegation("DerivedFoo", ld1);
17         ld2.addParentDelegation("java.lang.Object");
18         ld2.addParentDelegation("java.lang.String");
19
20         // loading BarPassFoo
21         ct.expect("requested", ld2, "BarPassFoo");
22         ct.expect("defined", ld2, "<BarPassFoo>");
23         ct.expect("loaded", ld2, "<BarPassFoo>");
24
25         Class cls = ct.loadClass(ld2, "BarPassFoo");
26
27         // linking BarPassFoo
28         ct.expectLoadFromSystem(ld2, "java.lang.Object");
29
30         // executing createDerivedFoo
31         ct.expectDelegationAndDefinition(ld2, ld1, "DerivedFoo");
32         // ...linking (ld2, DerivedFoo)
33         ct.expect("requested", ld1, "Foo");
34         ct.expect("defined", ld1, "<Foo>");
35         ct.expectLoadFromSystem(ld1, "java.lang.Object");
36
37         ct.checkStringGetter(cls, "getDerivedFoo", "no exception");
38         ct.expectEnd();
39
40         // subtype check (DerivedFoo subtypeof Foo)
41         ct.expect("requested", ld2, "Foo");
42         ct.expect("defined", ld2, "<Foo>");
43         // ... linking (ld2, Foo), j.l.O is already loaded
44
45         // the subtype constraint ((ld2, DerivedFoo) subtypeof (ld2, Foo)) is violated
46         ct.expect("exception", "java.lang.LinkageError", "<BarPassFoo>");
47
48         ct.checkStringGetterMustFail(cls, "getDerivedFooAsFoo");
49
50         ct.exit();
51     }
52
53 }
54
55 // vim: et sw=4