diff --git a/tests/expectations/tests/array_pointers.rs b/tests/expectations/tests/array_pointers.rs new file mode 100644 index 0000000000..a8d9990a41 --- /dev/null +++ b/tests/expectations/tests/array_pointers.rs @@ -0,0 +1,21 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn test_fn( + a: f32, + arr: *mut ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn test_fn2( + arr: *const f32, + b: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} \ No newline at end of file diff --git a/tests/headers/array_pointers.h b/tests/headers/array_pointers.h new file mode 100644 index 0000000000..9028c43d5d --- /dev/null +++ b/tests/headers/array_pointers.h @@ -0,0 +1,4 @@ + +int test_fn(float a, int arr[20]); + +int test_fn2(const float arr[20], int b); \ No newline at end of file diff --git a/tests/tests.rs b/tests/tests.rs index ee4783ebd9..095b5a8767 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -466,3 +466,47 @@ fn dump_preprocessed_input() { "cpp-empty-layout.hpp is in the preprocessed file" ); } + + +#[test] +fn test_array_pointers() { + let actual = builder() + .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/array_pointers.h")) + .array_pointers(true) + .generate() + .unwrap() + .to_string(); + + let (actual, stderr) = rustfmt(actual); + println!("{}", stderr); + + let (expected, _) = rustfmt(r#"/* automatically generated by rust-bindgen */ + +extern "C" { + pub fn test_fn( + a: f32, + arr: *mut [::std::os::raw::c_int; 20usize], + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn test_fn2( + arr: *const [f32; 20usize], + b: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +"#.to_string()); + + if actual != expected { + println!("Generated bindings differ from expected!"); + + for diff in diff::lines(&actual, &expected) { + match diff { + diff::Result::Left(l) => println!("-{}", l), + diff::Result::Both(l, _) => println!(" {}", l), + diff::Result::Right(r) => println!("+{}", r), + } + } + + panic!(); + } +} \ No newline at end of file