PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 83 lines | 58 code | 15 blank | 10 comment | 12 complexity | cc10e87740784862293e2a60c5a48899 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // Test case to check typemaps in various.i
  2. import java_lib_various.*;
  3. public class java_lib_various_runme {
  4. static {
  5. try {
  6. System.loadLibrary("java_lib_various");
  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. // STRING_ARRAY typemap parameter
  14. String animals[] = {"Cat","Dog","Cow","Goat"};
  15. if (java_lib_various.check_animals(animals) != 1)
  16. throw new RuntimeException("check_animals failed");
  17. // STRING_ARRAY typemap return value
  18. String expected[] = { "Dave", "Mike", "Susan", "John", "Michelle" };
  19. String got[] = java_lib_various.get_names();
  20. for (int i=0; i<got.length; i++)
  21. if ( !got[i].equals(expected[i]) )
  22. throw new RuntimeException("Name failed " + i + " " + got[i] + "|" + expected[i]);
  23. // STRING_ARRAY variable getter
  24. String langscheck[] = { "Hungarian", "Afrikaans", "Norwegian" };
  25. String langs[] = java_lib_various.getLanguages();
  26. for (int i=0; i<langs.length; i++)
  27. if ( !langs[i].equals(langscheck[i]) )
  28. throw new RuntimeException("Languages read failed " + i + " " + langs[i] + "|" + langscheck[i]);
  29. // STRING_ARRAY variable setter
  30. String newLangs[] = { "French", "Italian", "Spanish" };
  31. java_lib_various.setLanguages(newLangs);
  32. // STRING_ARRAY variable getter
  33. langs = java_lib_various.getLanguages();
  34. for (int i=0; i<langs.length; i++)
  35. if ( !langs[i].equals(newLangs[i]) )
  36. throw new RuntimeException("Languages verify failed " + i + " " + langs[i] + "|" + newLangs[i]);
  37. // STRING_RET test
  38. {
  39. String stringOutArray[] = { "" };
  40. java_lib_various.char_ptr_ptr_out(stringOutArray);
  41. if (!stringOutArray[0].equals("returned string"))
  42. throw new RuntimeException("Test failed: expected: returned string. got: " + stringOutArray[0]);
  43. }
  44. // STRING_RET null array test. Check that exception is thrown.
  45. try {
  46. String stringOutArray[] = null;
  47. java_lib_various.char_ptr_ptr_out(stringOutArray);
  48. throw new RuntimeException("Test failed: null array");
  49. } catch (NullPointerException e) {
  50. }
  51. // STRING_RET empty array test. Check that exception is thrown.
  52. try {
  53. String stringOutArray[] = {};
  54. java_lib_various.char_ptr_ptr_out(stringOutArray);
  55. throw new RuntimeException("Test failed: empty array");
  56. } catch (IndexOutOfBoundsException e) {
  57. }
  58. // BYTE typemap check
  59. byte b[] = new byte[20];
  60. java_lib_various.charout(b);
  61. String byjovestring = new String("by jove");
  62. byte byjove[] = byjovestring.getBytes();
  63. for (int i=0; i<byjovestring.length(); i++) {
  64. if (byjove[i] != b[i])
  65. throw new RuntimeException("By jove, it failed: [" + new String(b) + "]");
  66. }
  67. }
  68. }