From 3509f4b1c5e221bbaea26fb1b3a6cd169cd82908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 9 Jun 2022 19:48:16 +0200 Subject: [PATCH] tests: Add a test for struct constants going through typedefs. --- .../const_generics_constant.both.c | 19 +++++++++++++ .../const_generics_constant.both.compat.c | 27 +++++++++++++++++++ tests/expectations/const_generics_constant.c | 19 +++++++++++++ .../const_generics_constant.compat.c | 27 +++++++++++++++++++ .../expectations/const_generics_constant.cpp | 25 +++++++++++++++++ .../expectations/const_generics_constant.pyx | 20 ++++++++++++++ .../const_generics_constant.tag.c | 19 +++++++++++++ .../const_generics_constant.tag.compat.c | 27 +++++++++++++++++++ .../const_generics_constant.tag.pyx | 20 ++++++++++++++ tests/rust/const_generics_constant.rs | 18 +++++++++++++ 10 files changed, 221 insertions(+) create mode 100644 tests/expectations/const_generics_constant.both.c create mode 100644 tests/expectations/const_generics_constant.both.compat.c create mode 100644 tests/expectations/const_generics_constant.c create mode 100644 tests/expectations/const_generics_constant.compat.c create mode 100644 tests/expectations/const_generics_constant.cpp create mode 100644 tests/expectations/const_generics_constant.pyx create mode 100644 tests/expectations/const_generics_constant.tag.c create mode 100644 tests/expectations/const_generics_constant.tag.compat.c create mode 100644 tests/expectations/const_generics_constant.tag.pyx create mode 100644 tests/rust/const_generics_constant.rs diff --git a/tests/expectations/const_generics_constant.both.c b/tests/expectations/const_generics_constant.both.c new file mode 100644 index 000000000..42a992455 --- /dev/null +++ b/tests/expectations/const_generics_constant.both.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS { + uint16_t value; +} FixedPoint_FONT_WEIGHT_FRACTION_BITS; + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +typedef struct FontWeight { + FontWeightFixedPoint _0; +} FontWeight; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +void root(struct FontWeight w); diff --git a/tests/expectations/const_generics_constant.both.compat.c b/tests/expectations/const_generics_constant.both.compat.c new file mode 100644 index 000000000..ce880aeb0 --- /dev/null +++ b/tests/expectations/const_generics_constant.both.compat.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS { + uint16_t value; +} FixedPoint_FONT_WEIGHT_FRACTION_BITS; + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +typedef struct FontWeight { + FontWeightFixedPoint _0; +} FontWeight; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(struct FontWeight w); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/const_generics_constant.c b/tests/expectations/const_generics_constant.c new file mode 100644 index 000000000..dd2494087 --- /dev/null +++ b/tests/expectations/const_generics_constant.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +typedef struct { + uint16_t value; +} FixedPoint_FONT_WEIGHT_FRACTION_BITS; + +typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +typedef struct { + FontWeightFixedPoint _0; +} FontWeight; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +void root(FontWeight w); diff --git a/tests/expectations/const_generics_constant.compat.c b/tests/expectations/const_generics_constant.compat.c new file mode 100644 index 000000000..14ebfa2d4 --- /dev/null +++ b/tests/expectations/const_generics_constant.compat.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +typedef struct { + uint16_t value; +} FixedPoint_FONT_WEIGHT_FRACTION_BITS; + +typedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +typedef struct { + FontWeightFixedPoint _0; +} FontWeight; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(FontWeight w); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/const_generics_constant.cpp b/tests/expectations/const_generics_constant.cpp new file mode 100644 index 000000000..715a071a0 --- /dev/null +++ b/tests/expectations/const_generics_constant.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +constexpr static const uint16_t FONT_WEIGHT_FRACTION_BITS = 6; + +template +struct FixedPoint { + uint16_t value; +}; + +using FontWeightFixedPoint = FixedPoint; + +struct FontWeight { + FontWeightFixedPoint _0; +}; +constexpr static const FontWeight FontWeight_NORMAL = FontWeight{ /* ._0 = */ FontWeightFixedPoint{ /* .value = */ (400 << FONT_WEIGHT_FRACTION_BITS) } }; + +extern "C" { + +void root(FontWeight w); + +} // extern "C" diff --git a/tests/expectations/const_generics_constant.pyx b/tests/expectations/const_generics_constant.pyx new file mode 100644 index 000000000..4e2282932 --- /dev/null +++ b/tests/expectations/const_generics_constant.pyx @@ -0,0 +1,20 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6 + + ctypedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS: + uint16_t value; + + ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + + ctypedef struct FontWeight: + FontWeightFixedPoint _0; + const FontWeight FontWeight_NORMAL # = { { (400 << FONT_WEIGHT_FRACTION_BITS) } } + + void root(FontWeight w); diff --git a/tests/expectations/const_generics_constant.tag.c b/tests/expectations/const_generics_constant.tag.c new file mode 100644 index 000000000..5ffb2a1c5 --- /dev/null +++ b/tests/expectations/const_generics_constant.tag.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +struct FixedPoint_FONT_WEIGHT_FRACTION_BITS { + uint16_t value; +}; + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +struct FontWeight { + FontWeightFixedPoint _0; +}; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +void root(struct FontWeight w); diff --git a/tests/expectations/const_generics_constant.tag.compat.c b/tests/expectations/const_generics_constant.tag.compat.c new file mode 100644 index 000000000..fc115cff1 --- /dev/null +++ b/tests/expectations/const_generics_constant.tag.compat.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#define FONT_WEIGHT_FRACTION_BITS 6 + +struct FixedPoint_FONT_WEIGHT_FRACTION_BITS { + uint16_t value; +}; + +typedef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + +struct FontWeight { + FontWeightFixedPoint _0; +}; +#define FontWeight_NORMAL (FontWeight){ ._0 = (FontWeightFixedPoint){ .value = (400 << FONT_WEIGHT_FRACTION_BITS) } } + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(struct FontWeight w); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/const_generics_constant.tag.pyx b/tests/expectations/const_generics_constant.tag.pyx new file mode 100644 index 000000000..f42ed410e --- /dev/null +++ b/tests/expectations/const_generics_constant.tag.pyx @@ -0,0 +1,20 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + const uint16_t FONT_WEIGHT_FRACTION_BITS # = 6 + + cdef struct FixedPoint_FONT_WEIGHT_FRACTION_BITS: + uint16_t value; + + ctypedef FixedPoint_FONT_WEIGHT_FRACTION_BITS FontWeightFixedPoint; + + cdef struct FontWeight: + FontWeightFixedPoint _0; + const FontWeight FontWeight_NORMAL # = { { (400 << FONT_WEIGHT_FRACTION_BITS) } } + + void root(FontWeight w); diff --git a/tests/rust/const_generics_constant.rs b/tests/rust/const_generics_constant.rs new file mode 100644 index 000000000..83ed86085 --- /dev/null +++ b/tests/rust/const_generics_constant.rs @@ -0,0 +1,18 @@ +#[repr(C)] +pub struct FixedPoint { + value: u16, +} + +pub const FONT_WEIGHT_FRACTION_BITS: u16 = 6; + +pub type FontWeightFixedPoint = FixedPoint; + +#[repr(C)] +pub struct FontWeight(FontWeightFixedPoint); + +impl FontWeight { + pub const NORMAL: FontWeight = FontWeight(FontWeightFixedPoint { value: 400 << FONT_WEIGHT_FRACTION_BITS }); +} + +#[no_mangle] +pub extern "C" fn root(w: FontWeight) {}