File: java_lib_various_runme.java

package info (click to toggle)
swig 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 34,980 kB
  • ctags: 16,742
  • sloc: cpp: 54,566; ansic: 26,563; java: 9,485; python: 7,204; cs: 6,106; makefile: 5,709; yacc: 5,571; sh: 4,988; ruby: 3,742; perl: 3,224; lisp: 1,825; php: 1,670; tcl: 968; ml: 747; xml: 115
file content (88 lines) | stat: -rw-r--r-- 3,134 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

// Test case to check typemaps in various.i

import java_lib_various.*;

public class java_lib_various_runme {

  static {
    try {
	System.loadLibrary("java_lib_various");
    } catch (UnsatisfiedLinkError e) {
      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);
      System.exit(1);
    }
  }

  public static void main(String argv[]) {

    // STRING_ARRAY typemap parameter
    String animals[] = {"Cat","Dog","Cow","Goat"};
    if (java_lib_various.check_animals(animals) != 1)
      throw new RuntimeException("check_animals failed");

    // STRING_ARRAY typemap return value
    String expected[] = { "Dave", "Mike", "Susan", "John", "Michelle" };
    String got[] = java_lib_various.get_names();
    for (int i=0; i<got.length; i++)
      if ( !got[i].equals(expected[i]) )
        throw new RuntimeException("Name failed " + i + " " + got[i] + "|" + expected[i]);

    // STRING_ARRAY variable getter
    String langscheck[] = { "Hungarian", "Afrikaans", "Norwegian" };
    String langs[] = java_lib_various.getLanguages();
    for (int i=0; i<langs.length; i++)
      if ( !langs[i].equals(langscheck[i]) )
        throw new RuntimeException("Languages read failed " + i + " " + langs[i] + "|" + langscheck[i]);

    // STRING_ARRAY variable setter
    String newLangs[] = { "French", "Italian", "Spanish" };
    java_lib_various.setLanguages(newLangs);

    // STRING_ARRAY variable getter
    langs = java_lib_various.getLanguages();
    for (int i=0; i<langs.length; i++)
      if ( !langs[i].equals(newLangs[i]) )
        throw new RuntimeException("Languages verify failed " + i + " " + langs[i] + "|" + newLangs[i]);

    // STRING_ARRAY null
    java_lib_various.setLanguages(null);
    if (java_lib_various.getLanguages() != null)
      throw new RuntimeException("languages should be null");

    // STRING_RET test
    {
      String stringOutArray[] = { "" };
      java_lib_various.char_ptr_ptr_out(stringOutArray);
      if (!stringOutArray[0].equals("returned string"))
        throw new RuntimeException("Test failed: expected: returned string. got: " + stringOutArray[0]);
    }

    // STRING_RET null array test. Check that exception is thrown.
    try {
      String stringOutArray[] = null;
      java_lib_various.char_ptr_ptr_out(stringOutArray);
      throw new RuntimeException("Test failed: null array");
    } catch (NullPointerException e) {
    }

    // STRING_RET empty array test. Check that exception is thrown.
    try {
      String stringOutArray[] = {};
      java_lib_various.char_ptr_ptr_out(stringOutArray);
      throw new RuntimeException("Test failed: empty array");
    } catch (IndexOutOfBoundsException e) {
    }

    // BYTE typemap check
    byte b[] = new byte[20];
    java_lib_various.charout(b);
    String byjovestring = new String("by jove");
    byte byjove[] = byjovestring.getBytes();
    for (int i=0; i<byjovestring.length(); i++) {
      if (byjove[i] != b[i])
        throw new RuntimeException("By jove, it failed: [" + new String(b) + "]");
    }
  }

}