File: java_director_runme.java

package info (click to toggle)
swig2.0 2.0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 31,452 kB
  • ctags: 15,278
  • sloc: cpp: 50,112; ansic: 25,628; java: 8,829; python: 6,834; cs: 5,845; yacc: 5,199; makefile: 5,143; sh: 5,068; ruby: 3,683; perl: 2,389; lisp: 1,807; php: 1,701; tcl: 968; ml: 619; xml: 115
file content (92 lines) | stat: -rw-r--r-- 2,435 bytes parent folder | download | duplicates (2)
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
// Mainly tests that directors are finalized correctly

import java_director.*;

public class java_director_runme {

  static {
    try {
      System.loadLibrary("java_director");
    } 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[]) {
    QuuxContainer qc = createContainer();

    int instances = Quux.instances();
    if (instances != 4)
      throw new RuntimeException("Quux instances should be 4, actually " + instances);

    for (int i = 0; i < qc.size(); ++i) {
      Quux q = qc.get(i);

      if (!q.director_method().equals(qc.invoke(i))) {
        throw new RuntimeException ( "q.director_method()/qv.invoke(" + i + ")");
      }
    }

    qc = null;
    /* Watch qc get reaped, which causes the C++ object to delete
       objects from the internal vector */
    System.gc();
    System.runFinalization();

    // Give the finalizers a chance to run
    try {
      Thread.sleep(50);
    } catch (InterruptedException e) {
    }

    /* Watch the Quux objects formerly in the QuuxContainer object
       get reaped */
    System.gc();
    System.runFinalization();

    instances = Quux.instances();
    if (instances != 0)
      throw new RuntimeException("Quux instances should be 0, actually " + instances);

    /* Test Quux1's director disconnect method rename */
    Quux1 quux1 = new Quux1("quux1");
    if (quux1.disconnectMethodCalled)
      throw new RuntimeException("Oops");
    quux1.delete();
    if (!quux1.disconnectMethodCalled)
      throw new RuntimeException("disconnect method not called");
  }

  public static QuuxContainer createContainer() {
    QuuxContainer qc = new QuuxContainer();

    qc.push(new Quux("element 1"));
    qc.push(new java_director_MyQuux("element 2"));
    qc.push(new java_director_MyQuux("element 3"));
    qc.push(new Quux("element 4"));

    return qc;
  }
}

class java_director_MyQuux extends Quux {
  public java_director_MyQuux(String arg) {
    super(arg);
  }

  public String director_method() {
    return "java_director_MyQuux:" + member();
  }
}

class java_director_JavaExceptionTest extends JavaExceptionTest {
  public java_director_JavaExceptionTest() {
    super();
  }

  public void etest() throws Exception {
    super.etest();
  }
}