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