mirror of https://github.com/swig/swig
Split C complex.h from C++ complex testing
This commit is contained in:
parent
9a2513bf85
commit
fd592fdc3b
|
@ -0,0 +1,79 @@
|
|||
%module ccomplextest
|
||||
|
||||
%include <complex.i>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
%include <complex.i>
|
||||
|
||||
#ifdef __cplusplus
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
@ -10,9 +9,7 @@
|
|||
%}
|
||||
%include <std_vector.i>
|
||||
|
||||
#if 1
|
||||
%template(VectorStdCplx) std::vector<std::complex<double> >;
|
||||
#endif
|
||||
|
||||
%inline
|
||||
{
|
||||
|
@ -63,63 +60,3 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
%}
|
||||
|
||||
%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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue