Skip to content

Commit b90e3ae

Browse files
committed
C# directors override/virtual - additional testing
Add runtime test for scenario described in swig#1323. Expand testing to cover a mix of override/virtual method overloading. Remove testSwigDerivedClassHasMethod() test - not fixed yet.
1 parent e4a251f commit b90e3ae

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

Examples/test-suite/csharp/director_basic_runme.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,35 @@ void run()
4949
throw new Exception("non-null pointer marshalling problem");
5050
myNewBar.x = 10;
5151

52-
my.testSwigDerivedClassHasMethod();
52+
// Low level implementation check
53+
// my.testSwigDerivedClassHasMethod();
54+
55+
// These should not call the C# implementations as they are not overridden
56+
int v;
57+
v = MyClass.call_nonVirtual(my);
58+
if (v != 100) throw new Exception("call_nonVirtual broken() " + v);
59+
60+
v = MyClass.call_nonOverride(my);
61+
if (v != 101) throw new Exception("call_nonOverride broken() " + v);
62+
63+
// A mix of overridden and non-overridden
64+
MyClassEnd myend = new MyClassEnd();
65+
MyClass mc = myend;
66+
67+
v = mc.nonVirtual();
68+
if (v != 202) throw new Exception("mc.nonVirtual() broken " + v);
69+
70+
v = MyClass.call_nonVirtual(mc);
71+
if (v != 202) throw new Exception("call_nonVirtual(mc) broken " + v);
72+
73+
v = MyClass.call_nonVirtual(myend);
74+
if (v != 202) throw new Exception("call_nonVirtual(myend) broken" + v);
75+
76+
v = MyClass.call_nonOverride(mc);
77+
if (v != 101) throw new Exception("call_nonOverride(mc) broken" + v);
78+
79+
v = MyClass.call_nonOverride(myend);
80+
if (v != 101) throw new Exception("call_nonOverride(myend) broken" + v);
5381
}
5482
}
5583
}
@@ -81,4 +109,20 @@ public override Bar pmethod(Bar b) {
81109
}
82110
}
83111

112+
class MyClassMiddle : MyClass {
113+
public override int nonVirtual() {
114+
return 202;
115+
}
116+
}
117+
118+
class MyClassEnd : MyClassMiddle {
119+
public new bool nonVirtual() {
120+
throw new Exception("non-virtual overrides virtual method");
121+
}
122+
123+
public new virtual bool nonOverride() {
124+
throw new Exception("non-override overrides virtual method");
125+
}
126+
}
127+
84128
}

Examples/test-suite/director_basic.i

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,24 @@ public:
130130
return myclass->pmethod(b);
131131
}
132132

133-
virtual void nonVirtual()
133+
virtual int nonVirtual()
134134
{
135+
return 100;
135136
}
136137

137-
virtual void nonOverride()
138+
virtual int nonOverride()
138139
{
140+
return 101;
141+
}
142+
143+
static int call_nonVirtual(MyClass *myclass)
144+
{
145+
return myclass->nonVirtual();
146+
}
147+
148+
static int call_nonOverride(MyClass *myclass)
149+
{
150+
return myclass->nonOverride();
139151
}
140152

141153
// Collisions with generated method names

0 commit comments

Comments
 (0)