mirror of https://github.com/swig/swig
Convert javascript_arrays.i example into testcase
This commit is contained in:
parent
22c8b33edd
commit
227614056b
|
@ -1,3 +0,0 @@
|
||||||
SRCS =
|
|
||||||
|
|
||||||
include $(SRCDIR)../example.mk
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target_name": "example",
|
|
||||||
"sources": [ "example_wrap.cxx" ],
|
|
||||||
"include_dirs": ["$srcdir"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
/* File : example.i */
|
|
||||||
%module example
|
|
||||||
|
|
||||||
%include <arrays_javascript.i>
|
|
||||||
|
|
||||||
%apply int[] {int *data1}
|
|
||||||
%apply int[3] {int data2[3]}
|
|
||||||
%apply int[4] {int data3[4]}
|
|
||||||
|
|
||||||
%inline %{
|
|
||||||
|
|
||||||
int sum1(int *data1, int size) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
sum += data1[i];
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sum2(int data2[3]) {
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
sum += data2[i];
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
int data3[4] = {1, 2, 3, 4};
|
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
module.exports = require("build/Release/example");
|
|
|
@ -1,7 +0,0 @@
|
||||||
var example = require("example");
|
|
||||||
|
|
||||||
var arr = [1, 2, 3, 4, 5];
|
|
||||||
|
|
||||||
console.log(example.sum1(arr, arr.length));
|
|
||||||
console.log(example.sum2(arr));
|
|
||||||
console.log(example.data3)
|
|
|
@ -1,4 +1,3 @@
|
||||||
array
|
|
||||||
class
|
class
|
||||||
constant
|
constant
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -16,6 +16,9 @@ top_builddir = @top_builddir@
|
||||||
C_TEST_CASES += \
|
C_TEST_CASES += \
|
||||||
ccomplextest \
|
ccomplextest \
|
||||||
|
|
||||||
|
CPP_TEST_CASES += \
|
||||||
|
javascript_lib_arrays \
|
||||||
|
|
||||||
SWIGEXE = $(top_builddir)/swig
|
SWIGEXE = $(top_builddir)/swig
|
||||||
SWIG_LIB_DIR = $(top_srcdir)/Lib
|
SWIG_LIB_DIR = $(top_srcdir)/Lib
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
var javascript_lib_arrays = require("javascript_lib_arrays");
|
||||||
|
|
||||||
|
var arr = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
|
function check(a, b) {
|
||||||
|
if (a !== b) {
|
||||||
|
throw new Error("Not equal: " + a + " " + b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_array(a, b) {
|
||||||
|
if (a.length != b.length)
|
||||||
|
throw new Error("Array length mismatch " + a.length + " " + b.length)
|
||||||
|
if (!a.every(function(element, index) { return element === b[index]; }))
|
||||||
|
throw new Error("Arrays don't match a:" + a + " b:" + b)
|
||||||
|
}
|
||||||
|
|
||||||
|
check(15, javascript_lib_arrays.sum1(arr, arr.length));
|
||||||
|
check(6, javascript_lib_arrays.sum2(arr));
|
||||||
|
check_array([1, 2, 3, 4], javascript_lib_arrays.data3)
|
|
@ -0,0 +1,30 @@
|
||||||
|
%module javascript_lib_arrays
|
||||||
|
|
||||||
|
%include <arrays_javascript.i>
|
||||||
|
|
||||||
|
%apply int[] { int *data1 }
|
||||||
|
%apply int[3] { int data2[3] }
|
||||||
|
%apply int[4] { int data3[4] }
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
int sum1(int *data1, int size) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
sum += data1[i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum2(int data2[3]) {
|
||||||
|
int sum = 0;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
sum += data2[i];
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int data3[4] = {1, 2, 3, 4};
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
Loading…
Reference in New Issue