Add test to check javascript unicode strings.
This commit is contained in:
parent
caa92740d3
commit
04cdde0563
4 changed files with 39 additions and 21 deletions
|
|
@ -47,7 +47,8 @@ CPP_TEST_CASES = \
|
||||||
typemap_namespace \
|
typemap_namespace \
|
||||||
typemap_ns_using \
|
typemap_ns_using \
|
||||||
using1 \
|
using1 \
|
||||||
using2
|
using2 \
|
||||||
|
javascript_unicode
|
||||||
|
|
||||||
SKIP_CPP_CASES = @SKIP_CPP_CASES@
|
SKIP_CPP_CASES = @SKIP_CPP_CASES@
|
||||||
SKIP_C_CASES = @SKIP_C_CASES@
|
SKIP_C_CASES = @SKIP_C_CASES@
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
var str = "olé";
|
||||||
|
|
||||||
|
var copy = javascript_unicode.copy_string(str);
|
||||||
|
|
||||||
|
if (str !== copy) {
|
||||||
|
print("Error: copy is not equal: original="+str+", copy="+copy);
|
||||||
|
}
|
||||||
10
Examples/test-suite/javascript_unicode.i
Normal file
10
Examples/test-suite/javascript_unicode.i
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
%module javascript_unicode
|
||||||
|
|
||||||
|
%newobject copy_string;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
#include <string.h>
|
||||||
|
const char* copy_string(const char* str) {
|
||||||
|
return strdup(str);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
@ -8,12 +8,12 @@ SWIG_JSC_AsCharPtrAndSize(JSContextRef context, JSValueRef valRef, char** cptr,
|
||||||
if(JSValueIsString(context, valRef)) {
|
if(JSValueIsString(context, valRef)) {
|
||||||
JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
|
JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
|
||||||
size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
|
size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
|
||||||
size_t abs_len = JSStringGetLength(js_str);
|
|
||||||
char* cstr = (char*) malloc(len * sizeof(char));
|
char* cstr = (char*) malloc(len * sizeof(char));
|
||||||
JSStringGetUTF8CString(js_str, cstr, len);
|
/* JSStringGetUTF8CString returns the length including 0-terminator */
|
||||||
|
len = JSStringGetUTF8CString(js_str, cstr, len);
|
||||||
|
|
||||||
if(alloc) *alloc = SWIG_NEWOBJ;
|
if(alloc) *alloc = SWIG_NEWOBJ;
|
||||||
if(psize) *psize = abs_len + 1;
|
if(psize) *psize = len;
|
||||||
if(cptr) *cptr = cstr;
|
if(cptr) *cptr = cstr;
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue