diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/headers/struct_with_anon_struct_array.h | 6 | ||||
-rw-r--r-- | tests/headers/struct_with_anon_struct_pointer.h | 6 | ||||
-rw-r--r-- | tests/struct.rs | 33 |
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/headers/struct_with_anon_struct_array.h b/tests/headers/struct_with_anon_struct_array.h new file mode 100644 index 00000000..2d9d7bdd --- /dev/null +++ b/tests/headers/struct_with_anon_struct_array.h @@ -0,0 +1,6 @@ +struct foo { + struct { + int a; + int b; + } bar[2]; +}; diff --git a/tests/headers/struct_with_anon_struct_pointer.h b/tests/headers/struct_with_anon_struct_pointer.h new file mode 100644 index 00000000..0c486d84 --- /dev/null +++ b/tests/headers/struct_with_anon_struct_pointer.h @@ -0,0 +1,6 @@ +struct foo { + struct { + int a; + int b; + } *bar; +}; diff --git a/tests/struct.rs b/tests/struct.rs index 980ea558..f9900349 100644 --- a/tests/struct.rs +++ b/tests/struct.rs @@ -18,6 +18,39 @@ fn test_struct_with_anon_struct() { } #[test] +fn test_struct_with_anon_struct_array() { + mod ffi { bindgen!("headers/struct_with_anon_struct_array.h"); } + let mut x = ffi::Struct_foo { bar: [ + ffi::Struct_Unnamed1 { a: 0, b: 0 }, + ffi::Struct_Unnamed1 { a: 1, b: 1 } ] + }; + + x.bar[1].a = 1; + x.bar[1].b = 2; + + assert_eq!(x.bar[1].a, 1); + assert_eq!(x.bar[1].b, 2); +} + +#[test] +fn test_struct_with_anon_struct_pointer() { + mod ffi { bindgen!("headers/struct_with_anon_struct_pointer.h"); } + let mut unnamed = box ffi::Struct_Unnamed1 { a: 0, b: 0 }; + + unsafe { + let mut x = ffi::Struct_foo { bar: ::std::mem::transmute(unnamed) }; + + (*x.bar).a = 1; + (*x.bar).b = 2; + + assert_eq!((*x.bar).a, 1); + assert_eq!((*x.bar).b, 2); + + ::std::ptr::read(x.bar); + } +} + +#[test] fn test_struct_with_anon_union() { mod ffi { bindgen!("headers/struct_with_anon_union.h"); } let mut x = ffi::Struct_foo { bar: ffi::Union_Unnamed1 { _bindgen_data_: [0] } }; |