1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* This file is a part of RSPlayer
* Licensed under the GPL-3.0 License
* Copyright (C) 2026 Salmonik @ salmonik@tuta.io
* https://codeberg.org/salmonik/RSPlayer
*/
use std::path::PathBuf;
use rsp::daemon::ScrobbleState;
use rsp::queue::Track;
#[test]
fn test_scrobble_state_new() {
let s = ScrobbleState::new();
assert!(s.track.is_none());
assert!(s.start_time.is_none());
assert!(s.timestamp.is_none());
}
#[test]
fn test_scrobble_state_clear() {
let mut s = ScrobbleState::new();
let t = Track {
path: PathBuf::from("/test/song.mp3"),
title: Some("Test".into()),
artist: Some("Artist".into()),
album: None,
track_number: None,
duration_secs: Some(200.0),
is_stream: false,
};
s.start(t);
assert!(s.track.is_some());
s.clear();
assert!(s.track.is_none());
assert!(s.start_time.is_none());
assert!(s.timestamp.is_none());
}
#[test]
fn test_should_scrobble_without_track_returns_false() {
assert!(!ScrobbleState::new().should_scrobble());
}
#[test]
fn test_should_scrobble_threshold_below_30_seconds() {
assert!(!ScrobbleState::should_scrobble_with_params(29, Some(200.0)));
}
#[test]
fn test_should_scrobble_threshold_half_duration() {
assert!(ScrobbleState::should_scrobble_with_params(100, Some(200.0)));
}
#[test]
fn test_should_scrobble_threshold_below_half_duration() {
assert!(!ScrobbleState::should_scrobble_with_params(80, Some(200.0)));
}
#[test]
fn test_should_scrobble_threshold_capped_at_4min() {
assert!(ScrobbleState::should_scrobble_with_params(240, Some(600.0)));
assert!(!ScrobbleState::should_scrobble_with_params(
239,
Some(600.0)
));
}
#[test]
fn test_should_scrobble_no_duration_requires_4min() {
assert!(ScrobbleState::should_scrobble_with_params(240, None));
assert!(!ScrobbleState::should_scrobble_with_params(239, None));
}
#[test]
fn test_should_scrobble_short_song() {
assert!(ScrobbleState::should_scrobble_with_params(30, Some(60.0)));
assert!(!ScrobbleState::should_scrobble_with_params(15, Some(60.0)));
}
|