PageRenderTime 37ms CodeModel.GetById 30ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 125 lines | 103 code | 15 blank | 7 comment | 19 complexity | c94872a56ca2fe6d164a727a629bc15a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1
  2// Check a few of the INPUT, OUTPUT and INOUT typemaps.
  3
  4import li_typemaps.*;
  5import java.math.*;
  6
  7public class li_typemaps_runme {
  8
  9  static {
 10    try {
 11	System.loadLibrary("li_typemaps");
 12    } catch (UnsatisfiedLinkError e) {
 13      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);
 14      System.exit(1);
 15    }
 16  }
 17
 18  public static void main(String argv[]) {
 19
 20    // Check double INPUT typemaps
 21    if (li_typemaps.in_double(22.22) != 22.22) exit_test("in_double");
 22    if (li_typemaps.inr_double(22.22) != 22.22) exit_test("inr_double");
 23
 24    // Check double OUTPUT typemaps
 25    {
 26        double[] var = {44.44};
 27        li_typemaps.out_double(22.22, var);
 28        if (var[0] != 22.22) exit_test("out_double");
 29    }
 30    {
 31        double[] var = {44.44};
 32        li_typemaps.outr_double(22.22, var);
 33        if (var[0] != 22.22) exit_test("outr_double");
 34    }
 35    try {
 36        double[] var = null;
 37        li_typemaps.out_double(22.22, var);
 38        exit_test("null out_double");
 39    } catch (NullPointerException e) {
 40    }
 41
 42    // Check double INOUT typemaps
 43    {
 44        double[] var = {44.44};
 45        li_typemaps.inout_double(var);
 46        if (var[0] != 44.44) exit_test("inout_double");
 47    }
 48    {
 49        double[] var = {44.44};
 50        li_typemaps.inoutr_double(var);
 51        if (var[0] != 44.44) exit_test("inoutr_double");
 52    }
 53    try {
 54        double[] var = null;
 55        li_typemaps.inout_double(var);
 56        exit_test("null inout_double");
 57    } catch (NullPointerException e) {
 58    }
 59
 60    // Check unsigned long long INPUT typemaps
 61    BigInteger forty = new BigInteger("40");
 62    BigInteger twenty = new BigInteger("20");
 63    if (!li_typemaps.in_ulonglong(twenty).equals(twenty)) exit_test("in_ulonglong");
 64    if (!li_typemaps.inr_ulonglong(twenty).equals(twenty)) exit_test("inr_ulonglong");
 65
 66    try {
 67        li_typemaps.in_ulonglong(null);
 68        exit_test("null in_ulonglong");
 69    } catch (NullPointerException e) {
 70    }
 71
 72    // Check unsigned long long OUTPUT typemaps
 73    {
 74        BigInteger[] var = {new BigInteger("40")};
 75        li_typemaps.out_ulonglong(twenty, var);
 76        if (!var[0].equals(twenty)) exit_test("out_ulonglong");
 77    }
 78    {
 79        BigInteger[] var = {new BigInteger("40")};
 80        li_typemaps.outr_ulonglong(twenty, var);
 81        if (!var[0].equals(twenty)) exit_test("outr_ulonglong");
 82    }
 83    try {
 84        BigInteger[] var = null;
 85        li_typemaps.out_ulonglong(twenty, var);
 86        exit_test("null out_ulonglong");
 87    } catch (NullPointerException e) {
 88    }
 89    {
 90        BigInteger[] var = { null };
 91        li_typemaps.out_ulonglong(twenty, var);
 92        if (!var[0].equals(twenty)) exit_test("null element out_ulonglong");
 93    }
 94
 95    // Check unsigned long long INOUT typemaps
 96    {
 97        BigInteger[] var = {new BigInteger("40")};
 98        li_typemaps.inout_ulonglong(var);
 99        if (!var[0].equals(forty)) exit_test("inout_ulonglong");
100    }
101    {
102        BigInteger[] var = {new BigInteger("40")};
103        li_typemaps.inoutr_ulonglong(var);
104        if (!var[0].equals(forty)) exit_test("inoutr_ulonglong");
105    }
106    try {
107        BigInteger[] var = null;
108        li_typemaps.inout_ulonglong(var);
109        exit_test("null inout_ulonglong");
110    } catch (NullPointerException e) {
111    }
112    try {
113        BigInteger[] var = { null };
114        li_typemaps.inout_ulonglong(var);
115        exit_test("null element inout_ulonglong");
116    } catch (NullPointerException e) {
117    }
118
119  }
120
121  private static void exit_test(String funcName) {
122      throw new RuntimeException("Test FAILED in function " + funcName);
123  }
124}
125