From deafe98dc4d4fc1b0683f950cfffeb2ea519f45b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 8 Mar 2010 23:02:53 +0000 Subject: [PATCH] Test %extend and nspace feature git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11929 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/common.mk | 1 + .../test-suite/csharp/nspace_extend_runme.cs | 39 +++++++++++++++ Examples/test-suite/java/Makefile.in | 1 + .../test-suite/java/nspace_extend_runme.java | 44 ++++++++++++++++ Examples/test-suite/nspace_extend.i | 50 +++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 Examples/test-suite/csharp/nspace_extend_runme.cs create mode 100644 Examples/test-suite/java/nspace_extend_runme.java create mode 100644 Examples/test-suite/nspace_extend.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 2b4ab0701..db162487f 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -243,6 +243,7 @@ CPP_TEST_CASES += \ namespace_union \ namespace_virtual_method \ nspace \ + nspace_extend \ naturalvar \ nested_class \ nested_comment \ diff --git a/Examples/test-suite/csharp/nspace_extend_runme.cs b/Examples/test-suite/csharp/nspace_extend_runme.cs new file mode 100644 index 000000000..addee7fe5 --- /dev/null +++ b/Examples/test-suite/csharp/nspace_extend_runme.cs @@ -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); + } + } +} diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 119b50868..3cb7c0c53 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -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: diff --git a/Examples/test-suite/java/nspace_extend_runme.java b/Examples/test-suite/java/nspace_extend_runme.java new file mode 100644 index 000000000..3e44673d1 --- /dev/null +++ b/Examples/test-suite/java/nspace_extend_runme.java @@ -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); + } + } +} diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i new file mode 100644 index 000000000..7f7ba01f8 --- /dev/null +++ b/Examples/test-suite/nspace_extend.i @@ -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) {} +} +