Add support for java.nio.Buffer

including test-suite test case and documentation
This commit is contained in:
Yuval Kashtan 2014-07-18 15:45:16 +03:00
commit 093fe2a556
4 changed files with 69 additions and 0 deletions

View file

@ -83,6 +83,25 @@ public class java_lib_various_runme {
if (byjove[i] != b[i])
throw new RuntimeException("By jove, it failed: [" + new String(b) + "]");
}
// NIOBUFFER typemap check
java.nio.ByteBuffer buf = java.nio.ByteBuffer.allocateDirect(10);
java_lib_various.niobuffer_fill_hello(buf);
if (
(char)buf.get(0) != 'h' ||
(char)buf.get(1) != 'e' ||
(char)buf.get(2) != 'l' ||
(char)buf.get(3) != 'l' ||
(char)buf.get(4) != 'o'
)
throw new RuntimeException(
"nio test failed: " +
(char)buf.get(0) +
(char)buf.get(1) +
(char)buf.get(2) +
(char)buf.get(3) +
(char)buf.get(4)
);
}
}

View file

@ -8,6 +8,7 @@
%apply char **STRING_ARRAY { char **languages };
%apply char *BYTE { char *chars };
%apply char **STRING_OUT { char **string_ptr };
%apply unsigned char *NIOBUFFER { unsigned char *buf };
%typemap(freearg) char **languages "" // don't delete memory when setting global variable
%{
@ -47,5 +48,8 @@ void char_ptr_ptr_out(char **string_ptr) {
*string_ptr = ret;
}
void niobuffer_fill_hello(unsigned char *buf) {
sprintf ((char*)buf,"hello");
}
%}