Add test case for very simple director classes

Test both abstract and concrete base classes, with simple int/bool data.
This level of complexity is very helpful when setting up director
functionality for a new target language.
This commit is contained in:
Seth R Johnson 2022-02-12 19:19:31 -05:00
parent 266766d7c7
commit 77cdba81ad
2 changed files with 43 additions and 0 deletions

View File

@ -214,6 +214,7 @@ CPP_TEST_CASES += \
director_protected_overloaded \
director_redefined \
director_ref \
director_simple \
director_smartptr \
director_thread \
director_unroll \

View File

@ -0,0 +1,42 @@
%module(directors="1") director_simple
%feature("director") IntBase;
%feature("director") BoolBase;
%inline %{
class IntBase {
public:
virtual ~IntBase() {}
IntBase(int i = 3) { (void)i; }
virtual int apply(int x) const { return x * 2; }
};
class IntDerived : public IntBase {
public:
virtual int apply(int x) const { return x * 3; }
};
int apply(const IntBase& b, int x)
{
return b.apply(x);
}
class BoolBase {
public:
virtual ~BoolBase() {}
BoolBase() {}
virtual bool apply(bool a, bool b) const = 0;
};
class BoolDerived : public BoolBase {
public:
virtual bool apply(bool a, bool b) const { return a != b; }
};
bool apply(const BoolBase& base, bool a, bool b)
{
return base.apply(a, b);
}
%}