Skip to content

Commit

Permalink
Add tests for dependent qualified types.
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor committed Apr 23, 2021
1 parent cebb2d1 commit 5761a88
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 6 deletions.
120 changes: 120 additions & 0 deletions tests/expectations/tests/dependent_qualified_type_complex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct InnerType {
pub foo: ::std::os::raw::c_int,
pub foo2: ::std::os::raw::c_int,
}
pub type InnerType_related_type = ::std::os::raw::c_int;
impl __bindgen_has_inner_type_related_type for InnerType {
type related_type = InnerType_related_type;
}
#[test]
fn bindgen_test_layout_InnerType() {
assert_eq!(
::std::mem::size_of::<InnerType>(),
8usize,
concat!("Size of: ", stringify!(InnerType))
);
assert_eq!(
::std::mem::align_of::<InnerType>(),
4usize,
concat!("Alignment of ", stringify!(InnerType))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerType>())).foo as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(InnerType),
"::",
stringify!(foo)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerType>())).foo2 as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
stringify!(InnerType),
"::",
stringify!(foo2)
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Container<ContainedType>
where
ContainedType: __bindgen_has_inner_type_related_type,
{
pub contents_: Container_content_ty<ContainedType>,
pub _phantom_0:
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
}
pub type Container_content_ty<ContainedType> =
<ContainedType as __bindgen_has_inner_type_related_type>::related_type;
pub type Concrete = Container<InnerType>;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct LaterContainingType {
pub outer_contents: Concrete,
}
#[test]
fn bindgen_test_layout_LaterContainingType() {
assert_eq!(
::std::mem::size_of::<LaterContainingType>(),
4usize,
concat!("Size of: ", stringify!(LaterContainingType))
);
assert_eq!(
::std::mem::align_of::<LaterContainingType>(),
4usize,
concat!("Alignment of ", stringify!(LaterContainingType))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents
as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(LaterContainingType),
"::",
stringify!(outer_contents)
)
);
}
pub trait __bindgen_has_inner_type_related_type {
type related_type: std::fmt::Debug + Default + Copy + Clone;
}
#[test]
fn __bindgen_test_layout_Container_open0_InnerType_close0_instantiation() {
assert_eq!(
::std::mem::size_of::<Container<InnerType>>(),
4usize,
concat!(
"Size of template specialization: ",
stringify!(Container<InnerType>)
)
);
assert_eq!(
::std::mem::align_of::<Container<InnerType>>(),
4usize,
concat!(
"Alignment of template specialization: ",
stringify!(Container<InnerType>)
)
);
}
56 changes: 56 additions & 0 deletions tests/expectations/tests/dependent_qualified_type_simpler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct InnerType {
pub foo: ::std::os::raw::c_long,
}
pub type InnerType_related_type = ::std::os::raw::c_int;
impl __bindgen_has_inner_type_related_type for InnerType {
type related_type = InnerType_related_type;
}
#[test]
fn bindgen_test_layout_InnerType() {
assert_eq!(
::std::mem::size_of::<InnerType>(),
8usize,
concat!("Size of: ", stringify!(InnerType))
);
assert_eq!(
::std::mem::align_of::<InnerType>(),
8usize,
concat!("Alignment of ", stringify!(InnerType))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerType>())).foo as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(InnerType),
"::",
stringify!(foo)
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Container<ContainedType>
where
ContainedType: __bindgen_has_inner_type_related_type,
{
pub contents_:
<ContainedType as __bindgen_has_inner_type_related_type>::related_type,
pub _phantom_0:
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
}
pub type Concrete = Container<InnerType>;
pub trait __bindgen_has_inner_type_related_type {
type related_type: std::fmt::Debug + Default + Copy + Clone;
}
187 changes: 187 additions & 0 deletions tests/expectations/tests/dependent_qualified_type_two.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct InnerTypeA {
pub foo: ::std::os::raw::c_int,
pub foo2: ::std::os::raw::c_int,
}
pub type InnerTypeA_related_type = ::std::os::raw::c_int;
impl __bindgen_has_inner_type_related_type for InnerTypeA {
type related_type = InnerTypeA_related_type;
}
#[test]
fn bindgen_test_layout_InnerTypeA() {
assert_eq!(
::std::mem::size_of::<InnerTypeA>(),
8usize,
concat!("Size of: ", stringify!(InnerTypeA))
);
assert_eq!(
::std::mem::align_of::<InnerTypeA>(),
4usize,
concat!("Alignment of ", stringify!(InnerTypeA))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerTypeA>())).foo as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(InnerTypeA),
"::",
stringify!(foo)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerTypeA>())).foo2 as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
stringify!(InnerTypeA),
"::",
stringify!(foo2)
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct InnerTypeB {
pub bar: ::std::os::raw::c_ulong,
}
pub type InnerTypeB_related_type = ::std::os::raw::c_char;
impl __bindgen_has_inner_type_related_type for InnerTypeB {
type related_type = InnerTypeB_related_type;
}
#[test]
fn bindgen_test_layout_InnerTypeB() {
assert_eq!(
::std::mem::size_of::<InnerTypeB>(),
8usize,
concat!("Size of: ", stringify!(InnerTypeB))
);
assert_eq!(
::std::mem::align_of::<InnerTypeB>(),
8usize,
concat!("Alignment of ", stringify!(InnerTypeB))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<InnerTypeB>())).bar as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(InnerTypeB),
"::",
stringify!(bar)
)
);
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Container<ContainedType>
where
ContainedType: __bindgen_has_inner_type_related_type,
{
pub contents_: Container_content_ty<ContainedType>,
pub _phantom_0:
::std::marker::PhantomData<::std::cell::UnsafeCell<ContainedType>>,
}
pub type Container_content_ty<ContainedType> =
<ContainedType as __bindgen_has_inner_type_related_type>::related_type;
pub type Concrete = Container<InnerTypeA>;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct LaterContainingType {
pub outer_contents_a: Concrete,
pub outer_contents_b: Container<InnerTypeB>,
}
#[test]
fn bindgen_test_layout_LaterContainingType() {
assert_eq!(
::std::mem::size_of::<LaterContainingType>(),
8usize,
concat!("Size of: ", stringify!(LaterContainingType))
);
assert_eq!(
::std::mem::align_of::<LaterContainingType>(),
4usize,
concat!("Alignment of ", stringify!(LaterContainingType))
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents_a
as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(LaterContainingType),
"::",
stringify!(outer_contents_a)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<LaterContainingType>())).outer_contents_b
as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
stringify!(LaterContainingType),
"::",
stringify!(outer_contents_b)
)
);
}
pub trait __bindgen_has_inner_type_related_type {
type related_type: std::fmt::Debug + Default + Copy + Clone;
}
#[test]
fn __bindgen_test_layout_Container_open0_InnerTypeA_close0_instantiation() {
assert_eq!(
::std::mem::size_of::<Container<InnerTypeA>>(),
4usize,
concat!(
"Size of template specialization: ",
stringify!(Container<InnerTypeA>)
)
);
assert_eq!(
::std::mem::align_of::<Container<InnerTypeA>>(),
4usize,
concat!(
"Alignment of template specialization: ",
stringify!(Container<InnerTypeA>)
)
);
}
#[test]
fn __bindgen_test_layout_Container_open0_InnerTypeB_close0_instantiation() {
assert_eq!(
::std::mem::size_of::<Container<InnerTypeB>>(),
1usize,
concat!(
"Size of template specialization: ",
stringify!(Container<InnerTypeB>)
)
);
assert_eq!(
::std::mem::align_of::<Container<InnerTypeB>>(),
1usize,
concat!(
"Alignment of template specialization: ",
stringify!(Container<InnerTypeB>)
)
);
}
19 changes: 14 additions & 5 deletions tests/expectations/tests/issue-544-stylo-creduce-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
)]

#[repr(C)]
pub struct Foo {
pub member: Foo_SecondAlias,
#[derive(Debug, Copy, Clone)]
pub struct Foo<T>
where
T: __bindgen_has_inner_type_Associated,
{
pub member: Foo_SecondAlias<i32>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
pub type Foo_FirstAlias = [u8; 0usize];
pub type Foo_SecondAlias = [u8; 0usize];
impl Default for Foo {
pub type Foo_FirstAlias<T> =
<T as __bindgen_has_inner_type_Associated>::Associated;
pub type Foo_SecondAlias<T> = Foo<Foo_FirstAlias<T>>;
impl<T> Default for Foo<T> {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
pub trait __bindgen_has_inner_type_Associated {
type Associated: std::fmt::Debug + Default + Copy + Clone;
}
Loading

0 comments on commit 5761a88

Please sign in to comment.