mirror of https://github.com/swig/swig
Test %extend and nspace feature
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11929 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9dd30264f6
commit
deafe98dc4
|
@ -243,6 +243,7 @@ CPP_TEST_CASES += \
|
|||
namespace_union \
|
||||
namespace_virtual_method \
|
||||
nspace \
|
||||
nspace_extend \
|
||||
naturalvar \
|
||||
nested_class \
|
||||
nested_comment \
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
{
|
||||
// constructors and destructors
|
||||
nspace_extendNamespace.Outer.Inner1.Color color1 = new nspace_extendNamespace.Outer.Inner1.Color();
|
||||
nspace_extendNamespace.Outer.Inner1.Color color = new nspace_extendNamespace.Outer.Inner1.Color(color1);
|
||||
color1.Dispose();
|
||||
color1 = null;
|
||||
|
||||
// class methods
|
||||
color.colorInstanceMethod(20.0);
|
||||
nspace_extendNamespace.Outer.Inner1.Color.colorStaticMethod(20.0);
|
||||
nspace_extendNamespace.Outer.Inner1.Color created = nspace_extendNamespace.Outer.Inner1.Color.create();
|
||||
created.Dispose();
|
||||
}
|
||||
{
|
||||
// constructors and destructors
|
||||
nspace_extendNamespace.Outer.Inner2.Color color2 = new nspace_extendNamespace.Outer.Inner2.Color();
|
||||
nspace_extendNamespace.Outer.Inner2.Color color = new nspace_extendNamespace.Outer.Inner2.Color(color2);
|
||||
color2.Dispose();
|
||||
color2 = null;
|
||||
|
||||
// class methods
|
||||
color.colorInstanceMethod(20.0);
|
||||
nspace_extendNamespace.Outer.Inner2.Color.colorStaticMethod(20.0);
|
||||
nspace_extendNamespace.Outer.Inner2.Color created = nspace_extendNamespace.Outer.Inner2.Color.create();
|
||||
created.Dispose();
|
||||
|
||||
// Same class different namespaces
|
||||
nspace_extendNamespace.Outer.Inner1.Color col1 = new nspace_extendNamespace.Outer.Inner1.Color();
|
||||
nspace_extendNamespace.Outer.Inner2.Color col2 = nspace_extendNamespace.Outer.Inner2.Color.create();
|
||||
col2.colors(col1, col1, col2, col2, col2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ INTERFACEDIR = ../../
|
|||
|
||||
# Custom tests - tests with additional commandline options
|
||||
nspace.%: JAVA_PACKAGE = $*Package
|
||||
nspace_extend.%: JAVA_PACKAGE = $*Package
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name
|
||||
public class nspace_extend_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("nspace_extend");
|
||||
} 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[]) {
|
||||
{
|
||||
// constructors and destructors
|
||||
nspace_extendPackage.Outer.Inner1.Color color1 = new nspace_extendPackage.Outer.Inner1.Color();
|
||||
nspace_extendPackage.Outer.Inner1.Color color = new nspace_extendPackage.Outer.Inner1.Color(color1);
|
||||
color1.delete();
|
||||
color1 = null;
|
||||
|
||||
// class methods
|
||||
color.colorInstanceMethod(20.0);
|
||||
nspace_extendPackage.Outer.Inner1.Color.colorStaticMethod(20.0);
|
||||
nspace_extendPackage.Outer.Inner1.Color created = nspace_extendPackage.Outer.Inner1.Color.create();
|
||||
}
|
||||
{
|
||||
// constructors and destructors
|
||||
nspace_extendPackage.Outer.Inner2.Color color2 = new nspace_extendPackage.Outer.Inner2.Color();
|
||||
nspace_extendPackage.Outer.Inner2.Color color = new nspace_extendPackage.Outer.Inner2.Color(color2);
|
||||
color2.delete();
|
||||
color2 = null;
|
||||
|
||||
// class methods
|
||||
color.colorInstanceMethod(20.0);
|
||||
nspace_extendPackage.Outer.Inner2.Color.colorStaticMethod(20.0);
|
||||
nspace_extendPackage.Outer.Inner2.Color created = nspace_extendPackage.Outer.Inner2.Color.create();
|
||||
|
||||
// Same class different namespaces
|
||||
nspace_extendPackage.Outer.Inner1.Color col1 = new nspace_extendPackage.Outer.Inner1.Color();
|
||||
nspace_extendPackage.Outer.Inner2.Color col2 = nspace_extendPackage.Outer.Inner2.Color.create();
|
||||
col2.colors(col1, col1, col2, col2, col2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// Test the nspace feature and %extend
|
||||
%module nspace_extend
|
||||
|
||||
// nspace feature only supported by these languages
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
|
||||
%nspace;
|
||||
|
||||
%extend Outer::Inner1::Color {
|
||||
Color() { return new Outer::Inner1::Color(); }
|
||||
virtual ~Color() { delete $self; }
|
||||
static Color* create() { return new Outer::Inner1::Color(); }
|
||||
Color(const Color& other) { return new Outer::Inner1::Color(other); }
|
||||
|
||||
void colorInstanceMethod(double d) {}
|
||||
static void colorStaticMethod(double d) {}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
namespace Outer {
|
||||
namespace Inner1 {
|
||||
struct Color {
|
||||
};
|
||||
}
|
||||
|
||||
namespace Inner2 {
|
||||
struct Color {
|
||||
};
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
#endif
|
||||
|
||||
%extend Outer::Inner2::Color {
|
||||
Color() { return new Outer::Inner2::Color(); }
|
||||
~Color() { delete $self; }
|
||||
static Color* create() { return new Outer::Inner2::Color(); }
|
||||
Color(const Color& other) { return new Outer::Inner2::Color(other); }
|
||||
|
||||
void colorInstanceMethod(double d) {}
|
||||
static void colorStaticMethod(double d) {}
|
||||
void colors(const Inner1::Color& col1a,
|
||||
const Outer::Inner1::Color& col1b,
|
||||
const Color &col2a,
|
||||
const Inner2::Color& col2b,
|
||||
const Outer::Inner2::Color& col2c) {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue