From cfcafc807a435c6c9afccda2cc5ef8d99cded9d6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 Mar 2010 18:37:05 +0000 Subject: [PATCH] Add java run test for nspace test and extend the test a bit git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11899 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/nspace_runme.java | 64 ++++++++++++++++++++++ Examples/test-suite/nspace.i | 14 ++++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Examples/test-suite/java/nspace_runme.java diff --git a/Examples/test-suite/java/nspace_runme.java b/Examples/test-suite/java/nspace_runme.java new file mode 100644 index 000000000..ca83b7d04 --- /dev/null +++ b/Examples/test-suite/java/nspace_runme.java @@ -0,0 +1,64 @@ +// 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_runme { + + static { + try { + System.loadLibrary("nspace"); + } 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 + nspacePackage.Outer.Inner1.Color color1 = new nspacePackage.Outer.Inner1.Color(); + nspacePackage.Outer.Inner1.Color color = new nspacePackage.Outer.Inner1.Color(color1); + color1.delete(); + color1 = null; + + // class methods + color.colorInstanceMethod(20.0); + nspacePackage.Outer.Inner1.Color.colorStaticMethod(20.0); + nspacePackage.Outer.Inner1.Color created = nspacePackage.Outer.Inner1.Color.create(); + + // class enums + nspacePackage.Outer.SomeClass someClass = new nspacePackage.Outer.SomeClass(); + nspacePackage.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel(); + if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission) + throw new RuntimeException("Transmission wrong"); + + // static member variables + nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789); + if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789) + throw new RuntimeException("static member variable failed"); + + // instance member variables + color.setInstanceMemberVariable(123); + if (color.getInstanceMemberVariable() != 123) + throw new RuntimeException("instance member variable failed"); + + // Same class different namespaces + nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color(); + nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create(); + col2.colors(col1, col1, col2, col2, col2); + + // check globals in a namespace don't get mangled with the nspacePackage option + nspacePackage.nspace.namespaceFunction(color); + nspacePackage.nspace.setNamespaceVar(111); + if (nspacePackage.nspace.getNamespaceVar() != 111) + throw new RuntimeException("global var failed"); + + // global enums + nspacePackage.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel(); + if (outerChannel1 != nspacePackage.Outer.Inner1.Channel.Transmission1) + throw new RuntimeException("Transmission1 wrong"); + nspacePackage.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel(); + if (outerChannel2 != nspacePackage.Outer.Inner2.Channel.Transmission2) + throw new RuntimeException("Transmission2 wrong"); + + // turn feature off / ignoring + nspacePackage.Outer.nspace ns = new nspacePackage.Outer.nspace(); + nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease(); + } +} diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i index 26a3273b2..eb63f342d 100644 --- a/Examples/test-suite/nspace.i +++ b/Examples/test-suite/nspace.i @@ -4,9 +4,13 @@ #if defined(SWIGJAVA) SWIG_JAVABODY_METHODS(public, public, SWIGTYPE) %pragma(java) jniclassclassmodifiers = "public class" +#endif -%feature("nspace"); -%feature("nspace", "0") Outer::Inner2::NoNSpacePlease; +// nspace feature only supported by these languages +#if defined(SWIGJAVA) || defined(SWIGCSHARP) + +%nspace; +%nonspace Outer::Inner2::NoNSpacePlease; %copyctor; %ignore Outer::Inner2::Color::Color(); @@ -64,6 +68,11 @@ namespace Outer { static int staticMemberVariable; 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) {} }; // Color int Color::staticMemberVariable = 0; class NoNSpacePlease {}; @@ -91,3 +100,4 @@ void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {} %} #endif +