summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-01-14 23:58:40 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-01-15 00:05:06 +0000
commit2272d00c1a60ea6f3710e4d9dc17746b9df69780 (patch)
treee8bab58f4aa4e75cd4c1cd0bbd1fdbdb38d0e95d
parent3aa302c08f609ad15a602b32a8c0124eb48861f9 (diff)
downloadswig-2272d00c1a60ea6f3710e4d9dc17746b9df69780.tar.gz
Add Python testcase for testing flatstaticmethod syntax
For testing legacy flattened static method access for when issue #2137 is applied.
-rw-r--r--Examples/test-suite/python/Makefile.in3
-rw-r--r--Examples/test-suite/python/callback_runme.py3
-rw-r--r--Examples/test-suite/python/python_flatstaticmethod_runme.py85
-rw-r--r--Examples/test-suite/python_flatstaticmethod.i36
4 files changed, 123 insertions, 4 deletions
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index 0bdbad51e..a5f2670d8 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -54,6 +54,7 @@ CPP_TEST_CASES += \
python_director \
python_docstring \
python_extranative \
+ python_flatstaticmethod \
python_moduleimport \
python_overload_simple_cast \
python_pickle \
@@ -97,7 +98,7 @@ LIBS = -L.
VALGRIND_OPT += --suppressions=pythonswig.supp
# Custom tests - tests with additional commandline options
-# none!
+#python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
# Rules for the different types of tests
%.cpptest:
diff --git a/Examples/test-suite/python/callback_runme.py b/Examples/test-suite/python/callback_runme.py
index 19f61c96b..dbf957cbb 100644
--- a/Examples/test-suite/python/callback_runme.py
+++ b/Examples/test-suite/python/callback_runme.py
@@ -17,9 +17,6 @@ if foobar(3, _callback.foo) != foo(3):
if foobar(3, foo) != foo(3):
raise RuntimeError
-if foobar(3, A_bar) != A_bar(3):
- raise RuntimeError
-
if foobar(3, A.bar) != A.bar(3):
raise RuntimeError
diff --git a/Examples/test-suite/python/python_flatstaticmethod_runme.py b/Examples/test-suite/python/python_flatstaticmethod_runme.py
new file mode 100644
index 000000000..f34670013
--- /dev/null
+++ b/Examples/test-suite/python/python_flatstaticmethod_runme.py
@@ -0,0 +1,85 @@
+from python_flatstaticmethod import *
+import inspect
+
+# This testcase tests C++ class static functions when using legacy "flattened"
+# staticmethod access, A_bar, as well as the normal staticmethod access, A.bar.
+
+
+def check(got, expected):
+ if got != expected:
+ raise RuntimeError("\ngot :{}\nwant:{}\n".format(got, expected))
+
+if A_bar(2) != 4:
+ raise RuntimeError
+
+if A.bar(2) != 4:
+ raise RuntimeError
+
+# %callback
+if foobar(3, A_bar) != A_bar(3):
+ raise RuntimeError
+
+if foobar(3, A.bar) != A_bar(3):
+ raise RuntimeError
+
+# kwargs
+if A_pub() != 1:
+ raise RuntimeError
+
+if A_pub(b=2) != 3:
+ raise RuntimeError
+
+if A_pub(b=10,a=20) != 30:
+ raise RuntimeError
+
+if A.pub() != 1:
+ raise RuntimeError
+
+if A.pub(b=2) != 3:
+ raise RuntimeError
+
+if A.pub(b=10,a=20) != 30:
+ raise RuntimeError
+
+check(inspect.getdoc(A_func0static),
+ "A_func0static(e, arg2, hello, f=2) -> int")
+check(inspect.getdoc(A_func1static),
+ "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int")
+
+# overloaded static functions
+if A_over(3) != "over:int":
+ raise RuntimeError("A::over(int)")
+
+if A_over(3.0) != "over:double":
+ raise RuntimeError("A::over(double)")
+
+if A_over("hello") != "over:char *":
+ raise RuntimeError("A::over(char *)")
+
+if A.over(3) != "over:int":
+ raise RuntimeError("A::over(int)")
+
+if A.over(3.0) != "over:double":
+ raise RuntimeError("A::over(double)")
+
+if A.over("hello") != "over:char *":
+ raise RuntimeError("A::over(char *)")
+
+# default args
+if A_defargs() != 30:
+ raise RuntimeError
+
+if A_defargs(1) != 21:
+ raise RuntimeError
+
+if A_defargs(1, 2) != 3:
+ raise RuntimeError
+
+if A.defargs() != 30:
+ raise RuntimeError
+
+if A.defargs(1) != 21:
+ raise RuntimeError
+
+if A.defargs(1, 2) != 3:
+ raise RuntimeError
diff --git a/Examples/test-suite/python_flatstaticmethod.i b/Examples/test-suite/python_flatstaticmethod.i
new file mode 100644
index 000000000..c0de7d298
--- /dev/null
+++ b/Examples/test-suite/python_flatstaticmethod.i
@@ -0,0 +1,36 @@
+%module python_flatstaticmethod
+
+// This testcase tests C++ class static functions when using legacy "flattened"
+// staticmethod access, A_bar, as well as the normal staticmethod access, A.bar.
+
+%callback(1) A::bar;
+%feature("kwargs") A::pub;
+%feature("autodoc","0") A::func0static; // names
+%feature("autodoc","1") A::func1static; // names + types
+// special typemap and its docs
+%typemap(in) (int c, int d) "$1 = 0; $2 = 0;";
+%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
+
+%inline %{
+ struct A {
+ static int bar(int a) {
+ return 2*a;
+ }
+ static int pub(int a = 1, int b = 0) {
+ return a + b;
+ }
+ static int func0static(A *e, short, int c, int d, double f = 2) { return 0; }
+ static int func1static(A *e, short, int c, int d, double f = 2) { return 0; }
+
+ static const char *over(int) { return "over:int"; }
+ static const char *over(double) { return "over:double"; }
+ static const char *over(char *) { return "over:char *"; }
+
+ static int defargs(int xx = 10, int yy = 20) { return xx + yy; }
+ };
+
+ extern "C" int foobar(int a, int (*pf)(int a)) {
+ return pf(a);
+ }
+%}
+