PageRenderTime 44ms CodeModel.GetById 13ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/java/director_classic_runme.java

#
Java | 318 lines | 270 code | 34 blank | 14 comment | 7 complexity | ba007906c6422f5106af19b2d2d57366 MD5 | raw file
  1import director_classic.*;
  2
  3public class director_classic_runme {
  4  static {
  5    try {
  6        System.loadLibrary("director_classic");
  7    } catch (UnsatisfiedLinkError e) {
  8      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);
  9      System.exit(1);
 10    }
 11  }
 12
 13  public static void main(String argv[]) 
 14  {
 15    { 
 16      Person person = new Person();
 17      check(person, "Person");
 18      person.delete();
 19    }
 20    { 
 21      Person person = new Child();
 22      check(person, "Child");
 23      person.delete();
 24    }
 25    { 
 26      Person person = new GrandChild();
 27      check(person, "GrandChild"); 
 28      person.delete();
 29    }
 30    { 
 31      Person person = new TargetLangPerson();
 32      check(person, "TargetLangPerson"); 
 33      person.delete();
 34    }
 35    { 
 36      Person person = new TargetLangChild();
 37      check(person, "TargetLangChild"); 
 38      person.delete();
 39    }
 40    { 
 41      Person person = new TargetLangGrandChild();
 42      check(person, "TargetLangGrandChild"); 
 43      person.delete();
 44    }
 45
 46    // Semis - don't override id() in target language
 47    { 
 48      Person person = new TargetLangSemiPerson();
 49      check(person, "Person"); 
 50      person.delete();
 51    }
 52    { 
 53      Person person = new TargetLangSemiChild();
 54      check(person, "Child"); 
 55      person.delete();
 56    }
 57    { 
 58      Person person = new TargetLangSemiGrandChild();
 59      check(person, "GrandChild"); 
 60      person.delete();
 61    }
 62
 63    // Orphans - don't override id() in C++
 64    { 
 65      Person person = new OrphanPerson();
 66      check(person, "Person"); 
 67      person.delete();
 68    }
 69    { 
 70      Person person = new OrphanChild();
 71      check(person, "Child"); 
 72      person.delete();
 73    }
 74    { 
 75      Person person = new TargetLangOrphanPerson();
 76      check(person, "TargetLangOrphanPerson"); 
 77      person.delete();
 78    }
 79    { 
 80      Person person = new TargetLangOrphanChild();
 81      check(person, "TargetLangOrphanChild"); 
 82      person.delete();
 83    }
 84
 85    // Duals - id() makes an upcall to the base id()
 86    { 
 87      Person person = new TargetLangDualPerson();
 88      check(person, "TargetLangDualPerson + Person"); 
 89      person.delete();
 90    }
 91    { 
 92      Person person = new TargetLangDualChild();
 93      check(person, "TargetLangDualChild + Child"); 
 94      person.delete();
 95    }
 96    { 
 97      Person person = new TargetLangDualGrandChild();
 98      check(person, "TargetLangDualGrandChild + GrandChild"); 
 99      person.delete();
100    }
101
102    // Mix Orphans and Duals
103    { 
104      Person person = new TargetLangDualOrphanPerson();
105      check(person, "TargetLangDualOrphanPerson + Person"); 
106      person.delete();
107    }
108    { 
109      Person person = new TargetLangDualOrphanChild();
110      check(person, "TargetLangDualOrphanChild + Child"); 
111      person.delete();
112    }
113  }
114
115  static void check(Person person, String expected) {
116    String ret;
117    // Normal target language polymorphic call
118    ret = person.id();
119    if (debug) 
120      System.out.println(ret);
121    if (!ret.equals(expected))
122      throw new RuntimeException("Failed. Received: " + ret + " Expected: " + expected);
123
124    // Polymorphic call from C++
125    Caller caller = new Caller();
126    caller.setCallback(person);
127    ret = caller.call();
128    if (debug) 
129      System.out.println(ret);
130    if (!ret.equals(expected))
131      throw new RuntimeException("Failed. Received: " + ret + " Expected: " + expected);
132
133    // Polymorphic call of object created in target language and passed to C++ and back again
134    Person baseclass = caller.baseClass();
135    ret = baseclass.id();
136    if (debug) 
137      System.out.println(ret);
138    if (!ret.equals(expected))
139      throw new RuntimeException("Failed. Received: " + ret + " Expected: " + expected);
140
141    caller.resetCallback();
142    if (debug) 
143      System.out.println("----------------------------------------");
144  }
145  static boolean debug = false;
146}
147
148class TargetLangPerson extends Person
149{
150  public TargetLangPerson()
151  {
152    super();
153  }
154
155  public String id()
156  {
157    String identifier = "TargetLangPerson";
158    return identifier;
159  }
160}
161
162class TargetLangChild extends Child
163{
164  public TargetLangChild()
165  {
166    super();
167  }
168
169  public String id()
170  {
171    String identifier = "TargetLangChild";
172    return identifier;
173  }
174}
175
176class TargetLangGrandChild extends GrandChild
177{
178  public TargetLangGrandChild()
179  {
180    super();
181  }
182
183  public String id()
184  {
185    String identifier = "TargetLangGrandChild";
186    return identifier;
187  }
188}
189
190// Semis - don't override id() in target language
191class TargetLangSemiPerson extends Person
192{
193  public TargetLangSemiPerson()
194  {
195    super();
196  }
197  // No id() override
198}
199
200class TargetLangSemiChild extends Child
201{
202  public TargetLangSemiChild()
203  {
204    super();
205  }
206  // No id() override
207}
208
209class TargetLangSemiGrandChild extends GrandChild
210{
211  public TargetLangSemiGrandChild()
212  {
213    super();
214  }
215  // No id() override
216}
217
218// Orphans - don't override id() in C++
219class TargetLangOrphanPerson extends OrphanPerson
220{
221  public TargetLangOrphanPerson()
222  {
223    super();
224  }
225
226  public String id()
227  {
228    String identifier = "TargetLangOrphanPerson";
229    return identifier;
230  }
231}
232
233class TargetLangOrphanChild extends OrphanChild
234{
235  public TargetLangOrphanChild()
236  {
237    super();
238  }
239
240  public String id()
241  {
242    String identifier = "TargetLangOrphanChild";
243    return identifier;
244  }
245}
246
247// Duals - id() makes an upcall to the base id()
248class TargetLangDualPerson extends Person
249{
250  public TargetLangDualPerson()
251  {
252    super();
253  }
254
255  public String id()
256  {
257    String identifier = "TargetLangDualPerson + " + super.id();
258    return identifier;
259  }
260}
261
262class TargetLangDualChild extends Child
263{
264  public TargetLangDualChild()
265  {
266    super();
267  }
268
269  public String id()
270  {
271    String identifier = "TargetLangDualChild + " + super.id();
272    return identifier;
273  }
274}
275
276class TargetLangDualGrandChild extends GrandChild
277{
278  public TargetLangDualGrandChild()
279  {
280    super();
281  }
282
283  public String id()
284  {
285    String identifier = "TargetLangDualGrandChild + " + super.id();
286    return identifier;
287  }
288}
289
290// Mix Orphans and Duals
291class TargetLangDualOrphanPerson extends OrphanPerson
292{
293  public TargetLangDualOrphanPerson()
294  {
295    super();
296  }
297
298  public String id()
299  {
300    String identifier = "TargetLangDualOrphanPerson + " + super.id();
301    return identifier;
302  }
303}
304
305class TargetLangDualOrphanChild extends OrphanChild
306{
307  public TargetLangDualOrphanChild()
308  {
309    super();
310  }
311
312  public String id()
313  {
314    String identifier = "TargetLangDualOrphanChild + " + super.id();
315    return identifier;
316  }
317}
318