diff --git a/Examples/test-suite/ccomplextest.i b/Examples/test-suite/ccomplextest.i new file mode 100644 index 000000000..4a2f68ff6 --- /dev/null +++ b/Examples/test-suite/ccomplextest.i @@ -0,0 +1,79 @@ +%module ccomplextest + +%include + +%{ +#include + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199001L +#define HAS_C99_COMPLEX_FOR_TESTING 1 +#else +/* complex not supported - hack tests to just test plain floating point numbers */ +/* some pre c99 compilers (gcc-4.x) don't define _Complex but do define complex */ +#define _Complex +#if !defined(complex) +# define complex +#endif +#define conj +#define conjf +#if defined(I) +# undef I +# define I 1 +#endif +#define HAS_C99_COMPLEX_FOR_TESTING 0 +#endif +%} + +%inline +{ + int has_c99_complex(void) { + return HAS_C99_COMPLEX_FOR_TESTING; + } + + complex double Conj(complex double a) + { + return conj(a); + } + + + complex float Conjf(complex float a) + { + return conjf(a); + } + + + double complex Conj1(double complex a) + { + return conj(a); + } + + + float complex Conjf1(float complex a) + { + return conjf(a); + } + + + _Complex double Conj2(_Complex double a) + { + return conj(a); + } + + + _Complex float Conjf2(_Complex float a) + { + return conjf(a); + } + + + double _Complex Conj3(double _Complex a) + { + return conj(a); + } + + + float _Complex Conjf3(float _Complex a) + { + return conjf(a); + } +} diff --git a/Examples/test-suite/complextest.i b/Examples/test-suite/complextest.i index 622b38058..6c7b1f44a 100644 --- a/Examples/test-suite/complextest.i +++ b/Examples/test-suite/complextest.i @@ -2,7 +2,6 @@ %include -#ifdef __cplusplus %{ #include #include @@ -10,9 +9,7 @@ %} %include -#if 1 %template(VectorStdCplx) std::vector >; -#endif %inline { @@ -63,63 +60,3 @@ } } - -#else - - -%{ -#include -%} - -%inline -{ - complex double Conj(complex double a) - { - return conj(a); - } - - - complex float Conjf(complex float a) - { - return conjf(a); - } - - - double complex Conj1(double complex a) - { - return conj(a); - } - - - float complex Conjf1(float complex a) - { - return conjf(a); - } - - - _Complex double Conj2(_Complex double a) - { - return conj(a); - } - - - _Complex float Conjf2(_Complex float a) - { - return conjf(a); - } - - - double _Complex Conj3(double _Complex a) - { - return conj(a); - } - - - float _Complex Conjf3(float _Complex a) - { - return conjf(a); - } -} - - -#endif diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 4fab31206..d42ffec5a 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -13,6 +13,9 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ +C_TEST_CASES += \ + ccomplextest \ + SWIGEXE = $(top_builddir)/swig SWIG_LIB_DIR = $(top_srcdir)/Lib diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in index 1d54a47bb..9602d85f5 100644 --- a/Examples/test-suite/octave/Makefile.in +++ b/Examples/test-suite/octave/Makefile.in @@ -29,14 +29,6 @@ CPP_TEST_BROKEN += \ li_std_set \ li_std_stream -#C_TEST_CASES += - -# -# This test only works with modern C compilers -# -#C_TEST_CASES += \ -# complextest - include $(srcdir)/../common.mk # Overridden variables here diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 7ca98b3bc..c2528eb49 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -83,19 +83,13 @@ CPP11_TEST_CASES = \ cpp11_std_unordered_set \ C_TEST_CASES += \ - complextest \ + ccomplextest \ file_test \ li_cstring \ li_cwstring \ python_nondynamic \ python_varargs_typemap \ -# -# This test only works with modern C compilers -# -#C_TEST_CASES += \ -# complextest - include $(srcdir)/../common.mk # Overridden variables here diff --git a/Examples/test-suite/python/ccomplextest_runme.py b/Examples/test-suite/python/ccomplextest_runme.py new file mode 100644 index 000000000..60b95458d --- /dev/null +++ b/Examples/test-suite/python/ccomplextest_runme.py @@ -0,0 +1,24 @@ +import ccomplextest + +a = complex(-1, 2) + +if ccomplextest.has_c99_complex(): + if ccomplextest.Conj(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") + + if ccomplextest.Conjf(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") + + if ccomplextest.Conj2(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") + + if ccomplextest.Conjf2(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") + + if ccomplextest.Conj3(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") + + if ccomplextest.Conjf3(a) != a.conjugate(): + raise RuntimeError("bad complex mapping") +else: + print("Not a c99 compiler") diff --git a/Examples/test-suite/python/complextest_runme.py b/Examples/test-suite/python/complextest_runme.py index 3eef2b2bc..1b9ad6629 100644 --- a/Examples/test-suite/python/complextest_runme.py +++ b/Examples/test-suite/python/complextest_runme.py @@ -14,26 +14,16 @@ if complextest.Conj2(a) != a.conjugate(): if complextest.Conjf2(a) != a.conjugate(): raise RuntimeError("bad complex mapping") -if 'Conj3' in dir(complextest): - if complextest.Conj3(a) != a.conjugate(): - raise RuntimeError("bad complex mapping") +v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) -if 'Conjf3' in dir(complextest): - if complextest.Conjf3(a) != a.conjugate(): - raise RuntimeError("bad complex mapping") +if len(complextest.CopyHalf(v)) != 2: + raise RuntimeError("CopyHalf failed") -if 'CopyHalf' in dir(complextest): +if len(complextest.CopyHalfRef(v)) != 2: + raise RuntimeError("CopyHalfRef failed") - v = (complex(1, 2), complex(2, 3), complex(4, 3), 1) - - if len(complextest.CopyHalf(v)) != 2: - raise RuntimeError("CopyHalf failed") - - if len(complextest.CopyHalfRef(v)) != 2: - raise RuntimeError("CopyHalfRef failed") - - p = complextest.ComplexPair() - p.z1 = complex(0, 1) - p.z2 = complex(0, -1) - if complextest.Conj(p.z2) != p.z1: - raise RuntimeError("bad complex mapping") +p = complextest.ComplexPair() +p.z1 = complex(0, 1) +p.z2 = complex(0, -1) +if complextest.Conj(p.z2) != p.z1: + raise RuntimeError("bad complex mapping")