From dcc591183979a502decc4d2bfad09fd5ebeb8cd7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 17 Mar 2017 07:49:21 +0000 Subject: Fix handling of typedef'd function pointers for Go Add equivalent runtime tests for Python and Java --- Examples/test-suite/go/typedef_funcptr_runme.go | 29 ++++++++++++++++++ .../test-suite/java/typedef_funcptr_runme.java | 34 ++++++++++++++++++++++ .../test-suite/python/typedef_funcptr_runme.py | 20 +++++++++++++ Examples/test-suite/typedef_funcptr.i | 10 +++++++ 4 files changed, 93 insertions(+) create mode 100644 Examples/test-suite/go/typedef_funcptr_runme.go create mode 100644 Examples/test-suite/java/typedef_funcptr_runme.java create mode 100644 Examples/test-suite/python/typedef_funcptr_runme.py (limited to 'Examples') diff --git a/Examples/test-suite/go/typedef_funcptr_runme.go b/Examples/test-suite/go/typedef_funcptr_runme.go new file mode 100644 index 000000000..49d7086b1 --- /dev/null +++ b/Examples/test-suite/go/typedef_funcptr_runme.go @@ -0,0 +1,29 @@ +package main + +import . "./typedef_funcptr" + +func main() { + a := 100 + b := 10 + + if Do_op(a,b,Addf) != 110 { + panic(0) + } + if Do_op(a,b,Subf) != 90 { + panic(0) + } + + if Do_op_typedef_int(a,b,Addf) != 110 { + panic(0) + } + if Do_op_typedef_int(a,b,Subf) != 90 { + panic(0) + } + + if Do_op_typedef_Integer(a,b,Addf) != 110 { + panic(0) + } + if Do_op_typedef_Integer(a,b,Subf) != 90 { + panic(0) + } +} diff --git a/Examples/test-suite/java/typedef_funcptr_runme.java b/Examples/test-suite/java/typedef_funcptr_runme.java new file mode 100644 index 000000000..0dd44cecd --- /dev/null +++ b/Examples/test-suite/java/typedef_funcptr_runme.java @@ -0,0 +1,34 @@ + +import typedef_funcptr.*; + +public class typedef_funcptr_runme { + + static { + try { + System.loadLibrary("typedef_funcptr"); + } 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[]) { + int a = 100; + int b = 10; + + if (typedef_funcptr.do_op(a,b,typedef_funcptr.addf) != 110) + throw new RuntimeException("addf failed"); + if (typedef_funcptr.do_op(a,b,typedef_funcptr.subf) != 90) + throw new RuntimeException("subf failed"); + + if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.addf) != 110) + throw new RuntimeException("addf failed"); + if (typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.subf) != 90) + throw new RuntimeException("subf failed"); + + if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.addf) != 110) + throw new RuntimeException("addf failed"); + if (typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.subf) != 90) + throw new RuntimeException("subf failed"); + } +} diff --git a/Examples/test-suite/python/typedef_funcptr_runme.py b/Examples/test-suite/python/typedef_funcptr_runme.py new file mode 100644 index 000000000..a186963f7 --- /dev/null +++ b/Examples/test-suite/python/typedef_funcptr_runme.py @@ -0,0 +1,20 @@ +import typedef_funcptr + +a = 100 +b = 10 + +if typedef_funcptr.do_op(a,b,typedef_funcptr.addf) != 110: + raise RuntimeError("addf failed") +if typedef_funcptr.do_op(a,b,typedef_funcptr.subf) != 90: + raise RuntimeError("subf failed") + +if typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.addf) != 110: + raise RuntimeError("addf failed") +if typedef_funcptr.do_op_typedef_int(a,b,typedef_funcptr.subf) != 90: + raise RuntimeError("subf failed") + +if typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.addf) != 110: + raise RuntimeError("addf failed") +if typedef_funcptr.do_op_typedef_Integer(a,b,typedef_funcptr.subf) != 90: + raise RuntimeError("subf failed") + diff --git a/Examples/test-suite/typedef_funcptr.i b/Examples/test-suite/typedef_funcptr.i index f8cdd14b3..45ea99ef2 100644 --- a/Examples/test-suite/typedef_funcptr.i +++ b/Examples/test-suite/typedef_funcptr.i @@ -21,6 +21,16 @@ extern "C" Integer do_op(Integer x, Integer y, Integer (*op)(Integer, Integer)) { return (*op)(x,y); } + +typedef int (*FnPtr_int_td)(int, int); +int do_op_typedef_int(int x, int y, FnPtr_int_td op) { + return (*op)(x,y); +} + +typedef Integer (*FnPtr_Integer_td)(Integer, Integer); +Integer do_op_typedef_Integer(Integer x, Integer y, FnPtr_Integer_td op) { + return (*op)(x,y); +} %} %constant int addf(int x, int y); -- cgit v1.2.1