diff options
author | Michael Wu <mwu@mozilla.com> | 2015-03-25 00:39:01 -0400 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-03-16 23:24:22 +0100 |
commit | ab10295699a014dedea5a1abd9c03ed0847a11fd (patch) | |
tree | bd7da707d6af7136c03c35437397fe04db84738a /tests | |
parent | 6f1904e52612db3a2517727c053e7cbc84601b2a (diff) |
SM hacks squash
Generate better enums
Squash of...
Disable prefixing
Default to failing on unknown types
Add support for Char16
Emit errors for unknown cursor kinds
Hack in support for classes
Recurse into unexposed decls
This fixes functions that use extern "C".
Add support for generating unmangled functions
Prefix unnamed data structures with the file name
Recurse into namespaced things
Avoid rust reserved keywords in unmangle func args
Don't create variadic unmangled funcs
Don't translate typedefs to the same name
Ignore operator overloads
Avoid templates
Handle class declarations
Number duplicate demangle functions
Implement copy on enums
Translate stdint types into standard rust int types
Switch enums to i32 for better compatibility
Correctly deal with mangled functions with unnamed args
Mark unmangling functions as unsafe
Attempt to produce structs for C++ classes
Convert references
Generate better func decls for void returns
Make every function callback unsafe
Add support for generics in typedefs
Add support for class templates
Aggressively trim duplicates
Don't generate default impl for templates
Improve handling of templates
Fix function numbering
Fix deduplication
Make unmangling functions extern "C"
Convert all int/float typedefs to standard rust ints/floats
This also gives better information to the bitfield parsing and allows uint32_t and other stdint bitfields to be processed properly
Add support for wchar
Add support for bitfield setter generation
Fix floats
Squash of...
Shorten generated bitfield names
Add support for generating whole bitfields
Add support for enums nested inside structs/classes
Rustup
Fixes #184.
Rustup to b301e02f3 2015-05-19
Inline demangling functions
Add support for base classes/types
Generate bindings for methods
Make duplicate detection less aggressive
Avoid converting long/unsigned longs to rust types.
This fixes 64/32bit issues in structs.
Generate bitfields correctly for typedefs
Convert stdint types to rust types
Derive Debug on BindgenOptions, Bindings, and LinkType.
Remove +'static when writing bindings
Generate virtual function tables
Resolve some warnings
Add NotConst where Constness params are required
Generate real bools when applicable
Squash of...
Add support for comments
Improve bitfield support using const fn
Add limited support for references
Add comments to fields
Don't generate empty comments
Convert char16_t to u16 rather than i16
Convert signed chars to libc::c_char
Fix Cargo.toml rebasing breakage
Fix compiler errors
This gets bindgen to compile and run again, but all but one `cargo
test` tests fail. Not sure if that’s because of mistakes on my part or
if the sm-hacks branch never passed those tests.
Fix build warnings
Use link_name attr for mangled function names
Handle mangled global vars
Only generate bindings for visible symbols
Don't generate arrays for blobs when the length is 1
Name enums inside classes better
Handle template args inside typedefs better
Filter out duplicate decls better
Generate correctly sized enums
Squash of...
Fix bitfield accessor method generation for bools
Insert phantom fields in empty structs
Don't mark unmangling methods as extern "C"
Add back comment support for functions
Add basic annotation support
Don't generate univariant enums
Add support for hide annotation and adjust syntax
Don't generate unsupported structs
Don't parse hidden fields
Don't derive Copy for structs with destructors
Don't implement Clone or Default
Derive Clone when deriving Copy
Bypass single member unions
Disable references in function args for now
Remove extra underscore in mangled names on OSX
Don't translate private methods
Support generating consts from macros that are defined as integer literals.
Handle mangling better
Squash of...
Update README.md for fork
Generate docs for enum items
Generate docs for typedefs
Generate docs for enums
Update syntex_syntax to 0.24.*
Update clang info in README.md
Spit errors and warnings to stdout.
The correct thing to do here is to use env_logger, but that was causing cargo
troubles for me, and this is preferable to swallowing them.
Add the -ignore-functions argument.
Handle 1 << 63 as enum value.
Don't try to convert standard int types in rust_type_id.
It looks like mwu added this, but I'm pretty sure it's a category error. This
function appears to be designed to reproducibly permute C identifiers so that
they don't conflict with builtin rust types. It's specifically _not_ a type
translator (which would happen at the type level, rather than the string
level), and using it as such with callers like ctypedef_to_rs causes us to
generate things like:
type u64 = u64;
While processing stdint.h, which is clearly wrong.
Stop patching in placeholder names for CompInfo and EnumInfo instances during code generator.
As best as I can tell, it's done this way (rather than my way) because bindgen tries
to recognize struct and enums typedefs of the form:
/* This is a common idiom in C, not so much in C++ */
typdef struct {
...
} Foo;
The intention, I think, is to avoid generating rust code for a struct with a placeholder
name followed by a typedef, and just give the struct the right name initially.
This seems like a reasonable goal, though not a particularly important one. However, in
my testing this never actually happens, because we end up calling unnamed_name anyway
during the GComp(ci) case of gen_mod before we get to evaluting the typedef.
So let's just remove that stuff and simplify the code. This lets us remove all the
borrow_mut calls during code generation, which seems necessary for soundness.
gen: Allow empty union members
Use full paths in generation.
Fix test compilation
parser: Add support for parsing namespaces
Partial C++ namespaces support
We currently generate the modules as expected, but we don't resolve the
names from external namespaces well.
Remove unnecesary return statements
Put namespaces behind a flag
Overall now that they aren't complete still.
Moar refactoring
Finally take rid of all the warnings
Even moar
gen: Avoid so much cloning
parser: Refactor the way submodules are stored
This way we can share the global map, while having each module custom
globals.
gen: Checkpoint before the refactoring
This actually keeps working as before.
gen: Make modules (almost) work for typedef'd types
We generate almost valid code, we just have to add some use statements.
Or maybe is a better idea to add an unintelligible name to the root
mod, and actually output a root mod plus a use root::* before.
gen: Document the current submodule approach and some desirable
alternative
gen: Make it actually compilable \o/
gen: Make the code generation usable for every type.
There's just an edge case I've detected, and it's when we remove the
instantiation of C<int>, and another module uses it, because that means
we only know of its existance in that other module.
Probably we might want to use cursor_getSemanticParent to get the real
class instead of the instantiated, but I'm not too confident about that.
Fix a corner case when a template was instantiated in another module.
Added an example of the namespace resolution.
Don't panic when not finding the specialised template
This can be annoying if filtering files out.
Straight rebase completed, let's fix that build errors
wip
Pair up with master
nits
Update AST
Add -no-rename-fields option
This is for compatibility between C bindings and C++ bindings (in C
`struct Foo` and `enum Foo`, are different, while in C++ they aren't).
wip
Add enum tests pass, and add C++ tests
Make a few more struct-related tests pass
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; |