diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/headers/class.hpp | 3 | ||||
-rw-r--r-- | tests/headers/namespace.h | 45 | ||||
-rw-r--r-- | tests/headers/template.hpp | 5 | ||||
-rw-r--r-- | tests/support.rs | 2 | ||||
-rw-r--r-- | tests/test_builtins.rs | 1 | ||||
-rw-r--r-- | tests/test_cxx.rs | 34 | ||||
-rw-r--r-- | tests/test_decl.rs | 2 | ||||
-rw-r--r-- | tests/test_enum.rs | 43 | ||||
-rw-r--r-- | tests/test_extern.rs | 2 | ||||
-rw-r--r-- | tests/test_func.rs | 13 | ||||
-rw-r--r-- | tests/test_struct.rs | 222 | ||||
-rw-r--r-- | tests/tests.rs | 1 |
12 files changed, 144 insertions, 229 deletions
diff --git a/tests/headers/class.hpp b/tests/headers/class.hpp new file mode 100644 index 00000000..53894ab3 --- /dev/null +++ b/tests/headers/class.hpp @@ -0,0 +1,3 @@ +class C { + int a; +}; diff --git a/tests/headers/namespace.h b/tests/headers/namespace.h new file mode 100644 index 00000000..055e7258 --- /dev/null +++ b/tests/headers/namespace.h @@ -0,0 +1,45 @@ + + +void top_level(); + +namespace whatever { + typedef int whatever_int_t; + + void in_whatever(); +} + +namespace { + namespace empty {} + + void foo(); + struct A { + whatever::whatever_int_t b; + public: + int lets_hope_this_works(); + }; +} + +template<typename T> +class C: public A { + T m_c; +}; + + +template<> +class C<int>; + + +namespace w { + typedef unsigned int whatever_int_t; + + template<typename T> + class D { + C<T> m_c; + }; + + whatever_int_t heh(); // this should return w::whatever_int_t, and not whatever::whatever_int_t + + C<int> foo(); + + C<float> barr(); // <- This is the problematic one +} diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp new file mode 100644 index 00000000..80825b74 --- /dev/null +++ b/tests/headers/template.hpp @@ -0,0 +1,5 @@ +template<typename T> class Foo { + T m_member; +}; + +void bar(Foo<int> foo); diff --git a/tests/support.rs b/tests/support.rs index a82529fe..0ac92f5f 100644 --- a/tests/support.rs +++ b/tests/support.rs @@ -43,7 +43,7 @@ pub fn assert_bind_eq(options: BindgenOptions, let mut parser = parse::new_parser_from_source_str(ext_cx.parse_sess(), ext_cx.cfg(), "".to_string(), reference_items_str.to_string()); let mut reference_items = Vec::new(); - while let Some(item) = parser.parse_item().unwrap() { + while let Ok(Some(item)) = parser.parse_item() { reference_items.push(item); } diff --git a/tests/test_builtins.rs b/tests/test_builtins.rs index a19d048c..c1ddce72 100644 --- a/tests/test_builtins.rs +++ b/tests/test_builtins.rs @@ -4,6 +4,7 @@ use bindgen; fn test_builtin_va_list() { let bindings = bindgen::builder().header("tests/headers/builtin_va_list.h") .emit_builtins().generate().unwrap().to_string(); + println!("{}", bindings); assert!(bindings.contains("__builtin_va_list")); } diff --git a/tests/test_cxx.rs b/tests/test_cxx.rs new file mode 100644 index 00000000..ea4e516f --- /dev/null +++ b/tests/test_cxx.rs @@ -0,0 +1,34 @@ +use bindgen; +use bindgen::BindgenOptions; +use support::assert_bind_eq; + +fn cxx_options() -> BindgenOptions { + let mut options = BindgenOptions::default(); + options.rename_types = false; + + options +} + +#[test] +fn test_cxx_class() { + assert_bind_eq(cxx_options(), "headers/class.hpp", " + #[repr(C)] + #[derive(Copy, Clone)] + pub struct C { + pub a: ::std::os::raw::c_int, + }"); +} + +#[test] +fn test_cxx_template() { + assert_bind_eq(cxx_options(), "headers/template.hpp", " + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Foo<T> { + pub m_member: T, + } + extern \"C\" { + #[link_name = \"_Z3bar3FooIiE\"] + pub fn bar(foo: Foo<::std::os::raw::c_int>); + }"); +} diff --git a/tests/test_decl.rs b/tests/test_decl.rs index 6858d416..58f7faba 100644 --- a/tests/test_decl.rs +++ b/tests/test_decl.rs @@ -4,7 +4,7 @@ use support::assert_bind_eq; fn ptr_to_array() { assert_bind_eq(Default::default(), "headers/decl_ptr_to_array.h", " extern \"C\" { - pub static mut foo: [::std::os::raw::c_int; 1usize]; + pub static mut foo: [i32; 1usize]; } "); } diff --git a/tests/test_enum.rs b/tests/test_enum.rs index e8c56c14..0a8a2bb8 100644 --- a/tests/test_enum.rs +++ b/tests/test_enum.rs @@ -8,13 +8,11 @@ fn default_without_rust_enums() -> BindgenOptions { #[test] fn with_simple_enum() { assert_bind_eq(Default::default(), "headers/enum.h", " - #[derive(Clone, Copy)] #[repr(u32)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Foo { Bar = 0, Qux = 1, } - #[derive(Clone, Copy)] #[repr(i32)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Neg { MinusOne = -1, One = 1, } "); assert_bind_eq(default_without_rust_enums(), "headers/enum.h", " @@ -30,17 +28,14 @@ fn with_simple_enum() { #[test] fn with_packed_enums() { assert_bind_eq(Default::default(), "headers/enum_packed.h", " - #[derive(Clone, Copy)] #[repr(u8)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Foo { Bar = 0, Qux = 1, } - #[derive(Clone, Copy)] #[repr(i8)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Neg { MinusOne = -1, One = 1, } - #[derive(Clone, Copy)] #[repr(u16)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Bigger { Much = 255, Larger = 256, } "); assert_bind_eq(default_without_rust_enums(), "headers/enum_packed.h", " @@ -60,9 +55,8 @@ fn with_packed_enums() { fn with_duplicate_enum_value() { assert_bind_eq(Default::default(), "headers/enum_dupe.h", " pub const Dupe: Enum_Foo = Enum_Foo::Bar; - #[derive(Clone, Copy)] #[repr(u32)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Foo { Bar = 1, } "); assert_bind_eq(default_without_rust_enums(), "headers/enum_dupe.h", " @@ -75,25 +69,24 @@ fn with_duplicate_enum_value() { #[test] fn with_explicitly_typed_cxx_enum() { assert_bind_eq(Default::default(), "headers/enum_explicit_type.hpp", " - #[derive(Clone, Copy)] #[repr(u8)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Foo { Bar = 0, Qux = 1, } - #[derive(Clone, Copy)] + #[repr(i8)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Neg { MinusOne = -1, One = 1, } - #[derive(Clone, Copy)] + #[repr(u16)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Bigger { Much = 255, Larger = 256, } - #[derive(Clone, Copy)] + #[repr(i64)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_MuchLong { MuchLow = -4294967296, } - #[derive(Clone, Copy)] + #[repr(u64)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_MuchLongLong { MuchHigh = 4294967296, } "); assert_bind_eq(default_without_rust_enums(), "headers/enum_explicit_type.hpp", " @@ -116,17 +109,15 @@ fn with_explicitly_typed_cxx_enum() { #[test] fn with_overflowed_enum_value() { assert_bind_eq(Default::default(), "headers/overflowed_enum.hpp", " - #[derive(Clone, Copy)] #[repr(u32)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Foo { BAP_ARM = 9698489, BAP_X86 = 11960045, BAP_X86_64 = 3128633167, } - #[derive(Clone, Copy)] #[repr(u16)] - #[derive(Debug)] + #[derive(Copy, Clone, Debug)] pub enum Enum_Bar { One = 1, Big = 2, } "); assert_bind_eq(default_without_rust_enums(), "headers/overflowed_enum.hpp", " diff --git a/tests/test_extern.rs b/tests/test_extern.rs index 25b06f0a..0d093593 100644 --- a/tests/test_extern.rs +++ b/tests/test_extern.rs @@ -3,6 +3,6 @@ use support::assert_bind_eq; #[test] fn extern_c_in_hpp() { assert_bind_eq(Default::default(), "headers/extern.hpp", " - pub type foo = extern \"C\" fn(bar: ::std::os::raw::c_int) -> ::std::os::raw::c_int; + pub type foo = extern \"C\" fn(bar: i32) -> i32; "); } diff --git a/tests/test_func.rs b/tests/test_func.rs index e0b80d68..434612ef 100644 --- a/tests/test_func.rs +++ b/tests/test_func.rs @@ -15,21 +15,12 @@ fn func_ptr() { fn func_ptr_in_struct() { assert_bind_eq(Default::default(), "headers/func_ptr_in_struct.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_Foo { pub bar: ::std::option::Option< - extern \"C\" fn(x: ::std::os::raw::c_int, + unsafe extern \"C\" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> Enum_baz>, } - - impl ::std::clone::Clone for Struct_Foo { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_Foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } "); } diff --git a/tests/test_struct.rs b/tests/test_struct.rs index 2360f208..9f0625b4 100644 --- a/tests/test_struct.rs +++ b/tests/test_struct.rs @@ -4,125 +4,68 @@ use support::assert_bind_eq; fn with_anon_struct() { assert_bind_eq(Default::default(), "headers/struct_with_anon_struct.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_foo { - pub bar: Struct_Unnamed1, - } - impl ::std::clone::Clone for Struct_foo { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + pub bar: Struct_struct_with_anon_struct_h_unnamed_1, } + #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_Unnamed1 { + #[derive(Copy, Clone)] + pub struct Struct_struct_with_anon_struct_h_unnamed_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, - } - impl ::std::clone::Clone for Struct_Unnamed1 { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_Unnamed1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); + }"); } #[test] fn with_anon_struct_array() { assert_bind_eq(Default::default(), "headers/struct_with_anon_struct_array.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_foo { - pub bar: [Struct_Unnamed1; 2usize], - pub baz: [[[Struct_Unnamed2; 4usize]; 3usize]; 2usize], - } - - impl ::std::clone::Clone for Struct_foo { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + pub bar: [Struct_struct_with_anon_struct_array_h_unnamed_1; 2usize], + pub baz: [[[Struct_struct_with_anon_struct_array_h_unnamed_2; 4usize]; 3usize]; 2usize], } #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_Unnamed1 { + #[derive(Copy, Clone)] + pub struct Struct_struct_with_anon_struct_array_h_unnamed_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } - impl ::std::clone::Clone for Struct_Unnamed1 { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_Unnamed1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_Unnamed2 { + #[derive(Copy, Clone)] + pub struct Struct_struct_with_anon_struct_array_h_unnamed_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, - } - - impl ::std::clone::Clone for Struct_Unnamed2 { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_Unnamed2 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); + }"); } #[test] fn with_anon_struct_pointer() { assert_bind_eq(Default::default(), "headers/struct_with_anon_struct_pointer.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_foo { - pub bar: *mut Struct_Unnamed1, - } - impl ::std::clone::Clone for Struct_foo { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_foo { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } + pub bar: *mut Struct_struct_with_anon_struct_pointer_h_unnamed_1, } + #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_Unnamed1 { + #[derive(Copy, Clone)] + pub struct Struct_struct_with_anon_struct_pointer_h_unnamed_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, - } - impl ::std::clone::Clone for Struct_Unnamed1 { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_Unnamed1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); + }"); } #[test] fn with_anon_union() { assert_bind_eq(Default::default(), "headers/struct_with_anon_union.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_foo { - pub bar: Union_Unnamed1, + pub bar: Union_unnamed1, } impl ::std::clone::Clone for Struct_foo { fn clone(&self) -> Self { *self } @@ -133,10 +76,10 @@ fn with_anon_union() { #[repr(C)] #[derive(Copy)] #[derive(Debug)] - pub struct Union_Unnamed1 { + pub struct Union_unnamed1 { pub _bindgen_data_: [u32; 1usize], } - impl Union_Unnamed1 { + impl Union_unnamed1 { pub unsafe fn a(&mut self) -> *mut ::std::os::raw::c_uint { let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_); ::std::mem::transmute(raw.offset(0)) @@ -146,12 +89,6 @@ fn with_anon_union() { ::std::mem::transmute(raw.offset(0)) } } - impl ::std::clone::Clone for Union_Unnamed1 { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Union_Unnamed1 { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } "); } @@ -187,8 +124,7 @@ fn with_anon_unnamed_struct() { fn with_anon_unnamed_union() { assert_bind_eq(Default::default(), "headers/struct_with_anon_unnamed_union.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_foo { pub _bindgen_data_1_: [u32; 1usize], } @@ -264,34 +200,16 @@ fn with_nesting() { fn containing_fwd_decl_struct() { assert_bind_eq(Default::default(), "headers/struct_containing_forward_declared_struct.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_a { pub val_a: *mut Struct_b, } - impl ::std::clone::Clone for Struct_a { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_a { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_b { pub val_b: ::std::os::raw::c_int, } - - impl ::std::clone::Clone for Struct_b { - fn clone(&self) -> Self { *self } - } - - impl ::std::default::Default for Struct_b { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } "); } @@ -322,30 +240,16 @@ fn with_bitfields() { fn with_fwd_decl_struct() { assert_bind_eq(Default::default(), "headers/forward_declared_struct.h", " #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_a { pub b: ::std::os::raw::c_int, } - impl ::std::clone::Clone for Struct_a { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_a { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } + #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_c { pub d: ::std::os::raw::c_int, - } - impl ::std::clone::Clone for Struct_c { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_c { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); + }"); } @@ -353,69 +257,9 @@ fn with_fwd_decl_struct() { fn packed_struct() { assert_bind_eq(Default::default(), "headers/struct_with_packing.h", " #[repr(C, packed)] - #[derive(Copy)] - #[derive(Debug)] + #[derive(Copy, Clone)] pub struct Struct_a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, - } - impl ::std::clone::Clone for Struct_a { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_a { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); -} - -#[test] -fn derive_debug_big_array() { - assert_bind_eq(Default::default(), "headers/struct_with_derive_debug.h", " - #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_LittleArray { - pub a: [::std::os::raw::c_int; 32usize], - } - impl ::std::clone::Clone for Struct_LittleArray { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_LittleArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - #[repr(C)] - #[derive(Copy)] - pub struct Struct_BigArray { - pub a: [::std::os::raw::c_int; 33usize], - } - impl ::std::clone::Clone for Struct_BigArray { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_BigArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - #[repr(C)] - #[derive(Copy)] - #[derive(Debug)] - pub struct Struct_WithLittleArray { - pub a: Struct_LittleArray, - } - impl ::std::clone::Clone for Struct_WithLittleArray { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_WithLittleArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - #[repr(C)] - #[derive(Copy)] - pub struct Struct_WithBigArray { - pub a: Struct_BigArray, - } - impl ::std::clone::Clone for Struct_WithBigArray { - fn clone(&self) -> Self { *self } - } - impl ::std::default::Default for Struct_WithBigArray { - fn default() -> Self { unsafe { ::std::mem::zeroed() } } - } - "); + }"); } diff --git a/tests/tests.rs b/tests/tests.rs index 33a75511..2e7072fe 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -7,6 +7,7 @@ mod support; // Unused until we can generate code for tests //mod test_cmath; +mod test_cxx; mod test_enum; mod test_decl; mod test_extern; |