E3: prove di codec, rimuxaggio, fotogrammi, copie e conversione
Le prove del nucleo della tappa E3 (WP6a), con i media costruiti dalle prove: il controllo delle foto (stesso formato, HEIC/AVIF/raw, animate, CMYK e oltre 8 bit, budget di pixel), metadati nei blocchi giusti e perdite annotate, pixel identici in WEBP senza perdita; il rimuxaggio da MOV (nuovo TestVideos.Mov) e Matroska a MP4 con campioni, date, rotazione, lingua ed edit; i fotogrammi H.264 e H.265 all'istante, ogni k secondi e N in tutto; i suffissi protetti dal taglio a 240; le copie convertite, com'è con nota, adozione, «già copiato» in ogni forma, «Copia di nuovo» esatta, spazio sul convertito, fotogrammi nella cartella delle copie (FrameOnly, una copia per campione, lotti su più pagine, tetto); la conversione della libreria (perdite, rimuxaggio, doppioni, importazione delle copie convertite). Servono a fissare il comportamento di E3 prima dell'unione. Nessun codice del prodotto cambia; un limite trovato (istanti a meno di 1 ms in «N in tutto») è annotato per Alberto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d06b587806
commit
f5e12c5d74
9 files changed
+1408
-4
No files matched your search
@@ -1,7 +1,9 @@
|
||||
using System.Security.Cryptography;
|
||||
using Febe.Core.Codecs.Images;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Core.Library.Conversion;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Tests.Codecs.Containers;
|
||||
using Febe.Tests.Export.Support;
|
||||
@@ -10,8 +12,10 @@ using Febe.Tests.Support;
|
||||
namespace Febe.Tests.Export;
|
||||
|
||||
/// <summary>
|
||||
/// The copy job of tappa E3 on real folders (WP1.7): a converted copy and a frame copy. The full set of cases is WP6a's;
|
||||
/// the media are built by the tests.
|
||||
/// The copy job of tappa E3 on real folders (WP1.7): converted copies, byte copies of the same format, files copied as
|
||||
/// they are with a note, the format chosen by the request, the destination or the settings (D1), «già copiato» in any
|
||||
/// form (D3), adoption of a converted file (D10), «Copia di nuovo» of a form (D11), the space of the converted size
|
||||
/// (D17) and the file time (D18). The media are built by the tests; more frames are in <see cref="ExportFramesTests"/>.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class ExportConversionTests
|
||||
@@ -92,4 +96,312 @@ public sealed class ExportConversionTests
|
||||
Assert.AreEqual((ExportItemState.AlreadyCopied, copy.Id), (same.State, same.CopyId));
|
||||
Assert.HasCount(2, Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task JpgToJpgIsAByteCopyAndTheLibraryIsUntouched()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await FormatsAsync(bed, ExportFormat.Jpg, ct);
|
||||
var post = await bed.PostAsync(bed.Marta, "962", 33);
|
||||
var media = post.Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
var library = Fingerprint.Of(bed.Temp.Combine("libreria"));
|
||||
|
||||
var start = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
|
||||
Assert.AreEqual((1, 0, false), (start.Plan.Files, start.Plan.Converted, start.Plan.Lossy), "a JPEG to JPG is not a conversion, nor «con perdita»");
|
||||
var item = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Copied, (string?)null), (item.State, item.Note));
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Whole, ExportFormat.Original, media.Sha256), (copy.Variant, copy.Format, copy.CopySha256));
|
||||
CollectionAssert.AreEqual(await File.ReadAllBytesAsync(bed.LibraryFile(bed.Marta, media), ct), await File.ReadAllBytesAsync(bed.GeneralCopy(bed.Marta, media), ct));
|
||||
Fingerprint.AreEqual(library, Fingerprint.Of(bed.Temp.Combine("libreria")), "the library is never touched");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task APngIsConvertedToTheDestinationFormatWithItsNoteAndTime()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await FormatsAsync(bed, ExportFormat.Png, ct); // the destination's format wins over this one
|
||||
using var picture = Imaging.TestImages.Gradient(40, 30, seed: 6); // with transparent pixels
|
||||
var post = await SaveAsync(bed, bed.Marta, "963", ImageConverter.Encode(picture, ImageFormat.Png, null), ".png");
|
||||
var media = post.Media[0];
|
||||
await bed.Service.Destinations.CreateAsync(new DestinationSpec(ExportScope.General, null, bed.Usb, "Disco USB", ContentTypes.All, null, null, null, PhotoFormat: ExportFormat.Jpg), ct);
|
||||
var library = Fingerprint.Of(bed.Temp.Combine("libreria"));
|
||||
|
||||
var start = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
|
||||
Assert.AreEqual((1, 1, true), (start.Plan.Files, start.Plan.Converted, start.Plan.Lossy));
|
||||
var item = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Copied, ExportText.Notes.TransparencyWhite), (item.State, item.Note));
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Converted, ExportFormat.Jpg, media.Sha256), (copy.Variant, copy.Format, copy.SourceSha256));
|
||||
Assert.AreEqual("marta.demo/" + Path.ChangeExtension(media.RelativePath!, ".jpg"), copy.RelativePath);
|
||||
var file = Path.Combine(bed.Usb, LibraryLayout.ToPlatform(copy.RelativePath!));
|
||||
var bytes = await File.ReadAllBytesAsync(file, ct);
|
||||
CollectionAssert.AreEqual(new byte[] { 0xFF, 0xD8, 0xFF }, bytes[..3]);
|
||||
Assert.AreEqual((Convert.ToHexStringLower(SHA256.HashData(bytes)), (long?)bytes.Length), (copy.CopySha256, copy.Bytes));
|
||||
Assert.AreEqual(post.Entry.PublishedAt.UtcDateTime, File.GetLastWriteTimeUtc(file), "«libreria.data-file-pubblicazione» is on");
|
||||
Fingerprint.AreEqual(library, Fingerprint.Of(bed.Temp.Combine("libreria")), "the original stays as it is");
|
||||
|
||||
// The report lists the note, in Italian.
|
||||
var report = await bed.Service.Reports.BuildAsync(start.Runs.Single().Id, ct);
|
||||
var line = report.Notes.Single();
|
||||
Assert.AreEqual((item.Id, ExportItemState.Copied), (line.ItemId, line.State));
|
||||
Assert.AreEqual(ExportText.Note(ExportText.Notes.TransparencyWhite), line.Text);
|
||||
Assert.IsEmpty(report.Accounts.Single().AsIs);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheFormatIsTheRequestsThenTheDestinationsThenTheSettings()
|
||||
{
|
||||
var settings = ExportSettings.Default with { PhotoFormat = ExportFormat.Png, VideoFormat = ExportFormat.Mp4 };
|
||||
var destination = new ExportDestination { Id = 1, Scope = ExportScope.General, RootPath = "/copie", ContentTypes = ContentTypes.All, CreatedAt = Make.T0 };
|
||||
var jpgHere = destination with { PhotoFormat = ExportFormat.Jpg, VideoFormat = ExportFormat.Original };
|
||||
|
||||
Assert.AreEqual(ExportFormat.Png, ExportConversions.Resolve(MediaKind.Photo, null, destination, settings));
|
||||
Assert.AreEqual(ExportFormat.Mp4, ExportConversions.Resolve(MediaKind.Video, null, destination, settings));
|
||||
Assert.AreEqual(ExportFormat.Jpg, ExportConversions.Resolve(MediaKind.Photo, null, jpgHere, settings));
|
||||
Assert.AreEqual(ExportFormat.Original, ExportConversions.Resolve(MediaKind.Video, null, jpgHere, settings));
|
||||
Assert.AreEqual(ExportFormat.WebpLossless, ExportConversions.Resolve(MediaKind.Photo, new ExportFormatChoice(ExportFormat.WebpLossless, null), jpgHere, settings));
|
||||
Assert.AreEqual(ExportFormat.Mp4, ExportConversions.Resolve(MediaKind.Video, new ExportFormatChoice(null, ExportFormat.Mp4), jpgHere, settings));
|
||||
Assert.AreEqual(ExportFormat.Jpg, ExportConversions.Resolve(MediaKind.Photo, new ExportFormatChoice(ExportFormat.Mp4, null), jpgHere, settings), "a video format is not a photo's");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheRequestOverridesTheDestination()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var post = await bed.PostAsync(bed.Marta, "964", 34);
|
||||
await bed.Service.Destinations.CreateAsync(new DestinationSpec(ExportScope.General, null, bed.Usb, "Disco USB", ContentTypes.All, null, null, null, PhotoFormat: ExportFormat.Png), ct);
|
||||
|
||||
var start = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([post.Media[0].Id]), Formats: new ExportFormatChoice(ExportFormat.WebpLossless, null)), ct);
|
||||
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync((await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single().CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Converted, ExportFormat.WebpLossless), (copy.Variant, copy.Format));
|
||||
StringAssert.EndsWith(copy.RelativePath, ".webp");
|
||||
Assert.AreEqual(ImageFormat.WebP, ImageFormatSniffer.Detect(await File.ReadAllBytesAsync(Path.Combine(bed.Usb, LibraryLayout.ToPlatform(copy.RelativePath!)), ct)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task HeicIsCopiedAsItIsWithANoteAndTheReportCountsIt()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await FormatsAsync(bed, ExportFormat.Jpg, ct);
|
||||
byte[] heic = [0, 0, 0, 0x18, .. "ftypheic"u8, 0, 0, 0, 0, .. "mif1heic"u8, 0, 0, 0, 8, .. "free"u8, .. new byte[64]];
|
||||
var post = await SaveAsync(bed, bed.Marta, "965", heic, ".heic");
|
||||
var media = post.Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
var start = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
|
||||
Assert.AreEqual(new ExportPlanAsIs("HEIC", 1), start.Plan.AsIs.Single(), "predicted from the name");
|
||||
var item = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Copied, ExportText.Notes.AsIsHeif), (item.State, item.Note));
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Whole, ExportFormat.Original, media.Sha256), (copy.Variant, copy.Format, copy.CopySha256));
|
||||
CollectionAssert.AreEqual(heic, await File.ReadAllBytesAsync(bed.GeneralCopy(bed.Marta, media), ct));
|
||||
|
||||
var report = await bed.Service.Reports.BuildAsync(start.Runs.Single().Id, ct);
|
||||
Assert.AreEqual(1, report.Accounts.Single().AsIs["HEIC"]);
|
||||
Assert.AreEqual(ExportText.Note(ExportText.Notes.AsIsHeif), report.Notes.Single().Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AConvertedFileAtThePathIsAdoptedAndASameSizeDifferentFileIsNot()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await FormatsAsync(bed, ExportFormat.Jpg, ct);
|
||||
var same = await SavePngAsync(bed, "966", 35);
|
||||
var other = await SavePngAsync(bed, "967", 36);
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
// An earlier conversion of the same file (the bytes Febe makes), and one of the other file with a byte changed.
|
||||
var adopted = ConvertedPath(bed, same.Media[0], ".jpg");
|
||||
var foreign = ConvertedPath(bed, other.Media[0], ".jpg");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(adopted)!);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(foreign)!);
|
||||
var conversion = await ConvertAsync(bed, same.Media[0], ExportFormat.Jpg, ct);
|
||||
await File.WriteAllBytesAsync(adopted, conversion, ct);
|
||||
var handDate = new DateTime(2020, 5, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
File.SetLastWriteTimeUtc(adopted, handDate);
|
||||
var changed = await ConvertAsync(bed, other.Media[0], ExportFormat.Jpg, ct);
|
||||
changed[^10] ^= 0x01;
|
||||
await File.WriteAllBytesAsync(foreign, changed, ct);
|
||||
var before = Fingerprint.Of(bed.Usb);
|
||||
|
||||
var start = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
|
||||
var items = (await bed.ItemsAsync(start.Runs.Single().Id, ct)).ToDictionary(i => i.MediaId!.Value);
|
||||
var adoption = items[same.Media[0].Id];
|
||||
Assert.AreEqual(ExportItemState.Adopted, adoption.State);
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync(adoption.CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportCopyOrigin.Adopted, ExportVariant.Converted, ExportFormat.Jpg), (copy.Origin, copy.Variant, copy.Format));
|
||||
Assert.AreEqual(Convert.ToHexStringLower(SHA256.HashData(conversion)), copy.CopySha256);
|
||||
Assert.AreEqual(handDate, File.GetLastWriteTimeUtc(adopted), "adopted, not written again");
|
||||
|
||||
var written = items[other.Media[0].Id];
|
||||
Assert.AreEqual(ExportItemState.Copied, written.State);
|
||||
StringAssert.Contains(written.Note, ExportText.Notes.NameTaken);
|
||||
StringAssert.EndsWith(written.RelativePath, " (2).jpg");
|
||||
var after = Fingerprint.Of(bed.Usb);
|
||||
foreach (var (path, print) in before)
|
||||
{
|
||||
Assert.AreEqual(print, after[path], path);
|
||||
}
|
||||
|
||||
Assert.AreEqual(before.Count + 1, after.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task SpaceIsCheckedOnTheConvertedSize()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await FormatsAsync(bed, ExportFormat.Png, ct);
|
||||
var post = await bed.PostAsync(bed.Marta, "968", 37);
|
||||
var media = post.Media[0];
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
long png = (await ConvertAsync(bed, media, ExportFormat.Png, ct)).Length;
|
||||
Assert.IsGreaterThan(media.Bytes!.Value, png, "the PNG of a small JPEG is bigger");
|
||||
|
||||
bed.Disk.Free = media.Bytes!.Value + ExportSpace.Margin; // enough for the original, not for its PNG
|
||||
var start = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
var run = await bed.RunAsync(start.Runs.Single().Id, ct);
|
||||
Assert.AreEqual(ExportRunState.Paused, run.State);
|
||||
StringAssert.Contains(run.LastError, "margine di 64 MB");
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
|
||||
bed.Disk.Free = png + ExportSpace.Margin;
|
||||
await bed.Service.ResumeAsync([run.Id], ct);
|
||||
await bed.Service.WaitAsync(ct);
|
||||
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(run.Id, ct)).State);
|
||||
Assert.IsNull((await bed.Db.Exports.GetDestinationAsync(usb.Id, ct))!.PausedAt);
|
||||
Assert.AreEqual(png, (await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct)).Single().Bytes);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ARemovedWholeCopyIsNotCopiedAgainInTheNewFormatUntilAskedAndExactIgnoresOtherForms()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var post = await SavePngAsync(bed, "969", 38);
|
||||
var media = post.Media[0];
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
var first = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
var whole = (await bed.ItemsAsync(first.Runs.Single().Id, ct)).Single().CopyId!.Value;
|
||||
File.Delete(bed.GeneralCopy(bed.Marta, media));
|
||||
|
||||
// The format changes to JPG: the file was copied («Tolto» now), so it is not copied again by itself (D3).
|
||||
await FormatsAsync(bed, ExportFormat.Jpg, ct);
|
||||
var skipped = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
var item = (await bed.ItemsAsync(skipped.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Skipped, ExportText.Notes.Removed, (long?)whole), (item.State, item.Note, item.CopyId));
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
var plan = await bed.Service.PlanAsync(new ExportJobRequest(new ExportSelection.Account(bed.Marta.Id)), ct);
|
||||
Assert.AreEqual((0, 1), (plan.Files, plan.RemovedOrSuperseded));
|
||||
|
||||
// «Copia di nuovo» from the dialog writes the current form: a JPG.
|
||||
var again = await bed.CopyAccountAsync(bed.Marta, copyAgain: true, ct: ct);
|
||||
var converted = (await bed.Db.Exports.GetCopyAsync((await bed.ItemsAsync(again.Runs.Single().Id, ct)).Single().CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Converted, ExportFormat.Jpg, ExportCopyState.Copied), (converted.Variant, converted.Format, converted.State));
|
||||
Assert.AreEqual(ExportCopyState.Removed, (await bed.Db.Exports.GetCopyAsync(whole, ct))!.State);
|
||||
|
||||
// «Copia di nuovo» of the removed row from the viewer: its own form, whatever else is copied (D11).
|
||||
var exact = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([media.Id]), CopyAgain: true, Exact: new ExportCopyRequest(ExportVariant.Whole, ExportFormat.Original, null)), ct);
|
||||
var back = (await bed.ItemsAsync(exact.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual(ExportItemState.Copied, back.State);
|
||||
var restored = (await bed.Db.Exports.GetCopyAsync(back.CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Whole, ExportFormat.Original), (restored.Variant, restored.Format));
|
||||
Assert.AreNotEqual(whole, restored.Id);
|
||||
Assert.IsTrue(File.Exists(bed.GeneralCopy(bed.Marta, media)));
|
||||
Assert.HasCount(2, Fingerprint.Of(bed.Usb), "the JPG and the PNG");
|
||||
Assert.AreEqual(ExportCopyState.Copied, (await bed.Db.Exports.GetCopyAsync(converted.Id, ct))!.State);
|
||||
|
||||
// The JPG asked again exactly: «Già copiato».
|
||||
var twice = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([media.Id]), CopyAgain: true, Exact: new ExportCopyRequest(ExportVariant.Converted, ExportFormat.Jpg, null)), ct);
|
||||
var same = (await bed.ItemsAsync(twice.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.AlreadyCopied, (long?)converted.Id), (same.State, same.CopyId));
|
||||
Assert.HasCount(3, await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task OneCopyOnlyIgnoresTheFormat()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
await (ExportSettings.Default with { SamePost = SamePostCopies.OneOnly, PhotoFormat = ExportFormat.Jpg }).SaveAsync(bed.Db.Settings, ct);
|
||||
using var image = TestImages.Scene(39, 64, 48);
|
||||
var png = TestImages.Png(image);
|
||||
await SaveAsync(bed, bed.Marta, "970", png, ".png");
|
||||
await SaveAsync(bed, bed.Luca, "970", png, ".png");
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
var luca = await bed.CopyAccountAsync(bed.Luca, ct: ct);
|
||||
|
||||
var item = (await bed.ItemsAsync(luca.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.AlreadyCopied, ExportText.Notes.CopiedForAnotherAccount), (item.State, item.Note));
|
||||
Assert.AreEqual(ExportVariant.Converted, (await bed.Db.Exports.GetCopyAsync(item.CopyId!.Value, ct))!.Variant);
|
||||
Assert.HasCount(1, Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AChangedSourceFailsTheConversionAndAStaleFailedRowIsClearedLater()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
var corrupt = true;
|
||||
await using var bed = await ExportTestBed.CreateAsync(env => env with { FileSystem = new CorruptingExportFileSystem(path => corrupt && path.EndsWith(".jpg", StringComparison.Ordinal)) });
|
||||
await FormatsAsync(bed, ExportFormat.Png, ct);
|
||||
var post = await bed.PostAsync(bed.Marta, "971", 40);
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
|
||||
var failed = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
var item = (await bed.ItemsAsync(failed.Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Failed, ExportText.Notes.SourceChanged), (item.State, item.Note));
|
||||
var row = (await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct)).Single();
|
||||
Assert.AreEqual((ExportCopyState.Failed, ExportVariant.Converted, ExportFormat.Png), (row.State, row.Variant, row.Format));
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
|
||||
// The disk reads well again and the format is back to Originale: the copy is written, the old failure goes.
|
||||
corrupt = false;
|
||||
await FormatsAsync(bed, ExportFormat.Original, ct);
|
||||
var copied = await bed.CopyAccountAsync(bed.Marta, ct: ct);
|
||||
Assert.AreEqual(ExportItemState.Copied, (await bed.ItemsAsync(copied.Runs.Single().Id, ct)).Single().State);
|
||||
var copies = await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct);
|
||||
Assert.AreEqual((ExportCopyState.Copied, ExportVariant.Whole), (copies.Single().State, copies.Single().Variant), "the «Non riuscito» row of the other form has no use");
|
||||
Assert.IsTrue(File.Exists(bed.GeneralCopy(bed.Marta, post.Media[0])));
|
||||
}
|
||||
|
||||
private static Task FormatsAsync(ExportTestBed bed, ExportFormat photo, CancellationToken ct) =>
|
||||
(ExportSettings.Default with { PhotoFormat = photo }).SaveAsync(bed.Db.Settings, ct);
|
||||
|
||||
private static Task<EntryWithMedia> SaveAsync(ExportTestBed bed, Account account, string code, byte[] bytes, string extension) =>
|
||||
bed.Library.SaveAsync(account, Make.Entry(account.Id, code, Make.T0.AddDays(-1)), [new TestFile(Make.Photo(1), bytes, extension)]);
|
||||
|
||||
private static Task<EntryWithMedia> SavePngAsync(ExportTestBed bed, string code, int scene)
|
||||
{
|
||||
using var image = TestImages.Scene(scene, 64, 48);
|
||||
return SaveAsync(bed, bed.Marta, code, TestImages.Png(image), ".png");
|
||||
}
|
||||
|
||||
/// <summary>Where the general folder gets the converted copy of a file of marta.demo.</summary>
|
||||
private static string ConvertedPath(ExportTestBed bed, Media media, string extension) =>
|
||||
Path.Combine(bed.Usb, bed.Marta.Username, LibraryLayout.ToPlatform(Path.ChangeExtension(media.RelativePath!, extension)));
|
||||
|
||||
/// <summary>The bytes Febe makes of a library file in a format.</summary>
|
||||
private static async Task<byte[]> ConvertAsync(ExportTestBed bed, Media media, ExportFormat format, CancellationToken ct)
|
||||
{
|
||||
var path = bed.LibraryFile(bed.Marta, media);
|
||||
using var conversion = await MediaConverter.PrepareAsync(() => File.OpenRead(path), media.RelativePath!, media.Kind, format, media.Sha256!, new ConversionThrottle(), ct);
|
||||
Assert.AreEqual(ExportVariant.Converted, conversion.Variant);
|
||||
using var output = new MemoryStream();
|
||||
await conversion.Produce!(output, ct);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Domain;
|
||||
using Febe.Core.Export;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Tests.Codecs.Containers;
|
||||
using Febe.Tests.Export.Support;
|
||||
using Febe.Tests.Support;
|
||||
|
||||
namespace Febe.Tests.Export;
|
||||
|
||||
/// <summary>
|
||||
/// «Fotogrammi…» → «Nella cartella delle copie» (tappa E3, D4 and D12-D14): frames go to the destination of each
|
||||
/// account with their suffix, one copy per frame shown, never making the video «Copiato»; photos, accounts that are not
|
||||
/// exported and videos without frames are skipped; the job waits for engine sessions; a removed frame is written again
|
||||
/// on request; a request over the cap is refused before anything is recorded. The videos are built by the tests.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class ExportFramesTests
|
||||
{
|
||||
private static readonly ElementaryStream Stream = ElementaryStream.Load("BA1_Sony_D");
|
||||
private static readonly byte[] Mp4 = TestVideos.Mp4(Stream);
|
||||
|
||||
public TestContext TestContext { get; set; } = null!;
|
||||
|
||||
[TestMethod]
|
||||
public async Task FramesGoToTheDestinationWithTheirSuffixes()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var duration = TimeSpan.FromMilliseconds((long)Duration(Mp4).TotalMilliseconds); // as the library keeps it
|
||||
var video = (await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "990", Make.T0.AddDays(-2)), [
|
||||
new TestFile(Make.Video(1) with { Duration = duration }, Mp4, ".mp4"),
|
||||
])).Media[0];
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
|
||||
// «N in tutto»: _f001…_f003, PNG.
|
||||
var count = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Count, null, null, 3, ExportFormat.Png)), ct);
|
||||
Assert.AreEqual((1, 3, 3), (count.Plan.Videos, count.Plan.Frames, count.Plan.Files));
|
||||
Assert.AreEqual(0L, count.Plan.Bytes, "frames have no size before they are made");
|
||||
var items = await bed.ItemsAsync(count.Runs.Single().Id, ct);
|
||||
Assert.IsTrue(items.All(i => i.State == ExportItemState.Copied && i.Variant == ExportVariant.Frame && i.Format == ExportFormat.Png));
|
||||
CollectionAssert.AreEqual(
|
||||
ExportFrames.Spread(duration, 3).Select(t => (TimeSpan?)TimeSpan.FromMilliseconds((long)t.TotalMilliseconds)).ToArray(),
|
||||
items.Select(i => i.FrameAt).ToArray(),
|
||||
"the item keeps the instant asked (in milliseconds)");
|
||||
var stem = Path.ChangeExtension(video.RelativePath!, null);
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "_f001", "_f002", "_f003" }.Select(s => "marta.demo/" + stem + s + ".png").ToArray(),
|
||||
items.Select(i => i.RelativePath).ToArray());
|
||||
|
||||
// «Uno ogni k secondi»: the actual instant of the frame shown, rounded up to the millisecond, in the name and the row.
|
||||
var every = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Every, null, TimeSpan.FromMilliseconds(250), null, ExportFormat.Jpg)), ct);
|
||||
var shown = Locate(Mp4, ExportFrames.Every(duration, TimeSpan.FromMilliseconds(250)));
|
||||
var frames = await bed.ItemsAsync(every.Runs.Single().Id, ct);
|
||||
Assert.HasCount(shown.Count, frames);
|
||||
for (var i = 0; i < shown.Count; i++)
|
||||
{
|
||||
var copy = (await bed.Db.Exports.GetCopyAsync(frames[i].CopyId!.Value, ct))!;
|
||||
Assert.AreEqual((ExportVariant.Frame, ExportFormat.Jpg, video.Sha256), (copy.Variant, copy.Format, copy.SourceSha256));
|
||||
Assert.AreEqual(TimeSpan.FromMilliseconds(ExportFrames.ActualMs(shown[i].Actual)), copy.FrameAt);
|
||||
Assert.AreEqual("marta.demo/" + stem + ExportFrames.Suffix(FrameMode.Every, shown[i].Actual, i, shown.Count) + ".jpg", copy.RelativePath);
|
||||
var bytes = await File.ReadAllBytesAsync(Path.Combine(bed.Usb, LibraryLayout.ToPlatform(copy.RelativePath!)), ct);
|
||||
CollectionAssert.AreEqual(new byte[] { 0xFF, 0xD8, 0xFF }, bytes[..3]);
|
||||
}
|
||||
|
||||
StringAssert.EndsWith(frames[0].RelativePath, "_t0m00s000.jpg");
|
||||
Assert.HasCount(3 + shown.Count, Fingerprint.Of(bed.Usb));
|
||||
Assert.IsTrue(every.Plan.Lossy, "JPG frames are «con perdita»");
|
||||
Assert.IsFalse(count.Plan.Lossy);
|
||||
Assert.IsTrue(File.Exists(bed.LibraryFile(bed.Marta, video)));
|
||||
Assert.HasCount(3 + shown.Count, await bed.Db.Exports.ListCopiesAsync(usb.Id, ct: ct));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TheSameFrameShownIsCopiedOnceAndABatchSpansPages()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var still = TestVideos.Mp4(Stream.FirstPictureRepeated(30)); // one second, 30 samples
|
||||
var video = (await SaveVideoAsync(bed, bed.Marta, "991", still, ".mp4")).Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
// 600 instants (more than a page of the copier, at least a millisecond apart) on 30 frames: each frame shown once.
|
||||
const int N = 600;
|
||||
var targets = Locate(still, ExportFrames.Spread(Duration(still), N));
|
||||
var leaders = targets.Select((t, i) => (t.Sample, i)).GroupBy(x => x.Sample).Select(g => g.First().i).ToList();
|
||||
Assert.HasCount(30, leaders);
|
||||
|
||||
var start = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Count, null, null, N, ExportFormat.Png)), ct);
|
||||
|
||||
var items = await bed.ItemsAsync(start.Runs.Single().Id, ct);
|
||||
Assert.HasCount(N, items);
|
||||
Assert.AreEqual(leaders.Count, items.Count(i => i.State == ExportItemState.Copied));
|
||||
Assert.AreEqual(N - leaders.Count, items.Count(i => i.State == ExportItemState.AlreadyCopied));
|
||||
Assert.HasCount(leaders.Count, Fingerprint.Of(bed.Usb));
|
||||
var stem = Path.ChangeExtension(video.RelativePath!, null);
|
||||
foreach (var k in leaders)
|
||||
{
|
||||
Assert.AreEqual("marta.demo/" + stem + ExportFrames.Suffix(FrameMode.Count, targets[k].Actual, k, N) + ".png", items[k].RelativePath, $"frame {k}");
|
||||
}
|
||||
|
||||
// A follower points at its leader's copy.
|
||||
for (var k = 0; k < N; k++)
|
||||
{
|
||||
Assert.AreEqual(items[leaders.First(l => targets[l].Sample == targets[k].Sample)].CopyId, items[k].CopyId, $"item {k}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task FramesDoNotMakeTheFileCopied()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var post = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "992", Make.T0.AddDays(-2)), [
|
||||
new TestFile(Make.Video(1) with { Duration = null }, Mp4, ".mp4"),
|
||||
new TestFile(Make.Video(2) with { Duration = null }, TestVideos.Mov(Stream), ".mov"),
|
||||
]);
|
||||
var (first, second) = (post.Media[0], post.Media[1]);
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
|
||||
await bed.CopyAsync(Frames(first, new ExportFramesRequest(FrameMode.At, TimeSpan.FromMilliseconds(300), null, null, ExportFormat.Png)), ct);
|
||||
|
||||
Assert.AreEqual(new ExportEntryCopies(2, 0, 1), (await bed.Db.Exports.GetEntryCopyCountsAsync([post.Entry.Id], ct))[post.Entry.Id]);
|
||||
Assert.AreEqual(ExportMark.FrameOnly, (await bed.Db.Exports.GetEntryMarksAsync([post.Entry.Id], ct))[post.Entry.Id]);
|
||||
var files = await bed.Db.Exports.GetFileMarksAsync([first.Id, second.Id], ct);
|
||||
Assert.AreEqual((ExportMark.FrameOnly, ExportMark.None), (files[first.Id], files[second.Id]));
|
||||
Assert.IsTrue((await EntriesAsync(bed, LibraryCopiesFilter.NotCopied, ct)).Contains(post.Entry.Id), "still «Non ancora copiato»");
|
||||
Assert.IsFalse((await EntriesAsync(bed, LibraryCopiesFilter.Copied, ct)).Contains(post.Entry.Id));
|
||||
Assert.AreEqual(2, (await bed.Db.Exports.CountAccountFilesAsync(bed.Marta.Id, ct)).NotCopied);
|
||||
|
||||
// The second video copied whole: «Copiato in parte», the first one is still not copied.
|
||||
await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Media([second.Id])), ct);
|
||||
Assert.AreEqual(new ExportEntryCopies(2, 1, 1), (await bed.Db.Exports.GetEntryCopyCountsAsync([post.Entry.Id], ct))[post.Entry.Id]);
|
||||
Assert.AreEqual(ExportMark.Partly, (await bed.Db.Exports.GetEntryMarksAsync([post.Entry.Id], ct))[post.Entry.Id]);
|
||||
Assert.AreEqual(1, (await bed.Db.Exports.CountAccountFilesAsync(bed.Marta.Id, ct)).NotCopied);
|
||||
|
||||
// «Copia in…» of the entry copies the first video whole (the frame does not count) and nothing else.
|
||||
var whole = await bed.CopyAsync(new ExportJobRequest(new ExportSelection.Entries([post.Entry.Id])), ct);
|
||||
Assert.AreEqual((1, 1), (whole.Plan.Files, whole.Plan.AlreadyCopied));
|
||||
Assert.AreEqual(ExportMark.Copied, (await bed.Db.Exports.GetEntryMarksAsync([post.Entry.Id], ct))[post.Entry.Id]);
|
||||
Assert.HasCount(3, Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PhotosAccountsNotExportedAndVideosWithoutFramesAreSkipped()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var mixed = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "993", Make.T0.AddDays(-2)), [
|
||||
ExportTestBed.Photo(1, 50),
|
||||
new TestFile(Make.Video(2) with { Duration = null }, Mp4, ".mp4"),
|
||||
]);
|
||||
var noise = await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "994", Make.T0.AddDays(-3)), [TestFile.Video(1, 4000)]);
|
||||
var luca = await SaveVideoAsync(bed, bed.Luca, "995", TestVideos.Mov(Stream), ".mov");
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
await bed.Service.Destinations.SetAccountEnabledAsync(bed.Luca.Id, false, ct);
|
||||
|
||||
var request = new ExportJobRequest(
|
||||
new ExportSelection.Entries([mixed.Entry.Id, noise.Entry.Id, luca.Entry.Id]),
|
||||
Frames: new ExportFramesRequest(FrameMode.At, TimeSpan.Zero, null, null, ExportFormat.Png));
|
||||
var start = await bed.CopyAsync(request, ct);
|
||||
|
||||
Assert.AreEqual((1, 1, 2), (start.Plan.PhotosSkipped, start.Plan.NotExported, start.Plan.Videos));
|
||||
var items = await bed.ItemsAsync(start.Runs.Single().Id, ct);
|
||||
Assert.HasCount(2, items, "no item for the photo, nor for the account that is not exported");
|
||||
Assert.AreEqual(ExportItemState.Copied, items.Single(i => i.MediaId == mixed.Media[1].Id).State);
|
||||
var unavailable = items.Single(i => i.MediaId == noise.Media[0].Id);
|
||||
Assert.AreEqual((ExportItemState.Skipped, ExportText.Notes.FrameNotAvailable, (long?)null), (unavailable.State, unavailable.Note, unavailable.CopyId));
|
||||
Assert.AreEqual("Fotogramma non disponibile per questo video", ExportText.Note(unavailable.Note));
|
||||
Assert.HasCount(1, Fingerprint.Of(bed.Usb));
|
||||
Assert.HasCount(1, await bed.Db.Exports.ListCopiesAsync(start.Runs.Single().DestinationId, ct: ct), "no copy row for a frame that is not there");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AFramesJobWaitsForTheEngineSession()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync(env => env with { Session = new CountedSession(3) });
|
||||
var video = (await SaveVideoAsync(bed, bed.Marta, "996", Mp4, ".mp4")).Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
var before = bed.Clock.Now;
|
||||
|
||||
var start = await bed.CopyAsync(Frames(video, new ExportFramesRequest(FrameMode.Count, null, null, 2, ExportFormat.Png)), ct);
|
||||
|
||||
Assert.AreEqual(ExportRunState.Completed, (await bed.RunAsync(start.Runs.Single().Id, ct)).State);
|
||||
Assert.IsGreaterThanOrEqualTo(before + TimeSpan.FromSeconds(10), bed.Clock.Now, "polled while the session ran");
|
||||
Assert.HasCount(2, Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ARemovedFrameIsWrittenAgainOnRequest()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var video = (await SaveVideoAsync(bed, bed.Marta, "997", Mp4, ".mp4")).Media[0];
|
||||
var usb = await bed.GeneralAsync(ct: ct);
|
||||
var request = Frames(video, new ExportFramesRequest(FrameMode.At, TimeSpan.FromMilliseconds(400), null, null, ExportFormat.WebpLossless));
|
||||
var first = (await bed.ItemsAsync((await bed.CopyAsync(request, ct)).Runs.Single().Id, ct)).Single();
|
||||
var path = Path.Combine(bed.Usb, LibraryLayout.ToPlatform(first.RelativePath!));
|
||||
var bytes = await File.ReadAllBytesAsync(path, ct);
|
||||
File.Delete(path);
|
||||
await bed.Service.CheckCopiesAsync(usb.Id, ct);
|
||||
await bed.Service.WaitAsync(ct);
|
||||
Assert.AreEqual(ExportCopyState.Removed, (await bed.Db.Exports.GetCopyAsync(first.CopyId!.Value, ct))!.State);
|
||||
|
||||
// An explicit frames request writes it again (D14), without «Copia di nuovo»: the same bytes, a new row.
|
||||
var second = (await bed.ItemsAsync((await bed.CopyAsync(request, ct)).Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.Copied, first.RelativePath), (second.State, second.RelativePath));
|
||||
Assert.AreNotEqual(first.CopyId, second.CopyId);
|
||||
CollectionAssert.AreEqual(bytes, await File.ReadAllBytesAsync(path, ct), "the same frame gives the same bytes");
|
||||
Assert.AreEqual(ExportCopyState.Removed, (await bed.Db.Exports.GetCopyAsync(first.CopyId!.Value, ct))!.State);
|
||||
|
||||
// Asked once more while it is there: «Già copiato».
|
||||
var third = (await bed.ItemsAsync((await bed.CopyAsync(request, ct)).Runs.Single().Id, ct)).Single();
|
||||
Assert.AreEqual((ExportItemState.AlreadyCopied, second.CopyId), (third.State, third.CopyId));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task OverTheCapIsRefusedBeforeAnythingIsRecorded()
|
||||
{
|
||||
var ct = TestContext.CancellationToken;
|
||||
await using var bed = await ExportTestBed.CreateAsync();
|
||||
var video = (await bed.Library.SaveAsync(bed.Marta, Make.Entry(bed.Marta.Id, "998", Make.T0.AddDays(-2)), [
|
||||
new TestFile(Make.Video(1) with { Duration = TimeSpan.FromSeconds(200) }, Mp4, ".mp4"),
|
||||
])).Media[0];
|
||||
await bed.GeneralAsync(ct: ct);
|
||||
var request = Frames(video, new ExportFramesRequest(FrameMode.Every, null, TimeSpan.FromMilliseconds(100), null, ExportFormat.Png));
|
||||
|
||||
Assert.AreEqual(1, (await bed.Service.PlanAsync(request, ct)).OverCap);
|
||||
var refused = await Assert.ThrowsExactlyAsync<ArgumentException>(() => bed.Service.StartAsync(request, ct));
|
||||
StringAssert.StartsWith(refused.Message, ExportFrames.OverCapMessage);
|
||||
Assert.IsEmpty(await bed.Db.Exports.ListRunsAsync(ct));
|
||||
Assert.IsEmpty(Fingerprint.Of(bed.Usb));
|
||||
}
|
||||
|
||||
private static ExportJobRequest Frames(Media video, ExportFramesRequest frames) => new(new ExportSelection.Media([video.Id]), Frames: frames);
|
||||
|
||||
/// <summary>A video whose length the library does not know (it is read when the job is recorded).</summary>
|
||||
private static Task<EntryWithMedia> SaveVideoAsync(ExportTestBed bed, Account account, string code, byte[] bytes, string extension) =>
|
||||
bed.Library.SaveAsync(account, Make.Entry(account.Id, code, Make.T0.AddDays(-2)), [new TestFile(Make.Video(1) with { Duration = null }, bytes, extension)]);
|
||||
|
||||
private static TimeSpan Duration(byte[] video)
|
||||
{
|
||||
using var stream = new MemoryStream(video);
|
||||
using var reader = VideoFrameReader.Open(stream, out var info);
|
||||
Assert.IsTrue(info.Available);
|
||||
return info.Duration;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<VideoFrameTarget> Locate(byte[] video, IReadOnlyList<TimeSpan> instants)
|
||||
{
|
||||
using var stream = new MemoryStream(video);
|
||||
using var reader = VideoFrameReader.Open(stream, out _);
|
||||
return reader.Locate(instants);
|
||||
}
|
||||
|
||||
private static async Task<List<long>> EntriesAsync(ExportTestBed bed, LibraryCopiesFilter filter, CancellationToken ct) =>
|
||||
[.. (await bed.Db.Entries.QueryLibraryAsync(new LibraryQuery { Filter = new LibraryFilter { Copies = filter } }, ct)).Tiles.Select(t => t.EntryId)];
|
||||
|
||||
/// <summary>An engine session for the first <paramref name="polls"/> looks, then none.</summary>
|
||||
private sealed class CountedSession(int polls) : IEngineSessionState
|
||||
{
|
||||
private int _left = polls;
|
||||
|
||||
public bool InSession => Interlocked.Decrement(ref _left) >= 0;
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,53 @@ public sealed class ExportPathsTests
|
||||
Assert.IsLessThanOrEqualTo(WindowsFileNames.MaxPathLength, Path.TrimEndingDirectorySeparator(root).Length + 1 + numbered.Length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheTargetExtensionReplacesTheSourceOneAndAFrameSuffixFollowsTheStem()
|
||||
{
|
||||
// Tappa E3 (WP1.8): a converted copy takes the extension of its format, a frame adds its suffix before it.
|
||||
var asJpg = new ExportNameOptions(".jpg", null);
|
||||
var png = Photo(1) with { RelativePath = "post/2026/vecchio_1.PNG" };
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "marta.demo", "post", "2026", "2026-10-13_10-00-00_C500_1.jpg" },
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), png, null, false, TestZones.Rome, asJpg).ToArray());
|
||||
var frame = new ExportNameOptions(".png", "_t0m01s250");
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "marta.demo", "post", "2026", "2026-10-13_10-00-00_C500_1_t0m01s250.png" },
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), png, null, false, TestZones.Rome, frame).ToArray());
|
||||
|
||||
// A file of «importati/» keeps its name, with the extension swapped too.
|
||||
var imported = Photo(1) with { RelativePath = "importati/vacanze/IMG 0001.HEIC.mov" };
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "marta.demo", "importati", "vacanze", "IMG 0001.HEIC.mp4" },
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), imported, null, false, TestZones.Rome, new ExportNameOptions(".mp4", null)).ToArray());
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { "marta.demo", "importati", "vacanze", "IMG 0001.HEIC_f001.png" },
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), imported, null, false, TestZones.Rome, new ExportNameOptions(".png", "_f001")).ToArray());
|
||||
|
||||
// No options: nothing changes.
|
||||
CollectionAssert.AreEqual(
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), png, null, false, TestZones.Rome).ToArray(),
|
||||
ExportPaths.Segments(General(), LibraryNaming.Default, Marta, Post(), png, null, false, TestZones.Rome, new ExportNameOptions(null, null)).ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheFrameSuffixSurvivesTheShorteningTo240()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), new string('r', 120));
|
||||
var deep = General() with { RootPath = root };
|
||||
var segments = new[] { "marta.demo", new string('a', 60), new string('b', 80) + "_t12m05s340.png" };
|
||||
|
||||
var fitted = ExportPaths.RelativePathFor(deep, segments, keepSuffix: "_t12m05s340");
|
||||
Assert.IsLessThanOrEqualTo(WindowsFileNames.MaxPathLength, Path.TrimEndingDirectorySeparator(root).Length + 1 + fitted.Length);
|
||||
StringAssert.EndsWith(fitted, "_t12m05s340.png");
|
||||
|
||||
// The numbered names of the safe writer keep it and put the number after it.
|
||||
var numbered = ExportPaths.NumberedName(root, fitted, 2, keepSuffix: "_t12m05s340");
|
||||
StringAssert.EndsWith(numbered, "_t12m05s340 (2).png");
|
||||
Assert.IsLessThanOrEqualTo(WindowsFileNames.MaxPathLength, Path.TrimEndingDirectorySeparator(root).Length + 1 + numbered.Length);
|
||||
Assert.AreEqual("marta.demo/x_f001.png", ExportPaths.RelativePathFor(deep, ["marta.demo", "x_f001.png"], keepSuffix: "_f001"), "short paths are not touched");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheNamingPreviewOfADestinationTakesTheLibrarySchemesWhenNull()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user