Debian Codegraph @

gcc/testsuite/gdc.test/runnable/interface.d

raw
1 import core.stdc.stdio;
2
3 /*******************************************/
4
5 interface IStream
6 {
7 int read();
8 }
9
10 interface OStream
11 {
12 int write();
13 }
14
15 class IO : IStream, OStream
16 {
17 int read() { return 7; }
18 int write() { return 267; }
19 }
20
21 void foo(IStream i, OStream o)
22 {
23 printf("foo(i = %p, o = %p)\n", i, o);
24 assert(i.read() == 7);
25 assert(o.write() == 267);
26 }
27
28 void test1()
29 {
30 IO io = new IO();
31 printf("io = %p\n", io);
32 foo(io, io);
33 destroy(io);
34 }
35
36 /*******************************************/
37
38 interface I { }
39 class C : I
40 {
41 ~this() { printf("~C()\n"); }
42 }
43
44 void test2()
45 {
46 I i = new C();
47 destroy(i);
48
49 {
50 scope I j = new C();
51 }
52 }
53
54 /*******************************************/
55
56 interface I3 {
57 void h();
58 }
59 interface K3 {
60 void f();
61 }
62
63 interface J3 : I3, K3 {}
64
65 class A3 : J3 {
66 short x = 3;
67
68 void f(){ assert(x == 3); }
69 void h(){ assert(x == 3); }
70 }
71
72 void test3()
73 {
74 auto a = new A3();
75 a.f();
76 a.h();
77 J3 j = a;
78 j.f();
79 K3 k = a;
80 k.f();
81 assert(&j.f == &k.f); // https://issues.dlang.org/show_bug.cgi?id=3706
82 }
83
84 /*******************************************/
85
86 int main()
87 {
88 test1();
89 test2();
90 test3();
91
92 printf("Success\n");
93 return 0;
94 }