Skip to content

Commit

Permalink
Added tests for array pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed May 20, 2019
1 parent 482e29a commit d4e2885
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/expectations/tests/array_pointers.rs
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 4 additions & 0 deletions tests/headers/array_pointers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

int test_fn(float a, int arr[20]);

int test_fn2(const float arr[20], int b);
44 changes: 44 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
}

0 comments on commit d4e2885

Please sign in to comment.