Skip to content

Commit 0dc7bcd

Browse files
committed
tests: Add negative tests for constructor/destructor generation behavior.
1 parent a4e606b commit 0dc7bcd

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default, Copy)]
9+
pub struct Foo {
10+
pub _address: u8,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Foo() {
14+
assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
15+
"Size of: " , stringify ! ( Foo ) ));
16+
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
17+
"Alignment of " , stringify ! ( Foo ) ));
18+
}
19+
impl Clone for Foo {
20+
fn clone(&self) -> Self { *self }
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default)]
9+
pub struct Foo {
10+
pub bar: ::std::os::raw::c_int,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Foo() {
14+
assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
15+
"Size of: " , stringify ! ( Foo ) ));
16+
assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
17+
"Alignment of " , stringify ! ( Foo ) ));
18+
assert_eq! (unsafe {
19+
& ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
20+
0usize , concat ! (
21+
"Alignment of field: " , stringify ! ( Foo ) , "::" ,
22+
stringify ! ( bar ) ));
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// bindgen-flags: --generate types,functions
2+
3+
class Foo {
4+
public:
5+
Foo(int a);
6+
};

tests/headers/gen-destructors-neg.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// bindgen-flags: --generate types,functions
2+
//
3+
// NB: This is intended to _not_ generate destructors.
4+
5+
class Foo {
6+
int bar;
7+
public:
8+
~Foo();
9+
};

0 commit comments

Comments
 (0)