Skip to content

Commit e36e898

Browse files
authored
Merge pull request swig#2205 from swig-fortran/extend-tests
Fix and add additional tests to test suite
2 parents 7f37bfe + 0268dde commit e36e898

30 files changed

+221
-13
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/callback.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
%callback("%s") A::foom;
1414
#endif
1515
%callback("%(uppercase)s_Cb_Ptr") foo_T; // this works in Python too
16+
%callback("%s_cb") identity_finger;
1617

1718
%inline %{
1819

@@ -85,6 +86,15 @@
8586
const T& ident(const T& x) {
8687
return x;
8788
}
89+
90+
// Test callbacks for enum types
91+
typedef enum {One, Two, Three, Four, Five} finger;
92+
typedef finger (*finger_finger)(finger);
93+
finger identity_finger(finger f) { return f; }
94+
finger apply_finger_cb(finger f, finger_finger cb) {
95+
return cb(f);
96+
}
97+
8898
%}
8999

90100
%template(foo_i) foo_T<int>;

Examples/test-suite/class_scope_namespace.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Space1 {
1515
void aaa(Space1::SubSpace1::A, SubSpace1::A, A) {}
1616
}
1717
}
18+
void global_namespace_a(A*) {}
1819

1920
namespace Space2 {
2021
struct B;

Examples/test-suite/clientdata_prop_a.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class A {
66

77
typedef A tA;
88

9-
void test_A(A *a) {}
10-
void test_tA(tA *a) {}
9+
inline void test_A(A *a) {}
10+
inline void test_tA(tA *a) {}
1111

12-
tA *new_tA() { return new tA(); }
12+
inline tA *new_tA() { return new tA(); }

Examples/test-suite/common.mk

Lines changed: 3 additions & 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 \
@@ -213,6 +214,7 @@ CPP_TEST_CASES += \
213214
director_protected_overloaded \
214215
director_redefined \
215216
director_ref \
217+
director_simple \
216218
director_smartptr \
217219
director_thread \
218220
director_unroll \
@@ -696,6 +698,7 @@ C_TEST_CASES += \
696698
command_line_define \
697699
const_const \
698700
constant_expr_c \
701+
contract_c \
699702
default_args_c \
700703
empty_c \
701704
enums \

Examples/test-suite/contract.i

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int test_prepost(int x, int y) {
4848
}
4949
%}
5050

51+
#ifdef __cplusplus
5152
/* Class tests */
5253

5354
%contract Foo::test_preassert(int x, int y) {
@@ -235,4 +236,4 @@ class myClass
235236
};
236237

237238
}
238-
239+
#endif

Examples/test-suite/contract_c.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%module contract_c;
2+
3+
%include <exception.i>
4+
5+
%include "contract.i"

Examples/test-suite/cpp_basic.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class FooSubSub : public FooSub {
4545
const char* __str__() const { return "FooSubSub"; }
4646
};
4747

48+
Foo& get_reference(Foo& other) { return other; }
49+
const Foo& get_const_reference(const Foo& other) { return other; }
50+
4851
%}
4952

5053
%{

Examples/test-suite/director_binary_string.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
%inline %{
1010
#include <stdlib.h>
11+
#include <string.h>
1112

1213
#define BUFFER_SIZE_AA 8
1314
#define BUFFER_SIZE_BB 5

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)