PageRenderTime 40ms CodeModel.GetById 1ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 1ms

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

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