explicitcall tests
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
da0f95ec8f
commit
37005baff5
4 changed files with 262 additions and 0 deletions
73
Examples/test-suite/csharp/explicitcall_runme.cs
Normal file
73
Examples/test-suite/csharp/explicitcall_runme.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using explicitcallNamespace;
|
||||||
|
|
||||||
|
public class explicitcall_runme {
|
||||||
|
|
||||||
|
public static void Main() {
|
||||||
|
|
||||||
|
GrandChild gc = new GrandChild();
|
||||||
|
if (gc.talkPerson() != "Person")
|
||||||
|
throw new Exception("Explicit Person");
|
||||||
|
if (gc.talkChild() != "Child")
|
||||||
|
throw new Exception("Explicit Child");
|
||||||
|
if (gc.talkBambino() != "GrandChild")
|
||||||
|
throw new Exception("Explicit GrandChild");
|
||||||
|
|
||||||
|
if (gc.talk() != "GrandChild")
|
||||||
|
throw new Exception("virtual GrandChild");
|
||||||
|
|
||||||
|
{
|
||||||
|
Person p = null;
|
||||||
|
p = new Mother();
|
||||||
|
if (p.talk() != "Person")
|
||||||
|
throw new Exception("Mother");
|
||||||
|
|
||||||
|
p = new Daughter();
|
||||||
|
if (p.talk() != "Person:Child")
|
||||||
|
throw new Exception("Daughter");
|
||||||
|
|
||||||
|
p = new GrandDaughter();
|
||||||
|
if (p.talk() != "Person:Child:GrandChild")
|
||||||
|
throw new Exception("GrandDaughter");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TemplateString t = new TemplateString();
|
||||||
|
if (t.barTemplateString(0) != "Template")
|
||||||
|
throw new Exception("Template");
|
||||||
|
|
||||||
|
TDerived td = new TDerived();
|
||||||
|
|
||||||
|
if (td.barTDerived() != "TDerived")
|
||||||
|
throw new Exception("TDerived TDerived()");
|
||||||
|
if (td.barTemplateString() != "Template")
|
||||||
|
throw new Exception("TDerived Template()");
|
||||||
|
|
||||||
|
if (td.barTDerived(0) != "TDerived")
|
||||||
|
throw new Exception("TDerived TDerived(0)");
|
||||||
|
if (td.barTemplateString(0) != "Template")
|
||||||
|
throw new Exception("TDerived Template(0)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test classic usage of the %explicitcall - using base class method from derived class
|
||||||
|
class Mother : Person {
|
||||||
|
public override string talk() {
|
||||||
|
return talkPerson();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Daughter : Child {
|
||||||
|
public override string talk() {
|
||||||
|
return talkPerson() + ":" + talkChild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GrandDaughter : GrandChild {
|
||||||
|
public override string talk() {
|
||||||
|
return talkPerson() + ":" + talkChild() + ":" + talkBambino();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
49
Examples/test-suite/explicitcall.i
Normal file
49
Examples/test-suite/explicitcall.i
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
%module(directors="1") explicitcall
|
||||||
|
|
||||||
|
%include <std_string.i>
|
||||||
|
|
||||||
|
%director;
|
||||||
|
|
||||||
|
%explicitcall;
|
||||||
|
%feature("explicitcall", suffix="Bambino") Space::GrandChild::talk;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
namespace Space {
|
||||||
|
struct Person {
|
||||||
|
Person() {}
|
||||||
|
virtual std::string talk() { return "Person"; }
|
||||||
|
virtual ~Person() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Child : Person {
|
||||||
|
void nonvirtual() {}
|
||||||
|
virtual std::string talk () { return "Child"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GrandChild : Child {
|
||||||
|
virtual std::string talk() { return "GrandChild"; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
%cleardirector;
|
||||||
|
|
||||||
|
// a template and default parameters test
|
||||||
|
%inline %{
|
||||||
|
template<class T> class Template {
|
||||||
|
public:
|
||||||
|
virtual ~Template(){}
|
||||||
|
virtual T bar(const int &t = int(20)) const { return "Template"; }
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%template(TemplateString) Template<std::string>;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
struct TDerived : Template<std::string> {
|
||||||
|
virtual std::string bar(const int &t = int(20)) const { return "TDerived"; }
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
83
Examples/test-suite/java/explicitcall_runme.java
Normal file
83
Examples/test-suite/java/explicitcall_runme.java
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
// Mainly tests that directors are finalized correctly
|
||||||
|
|
||||||
|
import explicitcall.*;
|
||||||
|
|
||||||
|
public class explicitcall_runme {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("explicitcall");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String argv[]) {
|
||||||
|
|
||||||
|
GrandChild gc = new GrandChild();
|
||||||
|
if (!gc.talkPerson().equals("Person"))
|
||||||
|
throw new RuntimeException("Explicit Person");
|
||||||
|
if (!gc.talkChild().equals("Child"))
|
||||||
|
throw new RuntimeException("Explicit Child");
|
||||||
|
if (!gc.talkBambino().equals("GrandChild"))
|
||||||
|
throw new RuntimeException("Explicit GrandChild");
|
||||||
|
|
||||||
|
if (!gc.talk().equals("GrandChild"))
|
||||||
|
throw new RuntimeException("virtual GrandChild");
|
||||||
|
|
||||||
|
{
|
||||||
|
Person p = null;
|
||||||
|
p = new Mother();
|
||||||
|
if (!p.talk().equals("Person"))
|
||||||
|
throw new RuntimeException("Mother");
|
||||||
|
|
||||||
|
p = new Daughter();
|
||||||
|
if (!p.talk().equals("Person:Child"))
|
||||||
|
throw new RuntimeException("Daughter");
|
||||||
|
|
||||||
|
p = new GrandDaughter();
|
||||||
|
if (!p.talk().equals("Person:Child:GrandChild"))
|
||||||
|
throw new RuntimeException("GrandDaughter");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TemplateString t = new TemplateString();
|
||||||
|
if (!t.barTemplateString(0).equals("Template"))
|
||||||
|
throw new RuntimeException("Template");
|
||||||
|
|
||||||
|
TDerived td = new TDerived();
|
||||||
|
|
||||||
|
if (!td.barTDerived().equals("TDerived"))
|
||||||
|
throw new RuntimeException("TDerived TDerived()");
|
||||||
|
if (!td.barTemplateString().equals("Template"))
|
||||||
|
throw new RuntimeException("TDerived Template()");
|
||||||
|
|
||||||
|
if (!td.barTDerived(0).equals("TDerived"))
|
||||||
|
throw new RuntimeException("TDerived TDerived(0)");
|
||||||
|
if (!td.barTemplateString(0).equals("Template"))
|
||||||
|
throw new RuntimeException("TDerived Template(0)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test classic usage of the %explicitcall - using base class method from derived class
|
||||||
|
class Mother extends Person {
|
||||||
|
public String talk() {
|
||||||
|
return talkPerson();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Daughter extends Child {
|
||||||
|
public String talk() {
|
||||||
|
return talkPerson() + ":" + talkChild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GrandDaughter extends GrandChild {
|
||||||
|
public String talk() {
|
||||||
|
return talkPerson() + ":" + talkChild() + ":" + talkBambino();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
57
Examples/test-suite/python/explicitcall_runme.py
Normal file
57
Examples/test-suite/python/explicitcall_runme.py
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
from explicitcall import *
|
||||||
|
|
||||||
|
|
||||||
|
# Test classic usage of the %explicitcall - using base class method from derived class
|
||||||
|
class Mother(Person):
|
||||||
|
def talk(self):
|
||||||
|
return Person.talkPerson(self)
|
||||||
|
|
||||||
|
class Daughter(Child):
|
||||||
|
def talk(self):
|
||||||
|
return Person.talkPerson(self) + ":" + Child.talkChild(self)
|
||||||
|
|
||||||
|
class GrandDaughter(GrandChild):
|
||||||
|
def talk(self):
|
||||||
|
return Person.talkPerson(self) + ":" + Child.talkChild(self) + ":" + GrandChild.talkBambino(self)
|
||||||
|
|
||||||
|
|
||||||
|
gc = GrandChild()
|
||||||
|
if (gc.talkPerson() != "Person"):
|
||||||
|
raise RuntimeError, "Explicit Person"
|
||||||
|
if (gc.talkChild() != "Child"):
|
||||||
|
raise RuntimeError, "Explicit Child"
|
||||||
|
if (gc.talkBambino() != "GrandChild"):
|
||||||
|
raise RuntimeError, "Explicit GrandChild"
|
||||||
|
|
||||||
|
if (gc.talk() != "GrandChild"):
|
||||||
|
raise RuntimeError, "virtual GrandChild"
|
||||||
|
|
||||||
|
|
||||||
|
p = Mother()
|
||||||
|
if (p.talk() != "Person"):
|
||||||
|
raise RuntimeError, "Mother"
|
||||||
|
|
||||||
|
p = Daughter()
|
||||||
|
if (p.talk() != "Person:Child"):
|
||||||
|
raise RuntimeError, "Daughter"
|
||||||
|
|
||||||
|
p = GrandDaughter()
|
||||||
|
if (p.talk() != "Person:Child:GrandChild"):
|
||||||
|
raise RuntimeError, "GrandDaughter"
|
||||||
|
|
||||||
|
t = TemplateString()
|
||||||
|
if (t.barTemplateString(0) != "Template"):
|
||||||
|
raise RuntimeError, "Template"
|
||||||
|
|
||||||
|
td = TDerived()
|
||||||
|
|
||||||
|
if (td.barTDerived() != "TDerived"):
|
||||||
|
raise RuntimeError, "TDerived TDerived()"
|
||||||
|
if (td.barTemplateString() != "Template"):
|
||||||
|
raise RuntimeError, "TDerived Template()"
|
||||||
|
|
||||||
|
if (td.barTDerived(0) != "TDerived"):
|
||||||
|
raise RuntimeError, "TDerived TDerived(0)"
|
||||||
|
if (td.barTemplateString(0) != "Template"):
|
||||||
|
raise RuntimeError, "TDerived Template(0)"
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue