Skip to content

Commit 77cdba8

Browse files
committed
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.
1 parent 266766d commit 77cdba8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Examples/test-suite/common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ CPP_TEST_CASES += \
214214
director_protected_overloaded \
215215
director_redefined \
216216
director_ref \
217+
director_simple \
217218
director_smartptr \
218219
director_thread \
219220
director_unroll \

Examples/test-suite/director_simple.i

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
%module(directors="1") director_simple
2+
3+
%feature("director") IntBase;
4+
%feature("director") BoolBase;
5+
6+
%inline %{
7+
class IntBase {
8+
public:
9+
virtual ~IntBase() {}
10+
IntBase(int i = 3) { (void)i; }
11+
virtual int apply(int x) const { return x * 2; }
12+
};
13+
14+
class IntDerived : public IntBase {
15+
public:
16+
virtual int apply(int x) const { return x * 3; }
17+
};
18+
19+
int apply(const IntBase& b, int x)
20+
{
21+
return b.apply(x);
22+
}
23+
24+
class BoolBase {
25+
public:
26+
virtual ~BoolBase() {}
27+
BoolBase() {}
28+
virtual bool apply(bool a, bool b) const = 0;
29+
};
30+
31+
class BoolDerived : public BoolBase {
32+
public:
33+
virtual bool apply(bool a, bool b) const { return a != b; }
34+
};
35+
36+
bool apply(const BoolBase& base, bool a, bool b)
37+
{
38+
return base.apply(a, b);
39+
}
40+
41+
%}
42+

0 commit comments

Comments
 (0)