PageRenderTime 1025ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/java/java_director_runme.java

#
Java | 75 lines | 53 code | 16 blank | 6 comment | 8 complexity | 998b364a97c25b09880fb159adb63cd8 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // Mainly tests that directors are finalized correctly
  2. import java_director.*;
  3. public class java_director_runme {
  4. static {
  5. try {
  6. System.loadLibrary("java_director");
  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. public static void main(String argv[]) {
  13. QuuxContainer qc = createContainer();
  14. int instances = Quux.instances();
  15. if (instances != 4)
  16. throw new RuntimeException("Quux instances should be 4, actually " + instances);
  17. for (int i = 0; i < qc.size(); ++i) {
  18. Quux q = qc.get(i);
  19. if (!q.director_method().equals(qc.invoke(i))) {
  20. throw new RuntimeException ( "q.director_method()/qv.invoke(" + i + ")");
  21. }
  22. }
  23. qc = null;
  24. /* Watch qc get reaped, which causes the C++ object to delete
  25. objects from the internal vector */
  26. System.gc();
  27. System.runFinalization();
  28. /* Watch the Quux objects formerly in the QuuxContainer object
  29. get reaped */
  30. System.gc();
  31. System.runFinalization();
  32. instances = Quux.instances();
  33. if (instances != 0)
  34. throw new RuntimeException("Quux instances should be 0, actually " + instances);
  35. /* Test Quux1's director disconnect method rename */
  36. Quux1 quux1 = new Quux1("quux1");
  37. if (quux1.disconnectMethodCalled)
  38. throw new RuntimeException("Oops");
  39. quux1.delete();
  40. if (!quux1.disconnectMethodCalled)
  41. throw new RuntimeException("disconnect method not called");
  42. }
  43. public static QuuxContainer createContainer() {
  44. QuuxContainer qc = new QuuxContainer();
  45. qc.push(new Quux("element 1"));
  46. qc.push(new java_director_MyQuux("element 2"));
  47. qc.push(new java_director_MyQuux("element 3"));
  48. qc.push(new Quux("element 4"));
  49. return qc;
  50. }
  51. }
  52. class java_director_MyQuux extends Quux {
  53. public java_director_MyQuux(String arg) {
  54. super(arg);
  55. }
  56. public String director_method() {
  57. return "java_director_MyQuux:" + member();
  58. }
  59. }