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

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

#
D | 63 lines | 48 code | 15 blank | 0 comment | 6 complexity | 2ca7e5070b15c8e96555e3ffe1c05977 MD5 | raw file
 1module allprotected_runme;
 2
 3import allprotected.Klass;
 4import allprotected.ProtectedBase;
 5import std.conv : text;
 6import std.exception : enforce;
 7
 8void main() {
 9  auto mpb = new MyProtectedBase("MyProtectedBase");
10  mpb.accessProtected();
11}
12
13class MyProtectedBase : ProtectedBase {
14public:
15  this(string name) {
16    super(name);
17  }
18
19  void accessProtected() {
20    string s = virtualMethod();
21    enforce(s == "ProtectedBase", "Failed, got '" ~ s ~ "'");
22
23    Klass k;
24    void expect(string name) {
25      auto kName = k.getName();
26      enforce(kName == name, "Failed, expected '" ~ name ~ "' instead of '" ~
27        kName ~ "'.");
28    }
29
30    k = instanceMethod(new Klass("xyz"));
31    expect("xyz");
32
33    k = instanceOverloaded(new Klass("xyz"));
34    expect("xyz");
35
36    k = instanceOverloaded(new Klass("xyz"), "abc");
37    expect("abc");
38
39    k = staticMethod(new Klass("abc"));
40    expect("abc");
41
42    k = staticOverloaded(new Klass("xyz"));
43    expect("xyz");
44
45    k = staticOverloaded(new Klass("xyz"), "abc");
46    expect("abc");
47
48    instanceMemberVariable = 30;
49    int i = instanceMemberVariable;
50    enforce(i == 30, text("Failed, expected ", 30, "instead of ", i));
51
52    staticMemberVariable = 40;
53    i = staticMemberVariable;
54    enforce(i == 40, text("Failed, expected ", 40, "instead of ", i));
55
56    i = staticConstMemberVariable;
57    enforce(i == 20, text("Failed, expected ", 20, "instead of ", i));
58
59    anEnum = ProtectedBase.AnEnum.EnumVal1;
60    ProtectedBase.AnEnum ae = anEnum;
61    enforce(ae == ProtectedBase.AnEnum.EnumVal1);
62  }
63}