Skip to content

Commit cf6edbd

Browse files
VeaaCemilio
authored andcommitted
Add tests
1 parent 098b416 commit cf6edbd

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Copy, Clone)]
10+
pub struct foo {
11+
pub member: foo__bindgen_ty_1,
12+
}
13+
pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A;
14+
pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B;
15+
#[repr(u32)]
16+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
17+
pub enum foo__bindgen_ty_1 {
18+
FOO_A = 0,
19+
FOO_B = 1,
20+
}
21+
#[test]
22+
fn bindgen_test_layout_foo() {
23+
assert_eq!(
24+
::std::mem::size_of::<foo>(),
25+
4usize,
26+
concat!("Size of: ", stringify!(foo))
27+
);
28+
assert_eq!(
29+
::std::mem::align_of::<foo>(),
30+
4usize,
31+
concat!("Alignment of ", stringify!(foo))
32+
);
33+
assert_eq!(
34+
unsafe { &(*(::std::ptr::null::<foo>())).member as *const _ as usize },
35+
0usize,
36+
concat!(
37+
"Offset of field: ",
38+
stringify!(foo),
39+
"::",
40+
stringify!(member)
41+
)
42+
);
43+
}
44+
impl Default for foo {
45+
fn default() -> Self {
46+
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
47+
unsafe {
48+
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
49+
s.assume_init()
50+
}
51+
}
52+
}
53+
#[repr(u32)]
54+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
55+
pub enum Foo {
56+
Bar = 0,
57+
Qux = 1,
58+
}
59+
pub mod Neg {
60+
pub type Type = ::std::os::raw::c_int;
61+
pub const MinusOne: Type = -1;
62+
pub const One: Type = 1;
63+
}
64+
#[repr(u32)]
65+
/// <div rustbindgen nodebug></div>
66+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
67+
pub enum NoDebug {
68+
NoDebug1 = 0,
69+
NoDebug2 = 1,
70+
}
71+
#[repr(u32)]
72+
/// <div rustbindgen derive="Debug"></div>
73+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
74+
pub enum Debug {
75+
Debug1 = 0,
76+
Debug2 = 1,
77+
}

tests/headers/enum-no-debug-rust.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// bindgen-flags: --no-derive-debug --default-enum-style=rust --constified-enum-module=Neg
2+
3+
#include "enum.h"

0 commit comments

Comments
 (0)