diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2014-12-19 19:35:38 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2014-12-19 19:35:38 +0000 |
commit | 68a936a63865eced4f9029c28d4fa7a13b538e0e (patch) | |
tree | e5e7bf9d797d5328d98620480a7a9bd9d4083dd3 /Examples | |
parent | 70a04c9ffe172c5449f1c5b9421c2b4bd6cf29df (diff) | |
download | swig-68a936a63865eced4f9029c28d4fa7a13b538e0e.tar.gz |
Add testcase for nested inner class deriving from a templated base class and defined outside of the outer class.
For languages that don't support nested class support, use flatnested.
See issue #270
Diffstat (limited to 'Examples')
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/java/nested_template_base_runme.java | 27 | ||||
-rw-r--r-- | Examples/test-suite/nested_template_base.i | 38 | ||||
-rw-r--r-- | Examples/test-suite/python/nested_template_base_runme.py | 13 |
4 files changed, 79 insertions, 0 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 314894598..ac2dfd4dd 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -299,6 +299,7 @@ CPP_TEST_CASES += \ nested_directors \ nested_comment \ nested_scope \ + nested_template_base \ nested_workaround \ newobject1 \ null_pointer \ diff --git a/Examples/test-suite/java/nested_template_base_runme.java b/Examples/test-suite/java/nested_template_base_runme.java new file mode 100644 index 000000000..8404afe04 --- /dev/null +++ b/Examples/test-suite/java/nested_template_base_runme.java @@ -0,0 +1,27 @@ +import nested_template_base.*; + +public class nested_template_base_runme { + + static { + try { + System.loadLibrary("nested_template_base"); + } 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[]) { + OuterC.InnerS ois = new OuterC.InnerS(123); + OuterC.InnerC oic = new OuterC.InnerC(); + + // Check base method is available + if (oic.outer(ois).getVal() != 123) + throw new RuntimeException("Wrong value calling outer"); + + // Check non-derived class using base class + if (oic.innerc().outer(ois).getVal() != 123) + throw new RuntimeException("Wrong value calling innerc"); + + } +} diff --git a/Examples/test-suite/nested_template_base.i b/Examples/test-suite/nested_template_base.i new file mode 100644 index 000000000..65cc715fa --- /dev/null +++ b/Examples/test-suite/nested_template_base.i @@ -0,0 +1,38 @@ +%module nested_template_base + +%inline %{ + template <class T> class OuterT { + public: + T outer(T t) { return t; } + }; +%} + +// The %template goes after OuterT and before OuterC as OuterC::InnerC's base is handled inside OuterC +%template(OuterTInnerS) OuterT<OuterC::InnerS>; + +#if !defined(SWIGCSHARP) && !defined(SWIGJAVA) +%feature("flatnested") OuterC::InnerS; +%feature("flatnested") OuterC::InnerC; +#endif + + +%inline %{ + class OuterC { + public: + class InnerS; + class InnerC; + }; + + struct OuterC::InnerS { + int val; + InnerS(int val = 0) : val(val) {} + }; + + + class OuterC::InnerC : public OuterT<InnerS> { + public: + OuterT<InnerS>& innerc() { + return *this; + } + }; +%} diff --git a/Examples/test-suite/python/nested_template_base_runme.py b/Examples/test-suite/python/nested_template_base_runme.py new file mode 100644 index 000000000..3d54b8391 --- /dev/null +++ b/Examples/test-suite/python/nested_template_base_runme.py @@ -0,0 +1,13 @@ +from nested_template_base import * + + +ois = InnerS(123); +oic = InnerC(); + +# Check base method is available +if (oic.outer(ois).val != 123): + raise RuntimeError("Wrong value calling outer"); + +# Check non-derived class using base class +if (oic.innerc().outer(ois).val != 123): + raise RuntimeError("Wrong value calling innerc"); |