PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 163 lines | 127 code | 31 blank | 5 comment | 48 complexity | c0680594df1d08ee5a7e0be813ecff62 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. import char_strings.*;
  2. public class char_strings_runme {
  3. static {
  4. try {
  5. System.loadLibrary("char_strings");
  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. private static String CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
  12. private static String OTHERLAND_MSG = "Little message from the safe world.";
  13. public static void main(String argv[]) {
  14. long count = 10000;
  15. long i = 0;
  16. // get functions
  17. for (i=0; i<count; i++) {
  18. String str = char_strings.GetCharHeapString();
  19. if (!str.equals(CPLUSPLUS_MSG))
  20. throw new RuntimeException("Test char get 1 failed, iteration " + i);
  21. char_strings.DeleteCharHeapString();
  22. }
  23. for (i=0; i<count; i++) {
  24. String str = char_strings.GetConstCharProgramCodeString();
  25. if (!str.equals(CPLUSPLUS_MSG))
  26. throw new RuntimeException("Test char get 2 failed, iteration " + i);
  27. char_strings.DeleteCharHeapString();
  28. }
  29. for (i=0; i<count; i++) {
  30. String str = char_strings.GetCharStaticString();
  31. if (!str.equals(CPLUSPLUS_MSG))
  32. throw new RuntimeException("Test char get 3 failed, iteration " + i);
  33. }
  34. for (i=0; i<count; i++) {
  35. String str = char_strings.GetCharStaticStringFixed();
  36. if (!str.equals(CPLUSPLUS_MSG))
  37. throw new RuntimeException("Test char get 4 failed, iteration " + i);
  38. }
  39. for (i=0; i<count; i++) {
  40. String str = char_strings.GetConstCharStaticStringFixed();
  41. if (!str.equals(CPLUSPLUS_MSG))
  42. throw new RuntimeException("Test char get 5 failed, iteration " + i);
  43. }
  44. // set functions
  45. for (i=0; i<count; i++) {
  46. if (!char_strings.SetCharHeapString(OTHERLAND_MSG + i, i))
  47. throw new RuntimeException("Test char set 1 failed, iteration " + i);
  48. }
  49. for (i=0; i<count; i++) {
  50. if (!char_strings.SetCharStaticString(OTHERLAND_MSG + i, i))
  51. throw new RuntimeException("Test char set 2 failed, iteration " + i);
  52. }
  53. for (i=0; i<count; i++) {
  54. if (!char_strings.SetCharArrayStaticString(OTHERLAND_MSG + i, i))
  55. throw new RuntimeException("Test char set 3 failed, iteration " + i);
  56. }
  57. for (i=0; i<count; i++) {
  58. if (!char_strings.SetConstCharHeapString(OTHERLAND_MSG + i, i))
  59. throw new RuntimeException("Test char set 4 failed, iteration " + i);
  60. }
  61. for (i=0; i<count; i++) {
  62. if (!char_strings.SetConstCharStaticString(OTHERLAND_MSG + i, i))
  63. throw new RuntimeException("Test char set 5 failed, iteration " + i);
  64. }
  65. for (i=0; i<count; i++) {
  66. if (!char_strings.SetConstCharArrayStaticString(OTHERLAND_MSG + i, i))
  67. throw new RuntimeException("Test char set 6 failed, iteration " + i);
  68. }
  69. for (i=0; i<count; i++) {
  70. if (!char_strings.SetCharConstStaticString(OTHERLAND_MSG + i, i))
  71. throw new RuntimeException("Test char set 7 failed, iteration " + i);
  72. }
  73. for (i=0; i<count; i++) {
  74. if (!char_strings.SetConstCharConstStaticString(OTHERLAND_MSG + i, i))
  75. throw new RuntimeException("Test char set 8 failed, iteration " + i);
  76. }
  77. // get set function
  78. for (i=0; i<count; i++) {
  79. String ping = OTHERLAND_MSG + i;
  80. String pong = char_strings.CharPingPong(ping);
  81. if (!ping.equals(pong))
  82. throw new RuntimeException("Test PingPong 1 failed.\nExpected:" + ping + "\nReceived:" + pong);
  83. }
  84. // variables
  85. for (i=0; i<count; i++) {
  86. char_strings.setGlobal_char(OTHERLAND_MSG + i);
  87. if (!char_strings.getGlobal_char().equals(OTHERLAND_MSG + i))
  88. throw new RuntimeException("Test variables 1 failed, iteration " + i);
  89. }
  90. for (i=0; i<count; i++) {
  91. char_strings.setGlobal_char_array1(OTHERLAND_MSG + i);
  92. if (!char_strings.getGlobal_char_array1().equals(OTHERLAND_MSG + i))
  93. throw new RuntimeException("Test variables 2 failed, iteration " + i);
  94. }
  95. for (i=0; i<count; i++) {
  96. char_strings.setGlobal_char_array2(OTHERLAND_MSG + i);
  97. if (!char_strings.getGlobal_char_array2().equals(OTHERLAND_MSG + i))
  98. throw new RuntimeException("Test variables 3 failed, iteration " + i);
  99. }
  100. for (i=0; i<count; i++) {
  101. if (!char_strings.getGlobal_const_char().equals(CPLUSPLUS_MSG))
  102. throw new RuntimeException("Test variables 4 failed, iteration " + i);
  103. }
  104. for (i=0; i<count; i++) {
  105. if (!char_strings.getGlobal_const_char_array1().equals(CPLUSPLUS_MSG))
  106. throw new RuntimeException("Test variables 5 failed, iteration " + i);
  107. }
  108. for (i=0; i<count; i++) {
  109. if (!char_strings.getGlobal_const_char_array2().equals(CPLUSPLUS_MSG))
  110. throw new RuntimeException("Test variables 6 failed, iteration " + i);
  111. }
  112. // char *& tests
  113. for (i=0; i<count; i++) {
  114. String str = char_strings.GetCharPointerRef();
  115. if (!str.equals(CPLUSPLUS_MSG))
  116. throw new RuntimeException("Test char pointer ref get failed, iteration " + i);
  117. }
  118. for (i=0; i<count; i++) {
  119. if (!char_strings.SetCharPointerRef(OTHERLAND_MSG + i, i))
  120. throw new RuntimeException("Test char pointer ref set failed, iteration " + i);
  121. }
  122. for (i=0; i<count; i++) {
  123. String str = char_strings.GetConstCharPointerRef();
  124. if (!str.equals(CPLUSPLUS_MSG))
  125. throw new RuntimeException("Test const char pointer ref get failed, iteration " + i);
  126. }
  127. for (i=0; i<count; i++) {
  128. if (!char_strings.SetConstCharPointerRef(OTHERLAND_MSG + i, i))
  129. throw new RuntimeException("Test const char pointer ref set failed, iteration " + i);
  130. }
  131. }
  132. }