Skip to content

Commit

Permalink
Fix logger test.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 14, 2024
1 parent 099e264 commit 6801970
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/tests/log.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
type LogFn = unsafe extern "C" fn(*const libc::c_char);

unsafe extern "C" fn test_info_callback(_msg: *const libc::c_char) {}
unsafe extern "C" fn test_error_callback(_msg: *const libc::c_char) {}

#[test]
fn can_set_logger() {
crate::set_logger(crate::LoggerType::Custom {
info: test_info_callback,
error: test_error_callback,
});
assert!(unsafe { crate::jack_sys::jack_info_callback } == Some(test_info_callback),);
assert!(unsafe { crate::jack_sys::jack_error_callback } == Some(test_error_callback),);
#[cfg(feature = "dynamic_loading")]
unsafe {
let lib = jack_sys::library().unwrap();
assert!(**lib.get::<*const LogFn>(b"jack_info_callback").unwrap() == test_info_callback);
assert!(**lib.get::<*const LogFn>(b"jack_error_callback").unwrap() == test_error_callback);
}
#[cfg(not(feature = "dynamic_loading"))]
{
assert!(unsafe { crate::jack_sys::jack_info_callback } == Some(test_info_callback),);
assert!(unsafe { crate::jack_sys::jack_error_callback } == Some(test_error_callback),);
}
super::log_to_stdio(); // Revert to enable debugging in other tests.
}

unsafe extern "C" fn test_info_callback(_msg: *const libc::c_char) {}
unsafe extern "C" fn test_error_callback(_msg: *const libc::c_char) {}

0 comments on commit 6801970

Please sign in to comment.