Fix director typemaps for pointers so that NULL pointers are correctly marshalled to C#/Java null in director methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10662 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b2cea3c42a
commit
4887e7be7c
6 changed files with 127 additions and 20 deletions
74
Examples/test-suite/csharp/director_basic_runme.cs
Normal file
74
Examples/test-suite/csharp/director_basic_runme.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
|
||||
namespace director_basicNamespace {
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
runme r = new runme();
|
||||
r.run();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
director_basic_MyFoo a = new director_basic_MyFoo();
|
||||
|
||||
if (a.ping() != "director_basic_MyFoo::ping()") {
|
||||
throw new Exception ( "a.ping()" );
|
||||
}
|
||||
|
||||
if (a.pong() != "Foo::pong();director_basic_MyFoo::ping()") {
|
||||
throw new Exception ( "a.pong()" );
|
||||
}
|
||||
|
||||
Foo b = new Foo();
|
||||
|
||||
if (b.ping() != "Foo::ping()") {
|
||||
throw new Exception ( "b.ping()" );
|
||||
}
|
||||
|
||||
if (b.pong() != "Foo::pong();Foo::ping()") {
|
||||
throw new Exception ( "b.pong()" );
|
||||
}
|
||||
|
||||
A1 a1 = new A1(1, false);
|
||||
a1.Dispose();
|
||||
|
||||
{
|
||||
MyOverriddenClass my = new MyOverriddenClass();
|
||||
|
||||
my.expectNull = true;
|
||||
if (MyClass.call_pmethod(my, null) != null)
|
||||
throw new Exception("null pointer marshalling problem");
|
||||
|
||||
Bar myBar = new Bar();
|
||||
my.expectNull = false;
|
||||
Bar myNewBar = MyClass.call_pmethod(my, myBar);
|
||||
if (myNewBar == null)
|
||||
throw new Exception("non-null pointer marshalling problem");
|
||||
myNewBar.x = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class director_basic_MyFoo : Foo {
|
||||
public director_basic_MyFoo() : base() {
|
||||
}
|
||||
|
||||
public override string ping() {
|
||||
return "director_basic_MyFoo::ping()";
|
||||
}
|
||||
}
|
||||
|
||||
class MyOverriddenClass : MyClass {
|
||||
public bool expectNull = false;
|
||||
public bool nonNullReceived = false;
|
||||
public override Bar pmethod(Bar b) {
|
||||
if ( expectNull && (b != null) )
|
||||
throw new Exception("null not received as expected");
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -112,12 +112,14 @@ public:
|
|||
return vmethod(b);
|
||||
}
|
||||
|
||||
|
||||
static MyClass *get_self(MyClass *c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
static Bar * call_pmethod(MyClass *myclass, Bar *b) {
|
||||
return myclass->pmethod(b);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
|||
|
|
@ -14,28 +14,43 @@ public class director_basic_runme {
|
|||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
director_basic_MyFoo a = new director_basic_MyFoo();
|
||||
director_basic_MyFoo a = new director_basic_MyFoo();
|
||||
|
||||
if (!a.ping().equals("director_basic_MyFoo::ping()")) {
|
||||
throw new RuntimeException ( "a.ping()" );
|
||||
}
|
||||
if (!a.ping().equals("director_basic_MyFoo::ping()")) {
|
||||
throw new RuntimeException ( "a.ping()" );
|
||||
}
|
||||
|
||||
if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) {
|
||||
throw new RuntimeException ( "a.pong()" );
|
||||
}
|
||||
if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) {
|
||||
throw new RuntimeException ( "a.pong()" );
|
||||
}
|
||||
|
||||
Foo b = new Foo();
|
||||
Foo b = new Foo();
|
||||
|
||||
if (!b.ping().equals("Foo::ping()")) {
|
||||
throw new RuntimeException ( "b.ping()" );
|
||||
}
|
||||
if (!b.ping().equals("Foo::ping()")) {
|
||||
throw new RuntimeException ( "b.ping()" );
|
||||
}
|
||||
|
||||
if (!b.pong().equals("Foo::pong();Foo::ping()")) {
|
||||
throw new RuntimeException ( "b.pong()" );
|
||||
}
|
||||
if (!b.pong().equals("Foo::pong();Foo::ping()")) {
|
||||
throw new RuntimeException ( "b.pong()" );
|
||||
}
|
||||
|
||||
A1 a1 = new A1(1, false);
|
||||
a1.delete();
|
||||
A1 a1 = new A1(1, false);
|
||||
a1.delete();
|
||||
|
||||
{
|
||||
MyOverriddenClass my = new MyOverriddenClass();
|
||||
|
||||
my.expectNull = true;
|
||||
if (MyClass.call_pmethod(my, null) != null)
|
||||
throw new RuntimeException("null pointer marshalling problem");
|
||||
|
||||
Bar myBar = new Bar();
|
||||
my.expectNull = false;
|
||||
Bar myNewBar = MyClass.call_pmethod(my, myBar);
|
||||
if (myNewBar == null)
|
||||
throw new RuntimeException("non-null pointer marshalling problem");
|
||||
myNewBar.setX(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,3 +60,13 @@ class director_basic_MyFoo extends Foo {
|
|||
}
|
||||
}
|
||||
|
||||
class MyOverriddenClass extends MyClass {
|
||||
public boolean expectNull = false;
|
||||
public boolean nonNullReceived = false;
|
||||
public Bar pmethod(Bar b) {
|
||||
if ( expectNull && (b != null) )
|
||||
throw new RuntimeException("null not received as expected");
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue