Skip to content

Commit

Permalink
Start client tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 13, 2024
1 parent 0551d4f commit e32d25d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
test-threads = 1
fail-fast = false
slow-timeout = { period = "30s", terminate-after = 4 }
retries = { backoff = "fixed", count = 2, delay = "1s" }
retries = { backoff = "fixed", count = 2, delay = "500ms" }
6 changes: 0 additions & 6 deletions src/client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,11 @@ impl Client {
/// (not the process callback). The return value can be compared with the value of
/// `last_frame_time` to relate time in other threads to JACK time. To obtain better time
/// information from within the process callback, see `ProcessScope`.
///
/// # TODO
/// - test
pub fn frame_time(&self) -> Frames {
unsafe { j::jack_frame_time(self.raw()) }
}

/// The estimated time in microseconds of the specified frame time
///
/// # TODO
/// - Improve test
pub fn frames_to_time(&self, n_frames: Frames) -> Time {
unsafe { j::jack_frames_to_time(self.raw(), n_frames) }
}
Expand Down
29 changes: 28 additions & 1 deletion src/tests/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#[test]
fn can_open_client() {
fn client_can_open() {
let (client, status) =
crate::Client::new("my new client", crate::ClientOptions::empty()).unwrap();
assert_eq!(status, crate::ClientStatus::empty());
assert_eq!(client.name(), "my new client");
assert_ne!(client.sample_rate(), 0);
assert_ne!(client.buffer_size(), 0);
assert_ne!(client.uuid_string(), "");
}

#[test]
fn time_is_montonically_increasing() {
let (client, _) = crate::Client::new("time client", crate::ClientOptions::empty()).unwrap();

let t0 = client.time();
let frames0 = client.frames_since_cycle_start();
let frame_time0 = client.frame_time();

std::thread::sleep(std::time::Duration::from_millis(50));
assert_ne!(client.time(), t0);
assert_ne!(client.frames_since_cycle_start(), frames0);
assert_ne!(client.frame_time(), frame_time0);
}

#[test]
fn frame_and_time_and_convertable() {
let (client, _) = crate::Client::new("frame times", crate::ClientOptions::empty()).unwrap();
let sample_rate = client.sample_rate();
assert_eq!(
(client.frames_to_time(1) - client.frames_to_time(0)) as f64,
(1_000_000.0 / sample_rate as f64).round()
);
}

0 comments on commit e32d25d

Please sign in to comment.