using Heimdall.Infrastructure.Services; using Shouldly; using Xunit; namespace Heimdall.Infrastructure.Tests; public sealed class PlateOcrTests { [Fact] public void Parses_synthetic_tsv_word_and_confidence() { const string fixture = "level\tpage_num\tblock_num\tpar_num\tline_num\tword_num\tleft\ttop\twidth\theight\tconf\ttext\n" + "5\t1\t1\t1\t1\t1\t0\t0\t100\t30\t92.5\tAB-123-CD\n"; var result = TesseractPlateOcr.ParseTsv(fixture); result.ShouldNotBeNull(); result!.Text.ShouldBe("AB-123-CD"); result.Confidence.ShouldBe(0.925); } [Fact] public void Rejects_empty_or_unconfident_tsv_rows() { var result = TesseractPlateOcr.ParseTsv("header\n5\t1\t1\t1\t1\t1\t0\t0\t1\t1\t-1\t"); result.ShouldBeNull(); } [Fact] public void OCR_options_are_bounded_when_enabled() { new PlateOcrOptions { Enabled = true, MaxImageBytes = 128 }.IsValid().ShouldBeFalse(); new PlateOcrOptions { Enabled = true, TimeoutSeconds = 100 }.IsValid().ShouldBeFalse(); new PlateOcrOptions { Enabled = false, MaxImageBytes = 0 }.IsValid().ShouldBeTrue(); } [Fact] public void Accepts_bounded_synthetic_plate_crop_and_rejects_invalid_bytes() { var fixture = File.ReadAllBytes(Path.Combine(AppContext.BaseDirectory, "Fixtures", "synthetic-plate.png")); TesseractPlateOcr.IsSafeImage(fixture).ShouldBeTrue(); TesseractPlateOcr.IsSafeImage(new byte[32]).ShouldBeFalse(); } }