scilab: new test overload_arrays

This commit is contained in:
Simon Marchetto 2014-03-31 17:00:00 +02:00
commit 2d11ed3932
3 changed files with 196 additions and 2 deletions

View file

@ -0,0 +1,147 @@
// Tests of overloaded functions of arrays
%module overload_arrays
#ifdef SWIGCHICKEN
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fbool;
#endif
#ifdef SWIGLUA
// lua only has one numeric type, so most of the overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) bar;
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Spam;
#endif
#ifdef SWIGGO
%warnfilter(SWIGWARN_PARSE_KEYWORD) type; // 'type' is a Go keyword, renamed as 'Xtype'
%rename(Foos) Foo;
#endif
#ifndef SWIG_NO_OVERLOAD
%immutable Spam::type;
%inline %{
#define SIZE 3
struct Foo {
};
class Bar {
public:
Bar(int i = 0) { num = i; }
static int foo(int a=0, int b=0) {return 0;}
int num;
};
char *foo() {
return (char *) "foo:";
}
char *foo(int[SIZE]) {
return (char*) "foo:int[SIZE]";
}
char *foo(double[SIZE]) {
return (char*) "foo:double[SIZE]";
}
char *foo(char *[SIZE]) {
return (char*) "foo:char *[SIZE]";
}
char *foo(Foo *[SIZE]) {
return (char*) "foo:Foo *[SIZE]";
}
char *foo(Bar *[SIZE]) {
return (char *) "foo:Bar *[SIZE]";
}
char *foo(void *[SIZE]) {
return (char *) "foo:void *[SIZE]";
}
char *foo(Foo *[SIZE], int[SIZE]) {
return (char *) "foo:Foo *[SIZE],int[SIZE]";
}
char *foo(double[SIZE], Bar *[SIZE]) {
return (char *) "foo:double[SIZE],Bar *[SIZE]";
}
char *blah(double[SIZE]) {
return (char *) "blah:double[SIZE]";
}
char *blah(char *[SIZE]) {
return (char *) "blah:char *[SIZE]";
}
class Spam {
public:
Spam() { type = "none"; }
Spam(int[SIZE]) { type = "int[SIZE]"; }
Spam(double[SIZE]) { type = "double[SIZE]"; }
Spam(char *[SIZE]) { type = "char *[SIZE]"; }
Spam(Foo *[SIZE]) { type = "Foo *[SIZE]"; }
Spam(Bar *[SIZE]) { type = "Bar *[SIZE]"; }
Spam(void *[SIZE]) { type = "void *[SIZE]"; }
const char *type;
char *foo(int[SIZE]) {
return (char*) "foo:int[SIZE]";
}
char *foo(double[SIZE]) {
return (char*) "foo:double[SIZE]";
}
char *foo(char *[SIZE]) {
return (char*) "foo:char *[SIZE]";
}
char *foo(Foo *[SIZE]) {
return (char*) "foo:Foo *[SIZE]";
}
char *foo(Bar *[SIZE]) {
return (char *) "foo:Bar *[SIZE]";
}
char *foo(void *[SIZE]) {
return (char *) "foo:void *[SIZE]";
}
static char *bar(int[SIZE]) {
return (char*) "bar:int[SIZE]";
}
static char *bar(double[SIZE]) {
return (char*) "bar:double[SIZE]";
}
static char *bar(char *[SIZE]) {
return (char*) "bar:char *[SIZE]";
}
static char *bar(Foo *[SIZE]) {
return (char*) "bar:Foo *[SIZE]";
}
static char *bar(Bar *[SIZE]) {
return (char *) "bar:Bar *[SIZE]";
}
static char *bar(void *[SIZE]) {
return (char *) "bar:void *[SIZE]";
}
};
%}
#endif
%inline {
class ClassA
{
public:
ClassA() {}
int method1( ) {return 0;}
int method1( int arg1[SIZE] ) {return arg1[0];}
protected:
int method1( int arg1[SIZE], int arg2[SIZE] ) {return arg1[0] + arg2[0];}
};
}

View file

@ -15,10 +15,11 @@ C_TEST_CASES += \
scilab_consts \
CPP_TEST_CASES += \
primitive_types \
inout \
primitive_types \
inout \
scilab_li_matrix \
scilab_pointer_conversion_functions \
overload_arrays \
CPP_STD_TEST_CASES += \
li_std_container_typemaps \

View file

@ -0,0 +1,46 @@
exec("swigtest.start", -1);
// Functions
checkequal(foo(int32([1, 2, 3])), "foo:int[SIZE]", "foo(int[SIZE])");
checkequal(foo([1, 2, 3]), "foo:double[SIZE]", "foo(double[SIZE])");
checkequal(foo(["1" "2" "3"]), "foo:char *[SIZE]", "foo(char *[SIZE])");
// Class methods
s = new_Spam();
checkequal(Spam_foo(s, int32([1, 2, 3])), "foo:int[SIZE]", "Spam::foo(int[SIZE])");
checkequal(Spam_foo(s, [1, 2, 3]), "foo:double[SIZE]", "Spam::foo(double[SIZE])");
checkequal(Spam_foo(s, ["1" "2" "3"]), "foo:char *[SIZE]", "Spam::foo(char *[SIZE])");
delete_Spam(s);
// Static class methods
checkequal(Spam_bar(int32([1, 2, 3])), "bar:int[SIZE]", "Spam::bar(int[SIZE])");
checkequal(Spam_bar([1, 2, 3]), "bar:double[SIZE]", "Spam::bar(double[SIZE])");
checkequal(Spam_bar("hello"), "bar:char *[SIZE]", "Spam::bar(char *[SIZE])");
// Constructors
s = new_Spam();
checkequal(Spam_type_get(s), "none", "Spam::Spam()");
delete_Spam(s);
s = new_Spam(int32([1, 2, 3]));
checkequal(Spam_type_get(s), "int[SIZE]", "Spam::Spam(int[SIZE])");
delete_Spam(s);
s = new_Spam([1, 2, 3]);
checkequal(Spam_type_get(s), "double[SIZE]", "Spam::Spam(double[SIZE])");
delete_Spam(s);
s = new_Spam(["1" "2" "3"]);
checkequal(Spam_type_get(s), "char *[SIZE]", "Spam::Spam(char *[SIZE])");
delete_Spam(s);
a = new_ClassA();
b = ClassA_method1(a, [1 2 3]);
exec("swigtest.quit", -1);