PageRenderTime 133ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
Java | 226 lines | 198 code | 23 blank | 5 comment | 156 complexity | 94b9ae156e55252aa0f5b3156e7e91ad MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. import extend_default.Override;
  2. import extend_default.*;
  3. public class extend_default_runme {
  4. static {
  5. try {
  6. System.loadLibrary("extend_default");
  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. {
  14. // %extend before the class definition
  15. {
  16. Before ex = new Before();
  17. if (ex.getI() != -1.0 && ex.getD() != -1.0)
  18. throw new RuntimeException("Before constructor 1 failed");
  19. ex = new Before(10);
  20. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  21. throw new RuntimeException("Before constructor 2 failed");
  22. ex = new Before(20, 30.0);
  23. if (ex.getI() != 20 && ex.getD() != 30.0)
  24. throw new RuntimeException("Before constructor 3 failed");
  25. }
  26. {
  27. Before ex = new Before();
  28. if (ex.AddedMethod() != -2.0)
  29. throw new RuntimeException("Before AddedMethod 1 failed");
  30. if (ex.AddedMethod(-2) != -3.0)
  31. throw new RuntimeException("Before AddedMethod 2 failed");
  32. if (ex.AddedMethod(-10, -10.0) != -20)
  33. throw new RuntimeException("Before AddedMethod 3 failed");
  34. }
  35. {
  36. if (Before.AddedStaticMethod() != -2.0)
  37. throw new RuntimeException("Before AddedStaticMethod 1 failed");
  38. if (Before.AddedStaticMethod(-2) != -3.0)
  39. throw new RuntimeException("Before AddedStaticMethod 2 failed");
  40. if (Before.AddedStaticMethod(-10, -10.0) != -20)
  41. throw new RuntimeException("Before AddedStaticMethod 3 failed");
  42. }
  43. // %extend after the class definition
  44. {
  45. After ex = new After();
  46. if (ex.getI() != -1.0 && ex.getD() != -1.0)
  47. throw new RuntimeException("After constructor 1 failed");
  48. ex = new After(10);
  49. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  50. throw new RuntimeException("After constructor 2 failed");
  51. ex = new After(20, 30.0);
  52. if (ex.getI() != 20 && ex.getD() != 30.0)
  53. throw new RuntimeException("After constructor 3 failed");
  54. }
  55. {
  56. After ex = new After();
  57. if (ex.AddedMethod() != -2.0)
  58. throw new RuntimeException("After AddedMethod 1 failed");
  59. if (ex.AddedMethod(-2) != -3.0)
  60. throw new RuntimeException("After AddedMethod 2 failed");
  61. if (ex.AddedMethod(-10, -10.0) != -20)
  62. throw new RuntimeException("After AddedMethod 3 failed");
  63. }
  64. {
  65. if (After.AddedStaticMethod() != -2.0)
  66. throw new RuntimeException("After AddedStaticMethod 1 failed");
  67. if (After.AddedStaticMethod(-2) != -3.0)
  68. throw new RuntimeException("After AddedStaticMethod 2 failed");
  69. if (After.AddedStaticMethod(-10, -10.0) != -20)
  70. throw new RuntimeException("After AddedStaticMethod 3 failed");
  71. }
  72. // %extend before the class definition - with overloading and default args
  73. {
  74. OverBefore ex = new OverBefore();
  75. if (ex.getI() != -1.0 && ex.getD() != -1.0)
  76. throw new RuntimeException("OverBefore constructor 1 failed");
  77. ex = new OverBefore(10);
  78. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  79. throw new RuntimeException("OverBefore constructor 2 failed");
  80. ex = new OverBefore(20, 30.0);
  81. if (ex.getI() != 20 && ex.getD() != 30.0)
  82. throw new RuntimeException("OverBefore constructor 3 failed");
  83. }
  84. {
  85. OverBefore ex = new OverBefore();
  86. if (ex.AddedMethod() != -2.0)
  87. throw new RuntimeException("OverBefore AddedMethod 1 failed");
  88. if (ex.AddedMethod(-2) != -3.0)
  89. throw new RuntimeException("OverBefore AddedMethod 2 failed");
  90. if (ex.AddedMethod(-10, -10.0) != -20)
  91. throw new RuntimeException("OverBefore AddedMethod 3 failed");
  92. }
  93. {
  94. if (OverBefore.AddedStaticMethod() != -2.0)
  95. throw new RuntimeException("OverBefore AddedStaticMethod 1 failed");
  96. if (OverBefore.AddedStaticMethod(-2) != -3.0)
  97. throw new RuntimeException("OverBefore AddedStaticMethod 2 failed");
  98. if (OverBefore.AddedStaticMethod(-10, -10.0) != -20)
  99. throw new RuntimeException("OverBefore AddedStaticMethod 3 failed");
  100. }
  101. {
  102. OverBefore ex = new OverBefore("hello");
  103. if (ex.getI() != -2.0 && ex.getD() != -2.0)
  104. throw new RuntimeException("OverBefore overload constructor 1 failed");
  105. ex = new OverBefore("hello", 10);
  106. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  107. throw new RuntimeException("OverBefore overload constructor 2 failed");
  108. ex = new OverBefore("hello", 20, 30.0);
  109. if (ex.getI() != 20 && ex.getD() != 30.0)
  110. throw new RuntimeException("OverBefore overload constructor 3 failed");
  111. }
  112. {
  113. OverBefore ex = new OverBefore("hello");
  114. if (ex.AddedMethod("hello") != -2.0)
  115. throw new RuntimeException("OverBefore overload AddedMethod 1 failed");
  116. if (ex.AddedMethod("hello", -2) != -3.0)
  117. throw new RuntimeException("OverBefore overload AddedMethod 2 failed");
  118. if (ex.AddedMethod("hello", -10, -10.0) != -20)
  119. throw new RuntimeException("OverBefore overload AddedMethod 3 failed");
  120. }
  121. {
  122. if (OverBefore.AddedStaticMethod("hello") != -2.0)
  123. throw new RuntimeException("OverBefore overload AddedStaticMethod 1 failed");
  124. if (OverBefore.AddedStaticMethod("hello", -2) != -3.0)
  125. throw new RuntimeException("OverBefore overload AddedStaticMethod 2 failed");
  126. if (OverBefore.AddedStaticMethod("hello", -10, -10.0) != -20)
  127. throw new RuntimeException("OverBefore overload AddedStaticMethod 3 failed");
  128. }
  129. // %extend after the class definition - with overloading and default args
  130. {
  131. OverAfter ex = new OverAfter();
  132. if (ex.getI() != -1.0 && ex.getD() != -1.0)
  133. throw new RuntimeException("OverAfter constructor 1 failed");
  134. ex = new OverAfter(10);
  135. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  136. throw new RuntimeException("OverAfter constructor 2 failed");
  137. ex = new OverAfter(20, 30.0);
  138. if (ex.getI() != 20 && ex.getD() != 30.0)
  139. throw new RuntimeException("OverAfter constructor 3 failed");
  140. }
  141. {
  142. OverAfter ex = new OverAfter();
  143. if (ex.AddedMethod() != -2.0)
  144. throw new RuntimeException("OverAfter AddedMethod 1 failed");
  145. if (ex.AddedMethod(-2) != -3.0)
  146. throw new RuntimeException("OverAfter AddedMethod 2 failed");
  147. if (ex.AddedMethod(-10, -10.0) != -20)
  148. throw new RuntimeException("OverAfter AddedMethod 3 failed");
  149. }
  150. {
  151. if (OverAfter.AddedStaticMethod() != -2.0)
  152. throw new RuntimeException("OverAfter AddedStaticMethod 1 failed");
  153. if (OverAfter.AddedStaticMethod(-2) != -3.0)
  154. throw new RuntimeException("OverAfter AddedStaticMethod 2 failed");
  155. if (OverAfter.AddedStaticMethod(-10, -10.0) != -20)
  156. throw new RuntimeException("OverAfter AddedStaticMethod 3 failed");
  157. }
  158. {
  159. OverAfter ex = new OverAfter("hello");
  160. if (ex.getI() != -2.0 && ex.getD() != -2.0)
  161. throw new RuntimeException("OverAfter overload constructor 1 failed");
  162. ex = new OverAfter("hello", 10);
  163. if (ex.getI() != 10.0 && ex.getD() != -1.0)
  164. throw new RuntimeException("OverAfter overload constructor 2 failed");
  165. ex = new OverAfter("hello", 20, 30.0);
  166. if (ex.getI() != 20 && ex.getD() != 30.0)
  167. throw new RuntimeException("OverAfter overload constructor 3 failed");
  168. }
  169. {
  170. OverAfter ex = new OverAfter("hello");
  171. if (ex.AddedMethod("hello") != -2.0)
  172. throw new RuntimeException("OverAfter overload AddedMethod 1 failed");
  173. if (ex.AddedMethod("hello", -2) != -3.0)
  174. throw new RuntimeException("OverAfter overload AddedMethod 2 failed");
  175. if (ex.AddedMethod("hello", -10, -10.0) != -20)
  176. throw new RuntimeException("OverAfter overload AddedMethod 3 failed");
  177. }
  178. {
  179. if (OverAfter.AddedStaticMethod("hello") != -2.0)
  180. throw new RuntimeException("OverAfter overload AddedStaticMethod 1 failed");
  181. if (OverAfter.AddedStaticMethod("hello", -2) != -3.0)
  182. throw new RuntimeException("OverAfter overload AddedStaticMethod 2 failed");
  183. if (OverAfter.AddedStaticMethod("hello", -10, -10.0) != -20)
  184. throw new RuntimeException("OverAfter overload AddedStaticMethod 3 failed");
  185. }
  186. // Override
  187. {
  188. Override o = new Override();
  189. if (o.over() != -1)
  190. throw new RuntimeException("override test 1 failed");
  191. if (o.over(10) != 10*10)
  192. throw new RuntimeException("override test 2 failed");
  193. if (o.ride() != -1)
  194. throw new RuntimeException("override test 3 failed");
  195. if (o.ride(10) != 10)
  196. throw new RuntimeException("override test 4 failed");
  197. if (o.overload() != -10)
  198. throw new RuntimeException("override test 5 failed");
  199. if (o.overload(10) != 10*10)
  200. throw new RuntimeException("override test 6 failed");
  201. }
  202. }
  203. }