scilab: new test for constants (scilabconst)

This commit is contained in:
Simon Marchetto 2014-02-17 16:28:42 +01:00
commit d8135e7387
3 changed files with 76 additions and 1 deletions

View file

@ -11,7 +11,8 @@ top_srcdir = $(abspath @top_srcdir@)
top_builddir = $(abspath @top_builddir@)
C_TEST_CASES += \
scilab_enums
scilab_enums \
scilab_consts \
CPP_STD_TEST_CASES += \
primitive_types \

View file

@ -0,0 +1,32 @@
exec("swigtest.start", -1);
function checkConst(const_val, expected_type, expected_const_val)
if typeof(const_val) <> expected_type then swigtesterror(); end
if const_val <> expected_const_val then swigtesterror(); end
endfunction
checkConst(ICONST0_get(), "constant", 42);
checkConst(FCONST0_get(), "constant", 2.1828);
checkConst(CCONST0_get(), "string", "x");
//checkConst(CCONST0_2_get(), "string", "\n");
checkConst(SCONST0_get(), "string", "Hello World");
checkConst(SCONST0_2_get(), "string", """Hello World""");
checkConst(EXPR0_get(), "constant", 48.5484);
checkConst(iconst0_get(), "constant", 37);
checkConst(fconst0_get(), "constant", 42.2);
if isdef('BAR0') then swigtesterror(); end
checkConst(ICONST1, "int32", 42);
checkConst(FCONST1, "constant", 2.1828);
checkConst(CCONST1, "string", "x");
//checkConst(CCONST1_2, "string", "\n");
checkConst(SCONST1, "string", "Hello World");
checkConst(SCONST1_2, "string", """Hello World""");
checkConst(EXPR1, "constant", 48.5484);
checkConst(iconst0_get(), "constant", 37);
checkConst(fconst0_get(), "constant", 42.2);
if isdef('BAR1') then swigtesterror(); end
exec("swigtest.quit", -1);

View file

@ -0,0 +1,42 @@
%module scilab_consts
/* Default mode: constants are wrapped as getter functions */
%scilabconst(0);
#define ICONST0 42
#define FCONST0 2.1828
#define CCONST0 'x'
#define CCONST0_2 '\n'
#define SCONST0 "Hello World"
#define SCONST0_2 "\"Hello World\""
/* Expressions should work too */
#define EXPR0 ICONST0 + 3*FCONST0
/* This shouldn't do anything, bar is not defined */
#define BAR0 bar
/* SWIG directive %constant produces constants too */
%constant int iconst0 = 37;
%constant double fconst0 = 42.2;
/* Alternative mode: constants are wrapped as variables */
%scilabconst(1);
#define ICONST1 42
#define FCONST1 2.1828
#define CCONST1 'x'
#define CCONST1_2 '\n'
#define SCONST1 "Hello World"
#define SCONST1_2 "\"Hello World\""
/* Expressions should work too */
#define EXPR1 ICONST1 + 3*FCONST1
/* This shouldn't do anything, bar is not defined */
#define BAR1 bar
/* SWIG directive %constant produces constants too */
%constant int iconst1 = 37;
%constant double fconst1 = 42.2;