99 lines
3.8 KiB
Rust
99 lines
3.8 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn splash_downloads_resume_after_a_network_error_and_only_fetch_new_champions() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG[..3]);
|
|
let failure = source.card_failure();
|
|
let splash_calls = source.splash_calls.clone();
|
|
let loading_calls = source.card_counter();
|
|
let tracker = reopen(dir.path(), source);
|
|
|
|
let mut attempts = Vec::new();
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |saved| {
|
|
attempts.push(saved);
|
|
// Three cards, then one splash. The next splash loses the network.
|
|
if attempts.len() == 4 {
|
|
failure.store(true, Ordering::SeqCst);
|
|
}
|
|
})
|
|
.unwrap();
|
|
assert_eq!(attempts, [true, true, true, true, false]);
|
|
assert_eq!(splash_calls.load(Ordering::SeqCst), 2);
|
|
assert_eq!(loading_calls.load(Ordering::SeqCst), 3);
|
|
let first = statistics(&tracker)
|
|
.rows
|
|
.into_iter()
|
|
.filter_map(|r| r.splash)
|
|
.collect::<Vec<_>>();
|
|
assert_eq!(first.len(), 1);
|
|
// (59 + 40/2, 6 + 0.30*60) in a 112 x 75 splash.
|
|
assert!(
|
|
first[0].focus.x.abs_diff(71) <= 1 && first[0].focus.y.abs_diff(32) <= 1,
|
|
"{:?}",
|
|
first[0].focus
|
|
);
|
|
assert_eq!(std::fs::read(&first[0].path).unwrap(), common::splash_art());
|
|
|
|
drop(tracker);
|
|
let next = FakeChampions::new("2", &CATALOG[..4]);
|
|
let calls = next.splash_calls.clone();
|
|
let loading_calls = next.card_counter();
|
|
let tracker = reopen(dir.path(), next);
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |ok| assert!(ok))
|
|
.unwrap();
|
|
let splashes = statistics(&tracker)
|
|
.rows
|
|
.into_iter()
|
|
.filter_map(|r| r.splash)
|
|
.collect::<Vec<_>>();
|
|
assert_eq!(splashes.len(), 4);
|
|
assert!(splashes.contains(&first[0]));
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |_| panic!("already cached"))
|
|
.unwrap();
|
|
assert_eq!(calls.load(Ordering::SeqCst), 3);
|
|
assert_eq!(loading_calls.load(Ordering::SeqCst), 3);
|
|
}
|
|
|
|
#[test]
|
|
fn missing_loading_art_still_saves_the_original_splash_once_with_fixed_focus() {
|
|
for cached_card in [false, true] {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let catalog = &CATALOG[..1];
|
|
if cached_card {
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1", catalog));
|
|
tracker.refresh_champions().unwrap();
|
|
tracker.refresh_card_portraits(&mut |_| {}).unwrap();
|
|
}
|
|
let source = FakeChampions::new("1", catalog).without_portrait("Annie");
|
|
let calls = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
let splash = statistics(&tracker).rows.remove(0).splash.unwrap();
|
|
assert_eq!((splash.focus.x, splash.focus.y), (50, 30));
|
|
assert_eq!(std::fs::read(splash.path).unwrap(), common::splash_art());
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_temporarily_unreadable_loading_image_is_retried_before_caching_the_splash() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG[..1]).with_card_art(b"not a JPEG".to_vec());
|
|
let splash_calls = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_none()));
|
|
assert_eq!(splash_calls.load(Ordering::SeqCst), 0);
|
|
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1", &CATALOG[..1]));
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |saved| assert!(saved))
|
|
.unwrap();
|
|
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_some()));
|
|
}
|