diff options
author | Christian Vetter <christian.vetter@here.com> | 2021-08-03 09:04:40 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-08-24 11:49:26 +0200 |
commit | cf6edbd7b0dc59b82311b65dcb62d5993349f577 (patch) | |
tree | e6faab03e5ec325040b309ac1b92d0b77c98a946 /tests | |
parent | 098b416283610b3adbb5a51325644a8a66a4bfd2 (diff) |
Add tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/expectations/tests/enum-no-debug-rust.rs | 77 | ||||
-rw-r--r-- | tests/headers/enum-no-debug-rust.h | 3 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs new file mode 100644 index 00000000..fa06fbc0 --- /dev/null +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -0,0 +1,77 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, +} +pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; +pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum foo__bindgen_ty_1 { + FOO_A = 0, + FOO_B = 1, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::<foo>(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::<foo>(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::<foo>())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::<Self>::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Foo { + Bar = 0, + Qux = 1, +} +pub mod Neg { + pub type Type = ::std::os::raw::c_int; + pub const MinusOne: Type = -1; + pub const One: Type = 1; +} +#[repr(u32)] +/// <div rustbindgen nodebug></div> +#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub enum NoDebug { + NoDebug1 = 0, + NoDebug2 = 1, +} +#[repr(u32)] +/// <div rustbindgen derive="Debug"></div> +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Debug { + Debug1 = 0, + Debug2 = 1, +}
\ No newline at end of file diff --git a/tests/headers/enum-no-debug-rust.h b/tests/headers/enum-no-debug-rust.h new file mode 100644 index 00000000..7cb73980 --- /dev/null +++ b/tests/headers/enum-no-debug-rust.h @@ -0,0 +1,3 @@ +// bindgen-flags: --no-derive-debug --default-enum-style=rust --constified-enum-module=Neg + +#include "enum.h" |