summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Jezabek <jezabek@poczta.onet.pl>2008-08-17 23:49:15 +0000
committerJan Jezabek <jezabek@poczta.onet.pl>2008-08-17 23:49:15 +0000
commit78a550dfe9611068226b84adac9c7b25ba7eb36b (patch)
treef1272f4c4dcca4f5ebc1c9780b1b1f63b6778c1c
parent1fc8ca6257292d60b34a17983696047b24283225 (diff)
downloadswig-78a550dfe9611068226b84adac9c7b25ba7eb36b.tar.gz
Added char_strings run-test. Changed mapping of bool-s from unsigned int to int (I will need to change it to VT_BOOL at some point). Added support for char *& and wchar_t *&.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-jezabek@10774 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Examples/test-suite/com/char_strings_runme.vbs174
-rw-r--r--Lib/com/com.swg64
-rw-r--r--Lib/com/typemaps.i12
3 files changed, 238 insertions, 12 deletions
diff --git a/Examples/test-suite/com/char_strings_runme.vbs b/Examples/test-suite/com/char_strings_runme.vbs
new file mode 100644
index 000000000..ba9287f87
--- /dev/null
+++ b/Examples/test-suite/com/char_strings_runme.vbs
@@ -0,0 +1,174 @@
+Dim CPLUSPLUS_MSG, OTHERLAND_MSG, char_strings
+
+CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."
+OTHERLAND_MSG = "Little message from the safe world."
+
+Set char_strings = CreateObject("char_strings.char_strings")
+
+Dim count, i, str
+count = 10000
+
+Rem get functions
+
+For i = 0 to count - 1
+ str = char_strings.GetCharHeapString()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char get 1 failed, iteration " & i
+ WScript.Quit 1
+ End If
+ char_strings.DeleteCharHeapString()
+Next
+
+For i = 0 to count - 1
+ str = char_strings.GetConstCharProgramCodeString()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char get 2 failed, iteration " & i
+ WScript.Quit 1
+ End If
+ char_strings.DeleteCharHeapString()
+Next
+
+For i = 0 to count - 1
+ str = char_strings.GetCharStaticString()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char get 3 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ str = char_strings.GetCharStaticStringFixed()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char get 4 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ str = char_strings.GetConstCharStaticStringFixed()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char get 5 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+Rem set functions
+
+For i = 0 to count - 1
+ If char_strings.SetCharHeapString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 1 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetCharStaticString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 2 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetCharArrayStaticString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 3 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetConstCharHeapString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 4 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetConstCharStaticString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 5 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetConstCharArrayStaticString(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char set 6 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+Rem get set function
+
+Dim ping, pong
+
+For i = 0 to count - 1
+ ping = OTHERLAND_MSG & i
+ pong = char_strings.CharPingPong(ping)
+ If ping <> pong Then
+ WScript.Echo "Test PingPong 1 failed."
+ WScript.Echo "Expected:" & ping
+ WScript.Echo "Reveived:" & pong
+ WScript.Quit 1
+ End If
+Next
+
+Rem variables
+
+For i = 0 to count - 1
+ char_strings.global_char = OTHERLAND_MSG & i
+ If char_strings.global_char <> OTHERLAND_MSG & i Then
+ WScript.Echo "Test variables 1 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ char_strings.global_char_array1 = OTHERLAND_MSG & i
+ If char_strings.global_char_array1 <> OTHERLAND_MSG & i Then
+ WScript.Echo "Test variables 2 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ char_strings.global_char_array2 = OTHERLAND_MSG & i
+ If char_strings.global_char_array2 <> OTHERLAND_MSG & i Then
+ WScript.Echo "Test variables 3 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.global_const_char <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test variables 4 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.global_const_char_array1 <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test variables 5 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.global_const_char_array2 <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test variables 6 failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ str = char_strings.GetConstCharPointerRef()
+ If str <> CPLUSPLUS_MSG Then
+ WScript.Echo "Test char pointer ref get failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
+
+For i = 0 to count - 1
+ If char_strings.SetConstCharPointerRef(OTHERLAND_MSG & i, i) = 0 Then
+ WScript.Echo "Test char pointer ref set failed, iteration " & i
+ WScript.Quit 1
+ End If
+Next
diff --git a/Lib/com/com.swg b/Lib/com/com.swg
index 3edfd9439..471aa52eb 100644
--- a/Lib/com/com.swg
+++ b/Lib/com/com.swg
@@ -7,7 +7,7 @@
* COM typemaps
* ----------------------------------------------------------------------------- */
-%typemap(ctype) bool, const bool & "unsigned int"
+%typemap(ctype) bool, const bool & "int"
%typemap(ctype) char, const char & "char"
%typemap(ctype) signed char, const signed char & "signed char"
%typemap(ctype) unsigned char, const unsigned char & "unsigned char"
@@ -28,7 +28,7 @@
%typemap(ctype) SWIGTYPE & "SWIGIUnknown *"
%typemap(ctype) enum SWIGTYPE "int"
-%typemap(comtype) bool, const bool & "unsigned int"
+%typemap(comtype) bool, const bool & "int"
%typemap(comtype) char, const char & "char"
%typemap(comtype) signed char, const signed char & "signed char"
%typemap(comtype) unsigned char, const unsigned char & "unsigned char"
@@ -191,8 +191,8 @@
%typemap(out) void ""
-%typemap(ctype) char *, char[], char[ANY] "WCHAR *"
-%typemap(comtype) char *, char[], char[ANY] "BSTR"
+%typemap(ctype) char *, char *&, char[], char[ANY] "WCHAR *"
+%typemap(comtype) char *, char *&, char[], char[ANY] "BSTR"
%typemap(in) char *, char[], char[ANY] {
if ($input) {
@@ -208,6 +208,21 @@
}
}
+%typemap(in) char *& ($*1_ltype temp = 0) {
+ if ($input) {
+ int SWIG_len = WideCharToMultiByte(CP_ACP, 0, $input, -1, 0, 0, 0, 0);
+ temp = ($*1_ltype) malloc(SWIG_len);
+ WideCharToMultiByte(CP_ACP, 0, $input, -1, (char *) temp, SWIG_len, 0, 0);
+ $1 = &temp;
+ }
+}
+
+%typemap(freearg) char *& {
+ if ($input) {
+ free(*$1);
+ }
+}
+
%typemap(out) char *, char[], char[ANY] %{
if ($1) {
int SWIG_len = MultiByteToWideChar(CP_ACP, 0, (char *) $1, -1, 0, 0);
@@ -219,8 +234,19 @@
}
%}
-%typemap(ctype) wchar_t *, wchar_t[], wchar_t[ANY] "WCHAR *"
-%typemap(comtype) wchar_t *, wchar_t[], wchar_t[ANY] "BSTR"
+%typemap(out) char *& {
+ if (*$1) {
+ int SWIG_len = MultiByteToWideChar(CP_ACP, 0, (char *) *$1, -1, 0, 0);
+ WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR));
+ /* First 4 bytes contain length in bytes */
+ *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR);
+ MultiByteToWideChar(CP_ACP, 0, (char *) *$1, -1, SWIG_res + 2, SWIG_len);
+ $result = SWIG_res + 2;
+ }
+}
+
+%typemap(ctype) wchar_t *, wchar_t *&, wchar_t[], wchar_t[ANY] "WCHAR *"
+%typemap(comtype) wchar_t *, wchar_t *&, wchar_t[], wchar_t[ANY] "BSTR"
%typemap(in) wchar_t *, wchar_t[], wchar_t[ANY] {
if ($input) {
@@ -236,6 +262,21 @@
}
}
+%typemap(in) wchar_t *& ($*1_ltype temp = 0) {
+ if ($input) {
+ int SWIG_len = wcslen($input) + 1;
+ temp = ($1_ltype) malloc(SWIG_len * sizeof(wchar_t));
+ wcsncpy(temp, $input, SWIG_len);
+ $1 = &temp;
+ }
+}
+
+%typemap(freearg) wchar_t *& {
+ if ($input) {
+ free(*$1);
+ }
+}
+
%typemap(out) wchar_t *, wchar_t[], wchar_t[ANY] %{
if ($1) {
int SWIG_len = wcslen((wchar_t *) $1) + 1;
@@ -247,6 +288,17 @@
}
%}
+%typemap(out) wchar_t *& %{
+ if ($1) {
+ int SWIG_len = wcslen((wchar_t *) *$1) + 1;
+ WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR));
+ /* First 4 bytes contain length in bytes */
+ *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR);
+ wcsncpy(SWIG_res + 2, *$1, SWIG_len);
+ $result = SWIG_res + 2;
+ }
+%}
+
%typemap(out) SWIGTYPE *, SWIGTYPE (CLASS::*) %{
if ($1) {
$result = (SWIGIUnknown *) SWIG_wrap$comclassname(*(void **) &$1, $owner);
diff --git a/Lib/com/typemaps.i b/Lib/com/typemaps.i
index f2abb8204..4ff9d512f 100644
--- a/Lib/com/typemaps.i
+++ b/Lib/com/typemaps.i
@@ -9,7 +9,7 @@
/* INPUT typemaps */
-%typemap(ctype) bool *INPUT, bool &INPUT "unsigned int *"
+%typemap(ctype) bool *INPUT, bool &INPUT "int *"
%typemap(ctype) signed char *INPUT, signed char &INPUT "signed char *"
%typemap(ctype) unsigned char *INPUT, unsigned char &INPUT "unsigned char *"
%typemap(ctype) short *INPUT, short &INPUT "short *"
@@ -23,7 +23,7 @@
%typemap(ctype) float *INPUT, float &INPUT "float *"
%typemap(ctype) double *INPUT, double &INPUT "double *"
-%typemap(comtype, attribute="in") bool *INPUT, bool &INPUT "unsigned int *"
+%typemap(comtype, attribute="in") bool *INPUT, bool &INPUT "int *"
%typemap(comtype, attribute="in") signed char *INPUT, signed char &INPUT "signed char *"
%typemap(comtype, attribute="in") unsigned char *INPUT, unsigned char &INPUT "unsigned char *"
%typemap(comtype, attribute="in") short *INPUT, short &INPUT "short *"
@@ -85,7 +85,7 @@
/* OUTPUT typemaps */
-%typemap(ctype) bool *OUTPUT, bool &OUTPUT "unsigned int *"
+%typemap(ctype) bool *OUTPUT, bool &OUTPUT "int *"
%typemap(ctype) signed char *OUTPUT, signed char &OUTPUT "signed char *"
%typemap(ctype) unsigned char *OUTPUT, unsigned char &OUTPUT "unsigned char *"
%typemap(ctype) short *OUTPUT, short &OUTPUT "short *"
@@ -99,7 +99,7 @@
%typemap(ctype) float *OUTPUT, float &OUTPUT "float *"
%typemap(ctype) double *OUTPUT, double &OUTPUT "double *"
-%typemap(comtype, attribute="out") bool *OUTPUT, bool &OUTPUT "unsigned int *"
+%typemap(comtype, attribute="out") bool *OUTPUT, bool &OUTPUT "int *"
%typemap(comtype, attribute="out") signed char *OUTPUT, signed char &OUTPUT "signed char *"
%typemap(comtype, attribute="out") unsigned char *OUTPUT, unsigned char &OUTPUT "unsigned char *"
%typemap(comtype, attribute="out") short *OUTPUT, short &OUTPUT "short *"
@@ -163,7 +163,7 @@
/* INOUT typemaps */
-%typemap(ctype) bool *INOUT, bool &INOUT "unsigned int *"
+%typemap(ctype) bool *INOUT, bool &INOUT "int *"
%typemap(ctype) signed char *INOUT, signed char &INOUT "signed char *"
%typemap(ctype) unsigned char *INOUT, unsigned char &INOUT "unsigned char *"
%typemap(ctype) short *INOUT, short &INOUT "short *"
@@ -177,7 +177,7 @@
%typemap(ctype) float *INOUT, float &INOUT "float *"
%typemap(ctype) double *INOUT, double &INOUT "double *"
-%typemap(comtype, attribute="in, out") bool *INOUT, bool &INOUT "unsigned int *"
+%typemap(comtype, attribute="in, out") bool *INOUT, bool &INOUT "int *"
%typemap(comtype, attribute="in, out") signed char *INOUT, signed char &INOUT "signed char *"
%typemap(comtype, attribute="in, out") unsigned char *INOUT, unsigned char &INOUT "unsigned char *"
%typemap(comtype, attribute="in, out") short *INOUT, short &INOUT "short *"