diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2017-01-13 20:42:12 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2017-01-13 20:43:50 +0000 |
commit | 3d2e57b0f2cd08e2856be53e98a164f891c8903c (patch) | |
tree | d372733d53658728a0eaf2305ca7ed902a1c879d /Examples/test-suite | |
parent | 88e2d02eadf1f0c6a27077461e19c69c2dc2ec16 (diff) | |
download | swig-3d2e57b0f2cd08e2856be53e98a164f891c8903c.tar.gz |
Add %proxycode directive for adding code into proxy classes for C#, D and Java
Diffstat (limited to 'Examples/test-suite')
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/csharp/proxycode_runme.cs | 33 | ||||
-rw-r--r-- | Examples/test-suite/d/proxycode_runme.2.d | 41 | ||||
-rw-r--r-- | Examples/test-suite/java/proxycode_runme.java | 42 | ||||
-rw-r--r-- | Examples/test-suite/proxycode.i | 141 |
5 files changed, 258 insertions, 0 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index e3881afd6..fb5aaa597 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -335,6 +335,7 @@ CPP_TEST_CASES += \ preproc_constants \ primitive_ref \ private_assign \ + proxycode \ protected_rename \ pure_virtual \ redefined \ diff --git a/Examples/test-suite/csharp/proxycode_runme.cs b/Examples/test-suite/csharp/proxycode_runme.cs new file mode 100644 index 000000000..24e76c0c6 --- /dev/null +++ b/Examples/test-suite/csharp/proxycode_runme.cs @@ -0,0 +1,33 @@ +using System; +using proxycodeNamespace; + +public class proxycode_runme { + + public static void Main() { + if (new Proxy1().proxycode1(100) != 101) + throw new Exception("Fail"); + if (new Proxy2().proxycode2a(100) != 102) + throw new Exception("Fail"); + if (new Proxy2().proxycode2b(100) != 102) + throw new Exception("Fail"); + if (new Proxy3().proxycode3(100) != 103) + throw new Exception("Fail"); + + if (new Proxy4().proxycode4(100) != 104) + throw new Exception("Fail"); + if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144) + throw new Exception("Fail"); + + if (new Proxy5a().proxycode5((short)100) != (short)100) + throw new Exception("Fail"); + if (new Proxy5b().proxycode5(100) != 100) + throw new Exception("Fail"); + if (new Proxy5b().proxycode5(100, 100) != 255) + throw new Exception("Fail"); + + uint t1 = 10; + uint t2 = 100; + Proxy6 p = new Proxy6().proxyUseT(t1, t2); + p.useT(t1, t2); + } +} diff --git a/Examples/test-suite/d/proxycode_runme.2.d b/Examples/test-suite/d/proxycode_runme.2.d new file mode 100644 index 000000000..133217f2e --- /dev/null +++ b/Examples/test-suite/d/proxycode_runme.2.d @@ -0,0 +1,41 @@ +module proxycode_runme; + +import std.exception; +import proxycode.Proxy1; +import proxycode.Proxy2; +import proxycode.Proxy3; +import proxycode.Proxy4; +import proxycode.Proxy5a; +import proxycode.Proxy5b; +import proxycode.Proxy6; + +void main() { + if (new Proxy1().proxycode1(100) != 101) + throw new Exception("Fail"); + + if (new Proxy1().proxycode1(100) != 101) + throw new Exception("Fail"); + if (new Proxy2().proxycode2a(100) != 102) + throw new Exception("Fail"); + if (new Proxy2().proxycode2b(100) != 102) + throw new Exception("Fail"); + if (new Proxy3().proxycode3(100) != 103) + throw new Exception("Fail"); + + if (new Proxy4().proxycode4(100) != 104) + throw new Exception("Fail"); +// if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144) +// throw new Exception("Fail"); + + if (new Proxy5a().proxycode5(100) != 100) + throw new Exception("Fail"); + if (new Proxy5b().proxycode5(100) != 100) + throw new Exception("Fail"); + if (new Proxy5b().proxycode5(100, 100) != 255) + throw new Exception("Fail"); + + uint t1 = 10; + uint t2 = 100; + Proxy6 p = new Proxy6().proxyUseT(t1, t2); + p.useT(t1, t2); +} diff --git a/Examples/test-suite/java/proxycode_runme.java b/Examples/test-suite/java/proxycode_runme.java new file mode 100644 index 000000000..cf981e723 --- /dev/null +++ b/Examples/test-suite/java/proxycode_runme.java @@ -0,0 +1,42 @@ +import proxycode.*; + +public class proxycode_runme { + + static { + try { + System.loadLibrary("proxycode"); + } 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[]) throws Throwable + { + if (new Proxy1().proxycode1(100) != 101) + throw new RuntimeException("Fail"); + if (new Proxy2().proxycode2a(100) != 102) + throw new RuntimeException("Fail"); + if (new Proxy2().proxycode2b(100) != 102) + throw new RuntimeException("Fail"); + if (new Proxy3().proxycode3(100) != 103) + throw new RuntimeException("Fail"); + + if (new Proxy4().proxycode4(100) != 104) + throw new RuntimeException("Fail"); + if (new Proxy4.Proxy4Nested().proxycode4nested(100) != 144) + throw new RuntimeException("Fail"); + + if (new Proxy5a().proxycode5((short)100) != (short)100) + throw new RuntimeException("Fail"); + if (new Proxy5b().proxycode5(100) != 100) + throw new RuntimeException("Fail"); + if (new Proxy5b().proxycode5(100, 100) != 255) + throw new RuntimeException("Fail"); + + long t1 = 10; + long t2 = 100; + Proxy6 p = new Proxy6().proxyUseT(t1, t2); + p.useT(t1, t2); + } +} diff --git a/Examples/test-suite/proxycode.i b/Examples/test-suite/proxycode.i new file mode 100644 index 000000000..02dab9ade --- /dev/null +++ b/Examples/test-suite/proxycode.i @@ -0,0 +1,141 @@ +%module proxycode + +%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Proxy4::Proxy4Nested; + +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) + +%{ +struct Proxy1 {}; +%} +struct Proxy1 { +%proxycode %{ + public int proxycode1(int i) { + return i+1; + } +%} +}; + +%proxycode %{ + this should be ignored as it is not in scope of a class +%} + +%extend Proxy2 { +%proxycode %{ + public int proxycode2a(int i) { + return i+2; + } +%} +} + +%extend Proxy2 { +%proxycode %{ + public int proxycode2b(int i) { + return i+2; + } +%} +} + +%inline %{ +struct Proxy2 {}; +struct Proxy3 {}; +struct Proxy4 { + struct Proxy4Nested {}; +}; +%} + +%extend Proxy3 { +%proxycode %{ + public int proxycode3(int i) { + return i+3; + } +%} +} + +%extend Proxy4 { +%proxycode %{ + public int proxycode4(int i) { + return i+4; + } +%} +} +%extend Proxy4::Proxy4Nested { +%proxycode %{ + public int proxycode4nested(int i) { + return i+44; + } +%} +} + +%extend TemplateProxy { +%proxycode %{ + public T proxycode5(T i) { + return i; + } +%} +} + +%extend TemplateProxy<int> { +%proxycode %{ + public int proxycode5(int i, int j) { + return i+j+55; + } +%} +} + +%inline %{ +template <typename T> struct TemplateProxy {}; +%} + +%template(Proxy5a) TemplateProxy<short>; +%template(Proxy5b) TemplateProxy<int>; + +%inline %{ +template <typename T> struct TypemapProxy { + T useT(T t1, T const& t2) { + return t1+t2; + } +}; +%} + +%extend TypemapProxy { +#if defined(SWIGJAVA) +%proxycode %{ + public $javaclassname proxyUseT(long t1, long t2) { + $typemap(jstype, unsigned int) tt1 = t1; + $typemap(jstype, unsigned int const&) tt2 = t2; + long ret = useT(tt1, tt2); + if (ret != t1+t2) + throw new RuntimeException("wrong sum"); + return this; + } +%} +#elif defined(SWIGCSHARP) +%proxycode %{ + public $csclassname proxyUseT(uint t1, uint t2) { + $typemap(cstype, unsigned int) tt1 = t1; + $typemap(cstype, unsigned int const&) tt2 = t2; + uint ret = useT(tt1, tt2); + if (ret != t1+t2) + throw new System.Exception("wrong sum"); + return this; + } +%} +#elif defined(SWIGD) +%proxycode %{ + public $dclassname proxyUseT(uint t1, uint t2) { + $typemap(dtype, unsigned int) tt1 = t1; + $typemap(dtype, unsigned int const&) tt2 = t2; + uint ret = useT(tt1, tt2); + if (ret != t1+t2) + throw new Exception("wrong sum"); + return this; + } +%} +#else +#error "missing test" +#endif +} + +%template(Proxy6) TypemapProxy<unsigned int>; + +#endif |