aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/java/cpp11_director_using_constructor_runme.java
blob: e1508a975dbcecfa21d02c9aa36c6ef240d79d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323

import cpp11_director_using_constructor.*;

public class cpp11_director_using_constructor_runme {

  static {
    try {
	System.loadLibrary("cpp11_director_using_constructor");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[]) {
    // This is a copy of cpp11_using_constructor_runme.java for testing that the expected constructors can be called

    // Public base constructors
    new PublicDerived1(0, "hi").meth();
    new PublicDerived2().meth();
    new PublicDerived2(0, "hi").meth();
    new PublicDerived3().meth();
    new PublicDerived3(0, "hi").meth();
    new PublicDerived4().meth();
    new PublicDerived5().meth();

    // Protected base constructors
    // Cannot test most of these as the constructors are protected
    new ProtectedDerived5();

    // Mix of public and overloaded constructors
    new MixedDerived1a(0, "hi").meth();
    new MixedDerived1a().meth();
    new MixedDerived1b(0, "hi").meth();
    new MixedDerived1b().meth();

    new MixedDerived2a(0, "hi").meth();
    new MixedDerived2a().meth();
    new MixedDerived2b(0, "hi").meth();
    new MixedDerived2b().meth();

    new MixedDerived2c(0, "hi").meth();
    new MixedDerived2c().meth();
    new MixedDerived2c(0).meth();

    new MixedDerived2d(0, "hi").meth();
    new MixedDerived2d().meth();
    new MixedDerived2d(0).meth();

    new MixedDerived3a(0, "hi").meth();
    new MixedDerived3a().meth();
    new MixedDerived3b(0, "hi").meth();
    new MixedDerived3b().meth();

    new MixedDerived3c(0, "hi").meth();
    new MixedDerived3c().meth();
    new MixedDerived3c(0).meth();

    new MixedDerived3d(0, "hi").meth();
    new MixedDerived3d().meth();
    new MixedDerived3d(0).meth();

    new MixedDerived4a(0, "hi").meth();
    new MixedDerived4a().meth();
    new MixedDerived4b(0, "hi").meth();
    new MixedDerived4b().meth();

    new MixedDerived4c().meth();
    new MixedDerived4c(0).meth();

    new MixedDerived4d().meth();
    new MixedDerived4d(0).meth();

    new MixedDerived4e().meth();

    new MixedDerived4f().meth();

    // Mix of protected base constructors and overloading
    new ProotDerived1a().meth();

    new ProotDerived1b(0, "hi").meth();
    new ProotDerived1b().meth();

    new ProotDerived1c(0, "hi").meth();
    new ProotDerived1c().meth();

    new ProotDerived1d(0).meth();
    new ProotDerived1d().meth();

    new ProotDerived1e(0).meth();
    new ProotDerived1e().meth();

    new ProotDerived2a(0, "hi").meth();

    new ProotDerived2b(0, "hi").meth();

    new ProotDerived2c(0, "hi").meth();
    new ProotDerived2c().meth();

    new ProotDerived2d(0, "hi").meth();
    new ProotDerived2d().meth();

    new ProotDerived2e(0, "hi").meth();
    new ProotDerived2e().meth();

    new ProotDerived2f(0, "hi").meth();
    new ProotDerived2f().meth();
    new ProotDerived2f(0).meth();

    // Deeper inheritance chain
    DeepBase3 db3 = new DeepBase3(11);
    db3 = new DeepBase3(11, 22);
    db3 = new DeepBase3(11, 22, 33);
    DeepProtectedBase3 dbp3 = new DeepProtectedBase3(11, 22, 33);

    // Missing base
    new HiddenDerived1();

    // Templates and public base constructors (derive from non-template)
    new TemplatePublicDerived1Int(0, "hi").meth();
    new TemplatePublicDerived2Int().meth();
    new TemplatePublicDerived2Int(0, "hi").meth();
    new TemplatePublicDerived3Int().meth();
    new TemplatePublicDerived3Int(0, "hi").meth();
    new TemplatePublicDerived4Int().meth();
    new TemplatePublicDerived5Int().meth();

    // Templates and public base constructors (derive from template)
    new TemplPublicDerived1Int(0, "hi").meth();
    new TemplPublicDerived2Int().meth();
    new TemplPublicDerived2Int(0, "hi").meth();
    new TemplPublicDerived3Int().meth();
    new TemplPublicDerived3Int(0, "hi").meth();
    new TemplPublicDerived4Int().meth();
    new TemplPublicDerived5Int().meth();
    new TemplPublicDerived6Int(0, "hi").meth();
    new TemplPublicDerived6Int().meth();

    // Templated constructors (public)
    TemplateConstructor1Base tcb = new TemplateConstructor1Base(0, "hi");
    tcb = new TemplateConstructor1Base("hi", "hi");
    tcb = new TemplateConstructor1Base(11.1, "hi");
    tcb.normal_method();
    tcb.template_method(0, "hi");
    tcb.template_method("hey", "ho");

    TemplateConstructor1Derived tcd1 = new TemplateConstructor1Derived(0, "hi");
    tcd1 = new TemplateConstructor1Derived("hi", "hi");
    tcd1 = new TemplateConstructor1Derived(11.1, "hi");
    // Not the best test as these are also in the base class, hence use also introspection below
    tcd1.normal_method();
    tcd1.template_method(0, "hi");
    tcd1.template_method("hey", "ho");

    // Templated methods
    // Introspection to make sure these are actually generated in the derived class
    try {
      TemplateConstructor1Derived.class.getDeclaredMethod("normal_method", (java.lang.Class[])null);
      TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{String.class, String.class});
      TemplateConstructor1Derived.class.getDeclaredMethod("template_method", new java.lang.Class[]{int.class, String.class});
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(e);
    }

    // Templated constructors (protected)
    TemplateConstructor2Derived tcd2 = new TemplateConstructor2Derived();
    tcd2.normal_method();
    tcd2.template_method(0, "hi");
    tcd2.template_method("hey", "ho");
  }

