PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/d/director_basic_runme.2.d

#
D | 46 lines | 39 code | 7 blank | 0 comment | 6 complexity | 5151f8ad46c1253fe63d59f4f7e59645 MD5 | raw file
 1module director_basic_runme;
 2
 3import std.exception;
 4import director_basic.A1;
 5import director_basic.Bar;
 6import director_basic.Foo;
 7import director_basic.MyClass;
 8
 9void main() {
10  auto a = new director_basic_MyFoo();
11  enforce(a.ping() == "director_basic_MyFoo::ping()", "a.ping()");
12  enforce(a.pong() == "Foo::pong();director_basic_MyFoo::ping()", "a.pong()");
13
14  auto b = new Foo();
15  enforce(b.ping() == "Foo::ping()", "b.ping()");
16  enforce(b.pong() == "Foo::pong();Foo::ping()", "b.pong()");
17
18  {
19    scope a1 = new A1(1, false);
20  }
21
22  auto my = new MyOverriddenClass();
23  my.expectNull = true;
24  enforce(MyClass.call_pmethod(my, null) is null, "null pointer conversion problem");
25  auto myBar = new Bar();
26  my.expectNull = false;
27  auto myNewBar = MyClass.call_pmethod(my, myBar);
28  enforce(myNewBar !is null, "non-null pointer conversion problem");
29  myNewBar.x = 10;
30}
31
32class director_basic_MyFoo : Foo {
33  public override string ping() {
34    return "director_basic_MyFoo::ping()";
35  }
36}
37
38class MyOverriddenClass : MyClass {
39  public bool expectNull = false;
40  public bool nonNullReceived = false;
41  public override Bar pmethod(Bar b) {
42    if (expectNull && (b !is null))
43      throw new Exception("null not received as expected");
44    return b;
45  }
46}