diff options
| author | salmonik <salmonik@noreply.codeberg.org> | 2026-06-06 19:07:09 +0200 |
|---|---|---|
| committer | salmonik <salmonik@noreply.codeberg.org> | 2026-06-06 19:07:09 +0200 |
| commit | 385c2a38eba689154b46d515f6a3a010c34d3119 (patch) | |
| tree | 8916681bafc9822ef371f949a176cf22307d2a2e /tests/daemon.rs | |
| parent | add verbosity to `rsp scan` (diff) | |
| parent | delete not needed md file (diff) | |
| download | rsplayer-385c2a38eba689154b46d515f6a3a010c34d3119.tar.gz rsplayer-385c2a38eba689154b46d515f6a3a010c34d3119.zip | |
Merge pull request 'autocompletion' (#1) from autocompletion into main
Reviewed-on: https://codeberg.org/salmonik/RSPlayer/pulls/1
Diffstat (limited to '')
| -rw-r--r-- | tests/daemon.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/daemon.rs b/tests/daemon.rs new file mode 100644 index 0000000..e5cb270 --- /dev/null +++ b/tests/daemon.rs | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | /* | ||
| 2 | * This file is a part of RSPlayer | ||
| 3 | * Licensed under the GPL-3.0 License | ||
| 4 | * Copyright (C) 2026 Salmonik @ salmonik@tuta.io | ||
| 5 | * https://codeberg.org/salmonik/RSPlayer | ||
| 6 | */ | ||
| 7 | |||
| 8 | use std::path::PathBuf; | ||
| 9 | |||
| 10 | use rsp::daemon::ScrobbleState; | ||
| 11 | use rsp::queue::Track; | ||
| 12 | |||
| 13 | #[test] | ||
| 14 | fn test_scrobble_state_new() { | ||
| 15 | let s = ScrobbleState::new(); | ||
| 16 | assert!(s.track.is_none()); | ||
| 17 | assert!(s.start_time.is_none()); | ||
| 18 | assert!(s.timestamp.is_none()); | ||
| 19 | } | ||
| 20 | |||
| 21 | #[test] | ||
| 22 | fn test_scrobble_state_clear() { | ||
| 23 | let mut s = ScrobbleState::new(); | ||
| 24 | let t = Track { | ||
| 25 | path: PathBuf::from("/test/song.mp3"), | ||
| 26 | title: Some("Test".into()), | ||
| 27 | artist: Some("Artist".into()), | ||
| 28 | album: None, | ||
| 29 | duration_secs: Some(200.0), | ||
| 30 | is_stream: false, | ||
| 31 | }; | ||
| 32 | s.start(t); | ||
| 33 | assert!(s.track.is_some()); | ||
| 34 | s.clear(); | ||
| 35 | assert!(s.track.is_none()); | ||
| 36 | assert!(s.start_time.is_none()); | ||
| 37 | assert!(s.timestamp.is_none()); | ||
| 38 | } | ||
| 39 | |||
| 40 | #[test] | ||
| 41 | fn test_should_scrobble_without_track_returns_false() { | ||
| 42 | assert!(!ScrobbleState::new().should_scrobble()); | ||
| 43 | } | ||
| 44 | |||
| 45 | #[test] | ||
| 46 | fn test_should_scrobble_threshold_below_30_seconds() { | ||
| 47 | assert!(!ScrobbleState::should_scrobble_with_params(29, Some(200.0))); | ||
| 48 | } | ||
| 49 | |||
| 50 | #[test] | ||
| 51 | fn test_should_scrobble_threshold_half_duration() { | ||
| 52 | assert!(ScrobbleState::should_scrobble_with_params(100, Some(200.0))); | ||
| 53 | } | ||
| 54 | |||
| 55 | #[test] | ||
| 56 | fn test_should_scrobble_threshold_below_half_duration() { | ||
| 57 | assert!(!ScrobbleState::should_scrobble_with_params(80, Some(200.0))); | ||
| 58 | } | ||
| 59 | |||
| 60 | #[test] | ||
| 61 | fn test_should_scrobble_threshold_capped_at_4min() { | ||
| 62 | assert!(ScrobbleState::should_scrobble_with_params(240, Some(600.0))); | ||
| 63 | assert!(!ScrobbleState::should_scrobble_with_params( | ||
| 64 | 239, | ||
| 65 | Some(600.0) | ||
| 66 | )); | ||
| 67 | } | ||
| 68 | |||
| 69 | #[test] | ||
| 70 | fn test_should_scrobble_no_duration_requires_4min() { | ||
| 71 | assert!(ScrobbleState::should_scrobble_with_params(240, None)); | ||
| 72 | assert!(!ScrobbleState::should_scrobble_with_params(239, None)); | ||
| 73 | } | ||
| 74 | |||
| 75 | #[test] | ||
| 76 | fn test_should_scrobble_short_song() { | ||
| 77 | assert!(ScrobbleState::should_scrobble_with_params(30, Some(60.0))); | ||
| 78 | assert!(!ScrobbleState::should_scrobble_with_params(15, Some(60.0))); | ||
| 79 | } | ||
