Skip to content

Commit 0da8a9b

Browse files
committed
Test ability to manipulate a daughter class from its base class wrapper
Even in the case of just creating a `DerivedClass` this test says: ``` swig/python detected a memory leak of type 'DerivedClass *', no destructor found. ``` even though the destructor is defined in the base class.
1 parent fb0cddf commit 0da8a9b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%module abstract_basecast
2+
3+
%inline %{
4+
class BaseClass {
5+
public:
6+
virtual ~BaseClass() { }
7+
8+
virtual void g() = 0;
9+
};
10+
11+
class DerivedClass : public BaseClass {
12+
public:
13+
14+
virtual void g() { }
15+
16+
BaseClass& f() {
17+
return *this;
18+
}
19+
};
20+
%}

Examples/test-suite/common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ C_TEST_BROKEN += \
102102
# C++ test cases. (Can be run individually using: make testcase.cpptest)
103103
CPP_TEST_CASES += \
104104
abstract_access \
105+
abstract_basecast \
105106
abstract_inherit \
106107
abstract_inherit_ok \
107108
abstract_signature \
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from abstract_basecast import *
2+
3+
def check(flag):
4+
if not flag:
5+
raise RuntimeError("Test failed")
6+
7+
derived = DerivedClass()
8+
derived.g()
9+
check(isinstance(derived, BaseClass))
10+
check(isinstance(derived, DerivedClass))
11+
12+
base = derived.f()
13+
base.g()
14+
check(isinstance(base, BaseClass))
15+
check(not isinstance(base, DerivedClass))

0 commit comments

Comments
 (0)