Commit 38410081 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

buffer testcase fix

parent 48af72b0
...@@ -18,16 +18,16 @@ else: ...@@ -18,16 +18,16 @@ else:
current_endian = '>' current_endian = '>'
other_endian = '<' other_endian = '<'
cdef struct align_of_double_helper: cdef struct align_of_float_helper:
char ch char ch
double d float d
cdef struct align_of_int_helper: cdef struct align_of_int_helper:
char ch char ch
int i int i
double_align = sizeof(align_of_double_helper) - sizeof(double) float_align = sizeof(align_of_float_helper) - sizeof(float)
int_align = sizeof(align_of_int_helper) - sizeof(int) int_align = sizeof(align_of_int_helper) - sizeof(int)
if double_align != 8 or sizeof(double) != 8: if float_align != 4 or sizeof(float) != 4:
raise RuntimeError("Alignment or size of double is %d on this system, please report to cython-dev for a testcase fix" % double_align) raise RuntimeError("Alignment or size of float is %d on this system, please report to cython-dev for a testcase fix" % float_align)
if int_align != 4 or sizeof(int) != 4: if int_align != 4 or sizeof(int) != 4:
raise RuntimeError("Alignment or size of int is %d on this system, please report to cython-dev for a testcase fix" % int_align) raise RuntimeError("Alignment or size of int is %d on this system, please report to cython-dev for a testcase fix" % int_align)
...@@ -105,9 +105,9 @@ def _obj(fmt): ...@@ -105,9 +105,9 @@ def _obj(fmt):
cdef object[object] buf = MockBuffer(fmt, sizeof(void*)) cdef object[object] buf = MockBuffer(fmt, sizeof(void*))
cdef struct ComplexDouble: cdef struct ComplexFloat:
double real float real
double imag float imag
ctypedef struct Char3Int: ctypedef struct Char3Int:
char a char a
...@@ -115,33 +115,33 @@ ctypedef struct Char3Int: ...@@ -115,33 +115,33 @@ ctypedef struct Char3Int:
int c int c
int d int d
cdef struct CharIntCDouble: cdef struct CharIntCFloat:
char a char a
int b int b
ComplexDouble c ComplexFloat c
double d float d
cdef struct UnpackedStruct1: cdef struct UnpackedStruct1:
char a char a
int b int b
ComplexDouble c ComplexFloat c
double c2 float c2
Char3Int d Char3Int d
ctypedef struct UnpackedStruct2: ctypedef struct UnpackedStruct2:
CharIntCDouble a CharIntCFloat a
Char3Int b Char3Int b
ctypedef struct UnpackedStruct3: ctypedef struct UnpackedStruct3:
CharIntCDouble a CharIntCFloat a
char b char b
int c, d, e int c, d, e
cdef struct UnpackedStruct4: cdef struct UnpackedStruct4:
char a char a
int b int b
ComplexDouble c ComplexFloat c
double c2 float c2
char d char d
int e, f, g int e, f, g
...@@ -178,17 +178,17 @@ def char3int(fmt): ...@@ -178,17 +178,17 @@ def char3int(fmt):
obj = MockBuffer(fmt, sizeof(Char3Int)) obj = MockBuffer(fmt, sizeof(Char3Int))
cdef object[Char3Int, ndim=1] buf = obj cdef object[Char3Int, ndim=1] buf = obj
#@testcase @testcase
def unpacked_struct(fmt): def unpacked_struct(fmt):
""" """
Native formats: Native formats:
>>> unpacked_struct("biZddbiii") >>> unpacked_struct("biZffbiii")
>>> unpacked_struct("@bi3db3i") >>> unpacked_struct("@bi3fb3i")
>>> unpacked_struct("@biZddbi2i") >>> unpacked_struct("@biZffbi2i")
>>> unpacked_struct("bidT{biii}") >>> unpacked_struct("biZffT{biii}")
>>> unpacked_struct("bT{idddb2i}i") >>> unpacked_struct("bT{ifffb2i}i")
>>> unpacked_struct("bidb3T{i}") >>> unpacked_struct("biZffb3T{i}")
>>> unpacked_struct("T{b}T{T{iZddT{bi}}}2T{T{i}}") >>> unpacked_struct("T{b}T{T{iZffT{bi}}}2T{T{i}}")
""" """
assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2) assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2)
...@@ -200,20 +200,20 @@ def unpacked_struct(fmt): ...@@ -200,20 +200,20 @@ def unpacked_struct(fmt):
cdef object[UnpackedStruct4, ndim=1] buf4 = obj cdef object[UnpackedStruct4, ndim=1] buf4 = obj
cdef struct ComplexTest: cdef struct ComplexTest:
ComplexDouble a, b, c ComplexFloat a, b, c
@testcase @testcase
def complex_test(fmt): def complex_test(fmt):
""" """
>>> complex_test("ZdZdZd") >>> complex_test("ZfZfZf")
>>> complex_test("3Zd") >>> complex_test("3Zf")
>>> complex_test("6d") >>> complex_test("6f")
>>> complex_test("3T{Zd}") >>> complex_test("3T{Zf}")
>>> complex_test("dZdZdd") >>> complex_test("fZfZff")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Buffer dtype mismatch, expected 'double' but got 'complex double' in 'ComplexDouble.imag' ValueError: Buffer dtype mismatch, expected 'float' but got 'complex float' in 'ComplexFloat.imag'
""" """
obj = MockBuffer(fmt, sizeof(ComplexTest)) obj = MockBuffer(fmt, sizeof(ComplexTest))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment