1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// test matrix.i library
exec("swigtest.start", -1);
// test matrix passed as output argument from fonction
function test_outMatrix(func, valueType, expectedOutMatrix)
funcName = msprintf("out%s%s", valueType, func);
cmd = msprintf("outMatrix = %s();", funcName);
ierr = execstr(cmd, "errcatch");
if ierr <> 0 then
swigtesterror(msprintf("Error %d in %s", ierr, funcName));
end
checkequal(outMatrix, expectedOutMatrix, funcName);
endfunction
// test matrix passed as input argument of fonction
function test_inMatrix(func, valueType, inMatrix, expectedInValue)
funcName = msprintf("in%s%s", valueType, func);
cmd = msprintf("inValue = %s(inMatrix);", funcName);
ierr = execstr(cmd, "errcatch");
if ierr <> 0 then
swigtesterror(msprintf("Error %d in %s", ierr, funcName));
end
checkequal(inValue, expectedInValue, funcName);
endfunction
// test matrixes passed as input and output arguments of fonction
function test_inoutMatrix(func, valueType, inoutMatrix, expectedInoutMatrix)
funcName = msprintf("inout%s%s", valueType, func);
cmd = msprintf("inoutMatrix = %s(inoutMatrix);", funcName);
ierr = execstr(cmd, "errcatch");
if ierr <> 0 then
swigtesterror(msprintf("Error %d in %s", ierr, funcName));
end
checkequal(inoutMatrix, expectedInoutMatrix, funcName);
endfunction
function test_matrix_typemaps(valueType, ..
expectedOutMatrixDims, expectedOutMatrixSize, ..
expectedInValue, ..
expectedInoutMatrixDims, expectedInoutMatrixSize)
test_outMatrix("MatrixDims", valueType, expectedOutMatrixDims);
test_outMatrix("MatrixSize", valueType, expectedOutMatrixSize);
matrixDims = expectedOutMatrixDims;
matrixSize = expectedOutMatrixSize;
test_inMatrix("MatrixDims", valueType, matrixDims, expectedInValue);
test_inMatrix("MatrixSize", valueType, matrixSize, expectedInValue);
test_inoutMatrix("MatrixDims", valueType, matrixDims, expectedInoutMatrixDims);
test_inoutMatrix("MatrixSize", valueType, matrixSize, expectedInoutMatrixSize);
endfunction
m = [0 3; 1 4; 2 5];
v = [0 1 2 3 4 5];
test_matrix_typemaps("Int", m, v, sum(m), m .* m, v .* v);
test_matrix_typemaps("Double", m, v, sum(m), m .* m, v .* v);
m = ["A" "D"; "B" "E"; "C" "F"];
v = ["A" "B" "C" "D" "E" "F"];
test_matrix_typemaps("CharPtr", m, v, strcat(m), m + m, v + v);
m = [%T %F; %F %T; %T %F];
v = [%T %F %T %F %T %F];
test_matrix_typemaps("Bool", m, v, %T, ~m, ~v);
exec("swigtest.quit", -1);
|