  //
  // Additional tests compared to cpp11_using_constructor test
  //
  // Protected constructors, check both protected and public constructors can be called from a derived class
  class cpp11_director_using_constructor_MyProtectedBase1 extends ProtectedBase1 {
    public cpp11_director_using_constructor_MyProtectedBase1(int i, String s) {
      super(i, s);
    }
  }
  class cpp11_director_using_constructor_MyProtectedDerived1 extends ProtectedDerived1 {
    public cpp11_director_using_constructor_MyProtectedDerived1(int i, String s) {
      super(i, s);
    }
  }
  class cpp11_director_using_constructor_MyProtectedBase2 extends ProtectedBase2 {
    public cpp11_director_using_constructor_MyProtectedBase2(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProtectedBase2() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedDerived2 extends ProtectedDerived2 {
    public cpp11_director_using_constructor_MyProtectedDerived2(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProtectedDerived2() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedBase3 extends ProtectedBase3 {
    public cpp11_director_using_constructor_MyProtectedBase3(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProtectedBase3() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedDerived3 extends ProtectedDerived3 {
    public cpp11_director_using_constructor_MyProtectedDerived3(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProtectedDerived3() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedBase4 extends ProtectedBase4 {
    public cpp11_director_using_constructor_MyProtectedBase4() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedDerived4 extends ProtectedDerived4 {
    public cpp11_director_using_constructor_MyProtectedDerived4() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedBase5 extends ProtectedBase5 {
    public cpp11_director_using_constructor_MyProtectedBase5() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProtectedDerived5 extends ProtectedDerived5 {
    public cpp11_director_using_constructor_MyProtectedDerived5() {
      super();
    }
  }

  // Protected constructors, just check the protected constructors can be called from a derived class
  class cpp11_director_using_constructor_MyProotBase1 extends ProotBase1 {
    public cpp11_director_using_constructor_MyProotBase1(int i, String s) {
      super(i, s);
    }
  }
  class cpp11_director_using_constructor_MyProotDerived1a extends ProotDerived1a {
    public cpp11_director_using_constructor_MyProotDerived1a(int i, String s) {
      super(i, s);
    }
  }
  class cpp11_director_using_constructor_MyProotDerived1d extends ProotDerived1d {
    public cpp11_director_using_constructor_MyProotDerived1d(int i, String s) {
      super(i, s);
    }
  }
  class cpp11_director_using_constructor_MyProotDerived1e extends ProotDerived1e {
    public cpp11_director_using_constructor_MyProotDerived1e(int i, String s) {
      super(i, s);
    }
  }

  // Protected constructors, check both protected and public constructors can be called from a derived class
  class cpp11_director_using_constructor_MyProotBase2 extends ProotBase2 {
    public cpp11_director_using_constructor_MyProotBase2(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotBase2() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2a extends ProotDerived2a {
    public cpp11_director_using_constructor_MyProotDerived2a(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2a() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2b extends ProotDerived2b {
    public cpp11_director_using_constructor_MyProotDerived2b(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2b() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2c extends ProotDerived2c {
    public cpp11_director_using_constructor_MyProotDerived2c(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2c() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2d extends ProotDerived2d {
    public cpp11_director_using_constructor_MyProotDerived2d(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2d() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2e extends ProotDerived2e {
    public cpp11_director_using_constructor_MyProotDerived2e(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2e() {
      super();
    }
  }
  class cpp11_director_using_constructor_MyProotDerived2f extends ProotDerived2f {
    public cpp11_director_using_constructor_MyProotDerived2f(int i, String s) {
      super(i, s);
    }
    public cpp11_director_using_constructor_MyProotDerived2f() {
      super();
    }
    public cpp11_director_using_constructor_MyProotDerived2f(int i) {
      super(i);
    }
  }


}