From 5761a887abd00805c9ff921bcbf1ad809903bb9a Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Fri, 23 Apr 2021 15:02:38 -0700 Subject: [PATCH] Add tests for dependent qualified types. --- .../tests/dependent_qualified_type_complex.rs | 120 +++++++++++ .../tests/dependent_qualified_type_simpler.rs | 56 ++++++ .../tests/dependent_qualified_type_two.rs | 187 ++++++++++++++++++ .../tests/issue-544-stylo-creduce-2.rs | 19 +- tests/expectations/tests/nsBaseHashtable.rs | 6 +- .../dependent_qualified_type_complex.hpp | 17 ++ .../dependent_qualified_type_simpler.hpp | 11 ++ .../headers/dependent_qualified_type_two.hpp | 23 +++ 8 files changed, 433 insertions(+), 6 deletions(-) create mode 100644 tests/expectations/tests/dependent_qualified_type_complex.rs create mode 100644 tests/expectations/tests/dependent_qualified_type_simpler.rs create mode 100644 tests/expectations/tests/dependent_qualified_type_two.rs create mode 100644 tests/headers/dependent_qualified_type_complex.hpp create mode 100644 tests/headers/dependent_qualified_type_simpler.hpp create mode 100644 tests/headers/dependent_qualified_type_two.hpp diff --git a/tests/expectations/tests/dependent_qualified_type_complex.rs b/tests/expectations/tests/dependent_qualified_type_complex.rs new file mode 100644 index 0000000000..11d14eb340 --- /dev/null +++ b/tests/expectations/tests/dependent_qualified_type_complex.rs @@ -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::(), + 8usize, + concat!("Size of: ", stringify!(InnerType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InnerType)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).foo as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InnerType), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).foo2 as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(InnerType), + "::", + stringify!(foo2) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Container +where + ContainedType: __bindgen_has_inner_type_related_type, +{ + pub contents_: Container_content_ty, + pub _phantom_0: + ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +pub type Container_content_ty = + ::related_type; +pub type Concrete = Container; +#[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::(), + 4usize, + concat!("Size of: ", stringify!(LaterContainingType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LaterContainingType)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).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::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(Container) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(Container) + ) + ); +} diff --git a/tests/expectations/tests/dependent_qualified_type_simpler.rs b/tests/expectations/tests/dependent_qualified_type_simpler.rs new file mode 100644 index 0000000000..47b120a34d --- /dev/null +++ b/tests/expectations/tests/dependent_qualified_type_simpler.rs @@ -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::(), + 8usize, + concat!("Size of: ", stringify!(InnerType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InnerType)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).foo as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InnerType), + "::", + stringify!(foo) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Container +where + ContainedType: __bindgen_has_inner_type_related_type, +{ + pub contents_: + ::related_type, + pub _phantom_0: + ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +pub type Concrete = Container; +pub trait __bindgen_has_inner_type_related_type { + type related_type: std::fmt::Debug + Default + Copy + Clone; +} diff --git a/tests/expectations/tests/dependent_qualified_type_two.rs b/tests/expectations/tests/dependent_qualified_type_two.rs new file mode 100644 index 0000000000..94a51d3b2f --- /dev/null +++ b/tests/expectations/tests/dependent_qualified_type_two.rs @@ -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::(), + 8usize, + concat!("Size of: ", stringify!(InnerTypeA)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InnerTypeA)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).foo as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InnerTypeA), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).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::(), + 8usize, + concat!("Size of: ", stringify!(InnerTypeB)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InnerTypeB)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).bar as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InnerTypeB), + "::", + stringify!(bar) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Container +where + ContainedType: __bindgen_has_inner_type_related_type, +{ + pub contents_: Container_content_ty, + pub _phantom_0: + ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +pub type Container_content_ty = + ::related_type; +pub type Concrete = Container; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct LaterContainingType { + pub outer_contents_a: Concrete, + pub outer_contents_b: Container, +} +#[test] +fn bindgen_test_layout_LaterContainingType() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(LaterContainingType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LaterContainingType)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).outer_contents_a + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LaterContainingType), + "::", + stringify!(outer_contents_a) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).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::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(Container) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(Container) + ) + ); +} +#[test] +fn __bindgen_test_layout_Container_open0_InnerTypeB_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::>(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(Container) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(Container) + ) + ); +} diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 5a6242ea8e..de590e6762 100644 --- a/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -6,13 +6,22 @@ )] #[repr(C)] -pub struct Foo { - pub member: Foo_SecondAlias, +#[derive(Debug, Copy, Clone)] +pub struct Foo +where + T: __bindgen_has_inner_type_Associated, +{ + pub member: Foo_SecondAlias, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; -impl Default for Foo { +pub type Foo_FirstAlias = + ::Associated; +pub type Foo_SecondAlias = Foo>; +impl Default for Foo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +pub trait __bindgen_has_inner_type_Associated { + type Associated: std::fmt::Debug + Default + Copy + Clone; +} diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/tests/expectations/tests/nsBaseHashtable.rs index e26190b0d8..9827ce2016 100644 --- a/tests/expectations/tests/nsBaseHashtable.rs +++ b/tests/expectations/tests/nsBaseHashtable.rs @@ -21,7 +21,8 @@ pub struct nsTHashtable { pub struct nsBaseHashtable { pub _address: u8, } -pub type nsBaseHashtable_KeyType = [u8; 0usize]; +pub type nsBaseHashtable_KeyType = + ::KeyType; pub type nsBaseHashtable_EntryType = nsBaseHashtableET; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -50,3 +51,6 @@ impl Default for nsBaseHashtable { unsafe { ::std::mem::zeroed() } } } +pub trait __bindgen_has_inner_type_KeyType { + type KeyType: std::fmt::Debug + Default + Copy + Clone; +} diff --git a/tests/headers/dependent_qualified_type_complex.hpp b/tests/headers/dependent_qualified_type_complex.hpp new file mode 100644 index 0000000000..56f014bf9a --- /dev/null +++ b/tests/headers/dependent_qualified_type_complex.hpp @@ -0,0 +1,17 @@ +struct InnerType { + typedef int related_type; + int foo; + int foo2; +}; + +template class Container { +public: + typedef typename ContainedType::related_type content_ty; + content_ty contents_; +}; + +typedef Container Concrete; + +struct LaterContainingType { + Concrete outer_contents; +}; \ No newline at end of file diff --git a/tests/headers/dependent_qualified_type_simpler.hpp b/tests/headers/dependent_qualified_type_simpler.hpp new file mode 100644 index 0000000000..3d28fe7126 --- /dev/null +++ b/tests/headers/dependent_qualified_type_simpler.hpp @@ -0,0 +1,11 @@ +struct InnerType { + typedef int related_type; + long int foo; +}; + +template class Container { +public: + typename ContainedType::related_type contents_; +}; + +typedef Container Concrete; diff --git a/tests/headers/dependent_qualified_type_two.hpp b/tests/headers/dependent_qualified_type_two.hpp new file mode 100644 index 0000000000..ee8e81f46d --- /dev/null +++ b/tests/headers/dependent_qualified_type_two.hpp @@ -0,0 +1,23 @@ +struct InnerTypeA { + typedef int related_type; + int foo; + int foo2; +}; + +struct InnerTypeB { + typedef char related_type; + unsigned long bar; +}; + +template class Container { +public: + typedef typename ContainedType::related_type content_ty; + content_ty contents_; +}; + +typedef Container Concrete; + +struct LaterContainingType { + Concrete outer_contents_a; + Container outer_contents_b; +};