PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 108 lines | 74 code | 20 blank | 14 comment | 13 complexity | 1eaec5e8247e81b4228206559eb7a962 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. import li_std_string.*;
  2. public class li_std_string_runme {
  3. static {
  4. try {
  5. System.loadLibrary("li_std_string");
  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. // Checking expected use of %typemap(in) std::string {}
  14. li_std_string.test_value("Fee");
  15. // Checking expected result of %typemap(out) std::string {}
  16. if (!li_std_string.test_value("Fi").equals("Fi"))
  17. throw new RuntimeException("Test 1 failed");
  18. // Verify type-checking for %typemap(in) std::string {}
  19. try {
  20. li_std_string.test_value(null);
  21. throw new RuntimeException("Test 2 failed");
  22. } catch (NullPointerException e) {
  23. }
  24. // Checking expected use of %typemap(in) const std::string & {}
  25. li_std_string.test_const_reference("Fo");
  26. // Checking expected result of %typemap(out) const std::string& {}
  27. if (!li_std_string.test_const_reference("Fum").equals("Fum"))
  28. throw new RuntimeException("Test 3 failed");
  29. // Verify type-checking for %typemap(in) const std::string & {}
  30. try {
  31. li_std_string.test_const_reference(null);
  32. throw new RuntimeException("Test 4 failed");
  33. } catch (NullPointerException e) {
  34. }
  35. //
  36. // Input and output typemaps for pointers and non-const references to
  37. // std::string are *not* supported; the following tests confirm
  38. // that none of these cases are slipping through.
  39. //
  40. SWIGTYPE_p_std__string stringPtr = null;
  41. stringPtr = li_std_string.test_pointer_out();
  42. li_std_string.test_pointer(stringPtr);
  43. stringPtr = li_std_string.test_const_pointer_out();
  44. li_std_string.test_const_pointer(stringPtr);
  45. stringPtr = li_std_string.test_reference_out();
  46. li_std_string.test_reference(stringPtr);
  47. // Check throw exception specification
  48. try {
  49. li_std_string.test_throw();
  50. throw new Throwable("Test 5 failed");
  51. } catch (RuntimeException e) {
  52. if (!e.getMessage().equals("test_throw message"))
  53. throw new Exception("Test 5 string check: " + e.getMessage());
  54. }
  55. try {
  56. li_std_string.test_const_reference_throw();
  57. throw new Throwable("Test 6 failed");
  58. } catch (RuntimeException e) {
  59. if (!e.getMessage().equals("test_const_reference_throw message"))
  60. throw new Exception("Test 6 string check: " + e.getMessage());
  61. }
  62. // Global variables
  63. String s = "initial string";
  64. if (!li_std_string.getGlobalString2().equals("global string 2"))
  65. throw new Exception("GlobalString2 test 1");
  66. li_std_string.setGlobalString2(s);
  67. if (!li_std_string.getGlobalString2().equals(s))
  68. throw new Exception("GlobalString2 test 2");
  69. if (!li_std_string.getConstGlobalString().equals("const global string"))
  70. throw new Exception("ConstGlobalString test");
  71. // Member variables
  72. Structure myStructure = new Structure();
  73. if (!myStructure.getMemberString2().equals("member string 2"))
  74. throw new Exception("MemberString2 test 1");
  75. myStructure.setMemberString2(s);
  76. if (!myStructure.getMemberString2().equals(s))
  77. throw new Exception("MemberString2 test 2");
  78. if (!myStructure.getConstMemberString().equals("const member string"))
  79. throw new Exception("ConstMemberString test");
  80. if (!Structure.getStaticMemberString2().equals("static member string 2"))
  81. throw new Exception("StaticMemberString2 test 1");
  82. Structure.setStaticMemberString2(s);
  83. if (!Structure.getStaticMemberString2().equals(s))
  84. throw new Exception("StaticMemberString2 test 2");
  85. if (!Structure.getConstStaticMemberString().equals("const static member string"))
  86. throw new Exception("ConstStaticMemberString test");
  87. }
  88. }