PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
Java | 92 lines | 65 code | 20 blank | 7 comment | 8 complexity | 762ea3de993f503a7701df9c296ee432 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. // Give the finalizers a chance to run
  29. try {
  30. Thread.sleep(50);
  31. } catch (InterruptedException e) {
  32. }
  33. /* Watch the Quux objects formerly in the QuuxContainer object
  34. get reaped */
  35. System.gc();
  36. System.runFinalization();
  37. instances = Quux.instances();
  38. if (instances != 0)
  39. throw new RuntimeException("Quux instances should be 0, actually " + instances);
  40. /* Test Quux1's director disconnect method rename */
  41. Quux1 quux1 = new Quux1("quux1");
  42. if (quux1.disconnectMethodCalled)
  43. throw new RuntimeException("Oops");
  44. quux1.delete();
  45. if (!quux1.disconnectMethodCalled)
  46. throw new RuntimeException("disconnect method not called");
  47. }
  48. public static QuuxContainer createContainer() {
  49. QuuxContainer qc = new QuuxContainer();
  50. qc.push(new Quux("element 1"));
  51. qc.push(new java_director_MyQuux("element 2"));
  52. qc.push(new java_director_MyQuux("element 3"));
  53. qc.push(new Quux("element 4"));
  54. return qc;
  55. }
  56. }
  57. class java_director_MyQuux extends Quux {
  58. public java_director_MyQuux(String arg) {
  59. super(arg);
  60. }
  61. public String director_method() {
  62. return "java_director_MyQuux:" + member();
  63. }
  64. }
  65. class java_director_JavaExceptionTest extends JavaExceptionTest {
  66. public java_director_JavaExceptionTest() {
  67. super();
  68. }
  69. public void etest() throws Exception {
  70. super.etest();
  71. }
  72. }