Skip to content

Commit

Permalink
Added C variadic test (#508)
Browse files Browse the repository at this point in the history
Test that foreign C functions with variadic argument lists can be mocked.
The variadic arguments won't be accessible to the matchers or returners, however.
  • Loading branch information
Enes1313 authored Aug 2, 2023
1 parent 1adf23c commit 31709a1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mockall/tests/automock_foreign_c_variadic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// vim: tw=80
#![cfg_attr(feature = "nightly", feature(c_variadic))]
#![deny(warnings)]

#[cfg(feature = "nightly")]
use mockall::*;

#[automock]
#[cfg(feature = "nightly")]
pub mod ffi {
extern "C" {
pub fn foo(x: i32, y: i32, ...) -> i32;
}
}

#[test]
#[cfg(feature = "nightly")]
fn mocked_c_variadic() {
let ctx = mock_ffi::foo_context();
ctx.expect().returning(|x, y| x * y);
assert_eq!(6, unsafe{mock_ffi::foo(2, 3, 1, 4, 1)});
}

0 comments on commit 31709a1

Please sign in to comment.