Until now a collected image was a row of text, and after a restart it was not
visible at all. The collect list gains a row thumbnail, and a Gallery page
browses the whole store with filters by source, format and address, paged at
120 tiles, with a built-in viewer showing the full size beside its provenance.
Thumbnails decode straight to the width they are drawn at. That is the whole
memory story: a 4000x3000 JPEG is about 48 MB once decoded, so decoding full
size and scaling afterwards runs out of memory long before the user finishes
scrolling. The cache is bounded and owns its bitmaps, which means its capacity
has to comfortably exceed a page - a bitmap evicted while still on screen would
be disposed out from under the renderer.
Paged rather than infinite-scrolled for the same reason: how much to decode is a
decision the page should make, not one the archive's size makes for it.
Video is not previewed and will not be. Extracting a first frame means FFmpeg,
which is a media stack in exchange for one picture per tile; those tiles show a
format badge instead. The refusal happens before touching the disk, because
attempting it would be an exception per tile.
Rendering the page caught the viewer overlay being see-through: it named a brush
that does not exist, and an unresolved DynamicResource fails silently - the
property just keeps its default. That is the second silent-reference bug to
reach a screenshot, so both kinds now have guards: one resolves every
{DynamicResource} in the XAML against both themes, the other checks every
{l:Loc} key exists. Both were confirmed to fail before being kept.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using AvParser.Core.Collecting;
|
|
using AvParser.Infrastructure.Storage;
|
|
using AvParser.UI.Media;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace AvParser.UI.Tests;
|
|
|
|
/// <summary>
|
|
/// The cache's refusals.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only the paths that answer before touching a decoder are covered here: decoding needs an
|
|
/// Avalonia rendering platform, which this project deliberately does not start. The decode itself
|
|
/// is one framework call; what is worth pinning is that the cache never reaches it for content it
|
|
/// cannot handle, because doing so would mean an exception per tile.
|
|
/// </remarks>
|
|
public sealed class ThumbnailCacheTests : IDisposable
|
|
{
|
|
private readonly string _root = Path.Combine(Path.GetTempPath(), "AvParserTests", Guid.NewGuid().ToString("N"));
|
|
private readonly ThumbnailCache _cache;
|
|
|
|
public ThumbnailCacheTests()
|
|
{
|
|
var paths = new AppPaths(_root);
|
|
paths.EnsureCreated();
|
|
|
|
_cache = new ThumbnailCache(paths, NullLogger<ThumbnailCache>.Instance);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_cache.Dispose();
|
|
|
|
if (Directory.Exists(_root))
|
|
{
|
|
Directory.Delete(_root, recursive: true);
|
|
}
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(MediaKind.Mp4)]
|
|
[InlineData(MediaKind.WebM)]
|
|
public async Task A_video_is_refused_without_looking_at_the_disk(MediaKind kind)
|
|
{
|
|
var result = await _cache.GetAsync(
|
|
new string('a', 64),
|
|
".mp4",
|
|
kind,
|
|
220,
|
|
TestContext.Current.CancellationToken
|
|
);
|
|
|
|
result.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task A_missing_blob_is_a_blank_tile_rather_than_a_throw()
|
|
{
|
|
var result = await _cache.GetAsync(
|
|
new string('b', 64),
|
|
".png",
|
|
MediaKind.Png,
|
|
220,
|
|
TestContext.Current.CancellationToken
|
|
);
|
|
|
|
result.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Clearing_an_empty_cache_is_harmless() => _cache.Clear();
|
|
|
|
[Fact]
|
|
public void The_capacity_leaves_room_for_more_than_one_screenful()
|
|
{
|
|
// The cache disposes what it evicts, so a capacity near the page size would dispose
|
|
// bitmaps that are still on screen.
|
|
ThumbnailCache.Capacity.ShouldBeGreaterThan(120 * 2);
|
|
}
|
|
}
|