PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 88 lines | 76 code | 7 blank | 5 comment | 10 complexity | 5a7d217e3fb43bbedce48d3ae0f2c184 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. import li_carrays.*;
  2. public class li_carrays_runme {
  3. static {
  4. try {
  5. System.loadLibrary("li_carrays");
  6. } catch (UnsatisfiedLinkError e) {
  7. 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);
  8. System.exit(1);
  9. }
  10. }
  11. public static void main(String argv[]) throws Throwable
  12. {
  13. // array_class
  14. {
  15. int length = 5;
  16. XYArray xyArray = new XYArray(length);
  17. for (int i=0; i<length; i++) {
  18. XY xy = xyArray.getitem(i);
  19. xy.setX(i*10);
  20. xy.setY(i*100);
  21. xyArray.setitem(i, xy);
  22. }
  23. for (int i=0; i<length; i++) {
  24. Assert(xyArray.getitem(i).getX(), i*10);
  25. Assert(xyArray.getitem(i).getY(), i*100);
  26. }
  27. }
  28. {
  29. // global array variable
  30. int length = 5;
  31. XY xyArrayPointer = li_carrays.getGlobalXYArray();
  32. XYArray xyArray = XYArray.frompointer(xyArrayPointer);
  33. for (int i=0; i<length; i++) {
  34. XY xy = xyArray.getitem(i);
  35. xy.setX(i*10);
  36. xy.setY(i*100);
  37. xyArray.setitem(i, xy);
  38. }
  39. for (int i=0; i<length; i++) {
  40. Assert(xyArray.getitem(i).getX(), i*10);
  41. Assert(xyArray.getitem(i).getY(), i*100);
  42. }
  43. }
  44. // array_functions
  45. {
  46. int length = 5;
  47. AB abArray = li_carrays.new_ABArray(length);
  48. for (int i=0; i<length; i++) {
  49. AB ab = li_carrays.ABArray_getitem(abArray, i);
  50. ab.setA(i*10);
  51. ab.setB(i*100);
  52. li_carrays.ABArray_setitem(abArray, i, ab);
  53. }
  54. for (int i=0; i<length; i++) {
  55. Assert(li_carrays.ABArray_getitem(abArray, i).getA(), i*10);
  56. Assert(li_carrays.ABArray_getitem(abArray, i).getB(), i*100);
  57. }
  58. li_carrays.delete_ABArray(abArray);
  59. }
  60. {
  61. // global array variable
  62. int length = 3;
  63. AB abArray = li_carrays.getGlobalABArray();
  64. for (int i=0; i<length; i++) {
  65. AB ab = li_carrays.ABArray_getitem(abArray, i);
  66. ab.setA(i*10);
  67. ab.setB(i*100);
  68. li_carrays.ABArray_setitem(abArray, i, ab);
  69. }
  70. for (int i=0; i<length; i++) {
  71. Assert(li_carrays.ABArray_getitem(abArray, i).getA(), i*10);
  72. Assert(li_carrays.ABArray_getitem(abArray, i).getB(), i*100);
  73. }
  74. }
  75. }
  76. private static void Assert(int val1, int val2) {
  77. // System.out.println("val1=" + val1 + " val2=" + val2);
  78. if (val1 != val2)
  79. throw new RuntimeException("Mismatch. val1=" + val1 + " val2=" + val2);
  80. }
  81. }