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