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