summaryrefslogtreecommitdiff
path: root/tests/test_struct.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_struct.rs')
-rw-r--r--tests/test_struct.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/test_struct.rs b/tests/test_struct.rs
index da7547e4..d3c52aef 100644
--- a/tests/test_struct.rs
+++ b/tests/test_struct.rs
@@ -11,6 +11,39 @@ fn with_anon_struct() {
}
#[test]
+fn 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 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 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] } };
@@ -68,7 +101,7 @@ fn with_nesting() {
}
#[test]
-fn with_fwd_decl_struct() {
+fn with_contain_fwd_decl_struct() {
assert_bind_eq!("headers/struct_containing_forward_declared_struct.h", cx,
quote_item!(cx,
#[repr(C)]
@@ -100,3 +133,14 @@ fn with_unnamed_bitfields() {
}
));
}
+
+#[test]
+fn with_fwd_decl_struct() {
+ mod ffi { bindgen!("headers/forward_declared_struct.h"); }
+
+ let a = ffi::Struct_a { b: 1 };
+ let c = ffi::Struct_c { d: 1 };
+
+ a.b;
+ c.d;
+}