Skip to content

Commit

Permalink
Fix metadata tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 9, 2024
1 parent 1675357 commit 21268f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
11 changes: 5 additions & 6 deletions src/client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,14 @@ impl Client {
let handler = Box::into_raw(Box::new(handler));
unsafe {
self.2 = Some(Box::from_raw(handler));
if j::jack_set_property_change_callback(
let res = j::jack_set_property_change_callback(
self.raw(),
Some(crate::properties::property_changed::<H>),
std::mem::transmute::<_, _>(handler),
) == 0
{
Ok(())
} else {
Err(Error::UnknownError)
);
match res {
0 => Ok(()),
error_code => Err(Error::UnknownError { error_code }),
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ mod metadata {
}
}

//helper to map 0 return to Ok
// Helper to map 0 return to Ok
fn map_error<F: FnOnce() -> ::libc::c_int>(func: F) -> Result<(), Error> {
if func() == 0 {
Ok(())
} else {
Err(Error::UnknownError)
match func() {
0 => Ok(()),
error_code => Err(Error::UnknownError { error_code }),
}
}

Expand Down Expand Up @@ -307,7 +306,7 @@ mod metadata {
pub fn property_remove_subject(&self, subject: uuid) -> Result<(), Error> {
unsafe {
if j::jack_remove_properties(self.raw(), subject) == -1 {
Err(Error::UnknownError)
Err(Error::UnknownError { error_code: -1 })
} else {
Ok(())
}
Expand Down Expand Up @@ -418,10 +417,10 @@ mod metadata {
assert_eq!(None, c1.property_get(c1.uuid(), "mutant"));

//second time, error
assert_eq!(
Err(Error::UnknownError),
c2.property_remove(c1.uuid(), "mutant")
);
assert!(matches!(
c2.property_remove(c1.uuid(), "mutant"),
Err(Error::UnknownError { .. })
));

assert_eq!(Some(prop1), c2.property_get(c2.uuid(), "blah"));
assert_eq!(Some(prop2), c2.property_get(c2.uuid(), "mutant"));
Expand Down

0 comments on commit 21268f3

Please sign in to comment.