2 A test case for testing char based strings. Useful for runtime testing,
3 there were some runtime crashes and leaks in the C# module in some of the scenarios
9 %warnfilter(SWIGWARN_TYPEMAP_VARIN_UNDEF) global_char_array1; // Unable to set variable of type char[]
10 %warnfilter(SWIGWARN_TYPEMAP_CHARLEAK_MSG) global_const_char; // Setting a const char * variable may leak memory.
12 #ifdef SWIG_ALLEGRO_CL
19 #define OTHERLAND_MSG "Little message from the safe world."
20 #define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible."
21 static char *global_str = NULL;
22 const int UINT_DIGITS = 10; // max unsigned int is 4294967295
24 bool check(const char *str, unsigned int number) {
25 static char expected[256];
26 sprintf(expected, "%s%d", OTHERLAND_MSG, number);
27 bool matches = (strcmp(str, expected) == 0);
28 if (!matches) printf("Failed: [%s][%s]\n", str, expected);
34 %immutable global_const_char;
38 char *GetCharHeapString() {
39 global_str = new char[sizeof(CPLUSPLUS_MSG)+1];
40 strcpy(global_str, CPLUSPLUS_MSG);
44 const char *GetConstCharProgramCodeString() {
48 void DeleteCharHeapString() {
53 char *GetCharStaticString() {
54 static char str[sizeof(CPLUSPLUS_MSG)+1];
55 strcpy(str, CPLUSPLUS_MSG);
59 char *GetCharStaticStringFixed() {
60 static char str[] = CPLUSPLUS_MSG;
64 const char *GetConstCharStaticStringFixed() {
65 static const char str[] = CPLUSPLUS_MSG;
70 bool SetCharHeapString(char *str, unsigned int number) {
72 global_str = new char[strlen(str)+UINT_DIGITS+1];
73 strcpy(global_str, str);
74 return check(global_str, number);
77 bool SetCharStaticString(char *str, unsigned int number) {
78 static char static_str[] = CPLUSPLUS_MSG;
79 strcpy(static_str, str);
80 return check(static_str, number);
83 bool SetCharArrayStaticString(char str[], unsigned int number) {
84 static char static_str[] = CPLUSPLUS_MSG;
85 strcpy(static_str, str);
86 return check(static_str, number);
89 bool SetConstCharHeapString(const char *str, unsigned int number) {
91 global_str = new char[strlen(str)+UINT_DIGITS+1];
92 strcpy(global_str, str);
93 return check(global_str, number);
96 bool SetConstCharStaticString(const char *str, unsigned int number) {
97 static char static_str[] = CPLUSPLUS_MSG;
98 strcpy(static_str, str);
99 return check(static_str, number);
102 bool SetConstCharArrayStaticString(const char str[], unsigned int number) {
103 static char static_str[] = CPLUSPLUS_MSG;
104 strcpy(static_str, str);
105 return check(static_str, number);
109 char *CharPingPong(char *str) {
114 char *global_char = NULL;
115 char global_char_array1[] = CPLUSPLUS_MSG;
116 char global_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG;
118 const char *global_const_char = CPLUSPLUS_MSG;
119 const char global_const_char_array1[] = CPLUSPLUS_MSG;
120 const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG;
125 %typemap(newfree) char *GetNewCharString() { /* hello */ delete[] $1; }
126 %newobject GetNewCharString();
129 char *GetNewCharString() {
130 char *nstr = new char[sizeof(CPLUSPLUS_MSG)+1];
131 strcpy(nstr, CPLUSPLUS_MSG);
140 static int GetNextFormat(Formatpos& itr, const char*& str,OBFormat*& pFormat) {
152 char *&GetCharPointerRef() {
153 static char str[] = CPLUSPLUS_MSG;
154 static char *ptr = str;
158 bool SetCharPointerRef(char *&str, unsigned int number) {
159 static char static_str[] = CPLUSPLUS_MSG;
160 strcpy(static_str, str);
161 return check(static_str, number);
164 const char *&GetConstCharPointerRef() {
165 static const char str[] = CPLUSPLUS_MSG;
166 static const char *ptr = str;
170 bool SetConstCharPointerRef(const char *&str, unsigned int number) {
171 static char static_str[] = CPLUSPLUS_MSG;
172 strcpy(static_str, str);
173 return check(static_str, number);