85 lines
4.5 KiB
Markdown
85 lines
4.5 KiB
Markdown
|
|
# Image generation test plan — ImageSharp-only (multiplatform)
|
|||
|
|
|
|||
|
|
Goal
|
|||
|
|
-----
|
|||
|
|
Create an automated, cross-platform test project that validates `ImageCreatorImageSharp` behavior by generating synthetic input images and pixel-inspecting outputs produced by the library.
|
|||
|
|
|
|||
|
|
Decisions
|
|||
|
|
---------
|
|||
|
|
- Test only `ImageCreatorImageSharp` (multiplatform).
|
|||
|
|
- Test project targets `net10.0` (not Windows-only) and uses SixLabors.ImageSharp for both generation and verification; avoid `System.Drawing.Common` in tests.
|
|||
|
|
- Inputs are programmatically generated images (no checked-in large binaries).
|
|||
|
|
- Verification uses pixel inspection (sample regions, color averages, non-background pixel counts).
|
|||
|
|
|
|||
|
|
Project
|
|||
|
|
-------
|
|||
|
|
- Name: `MaddoShared.ImageSharpTests` (folder: `MaddoShared.ImageSharpTests/`)
|
|||
|
|
- TargetFramework: `net10.0` (no Windows-only flags)
|
|||
|
|
- Package references:
|
|||
|
|
- `MSTest.TestFramework` / `MSTest.TestAdapter` / `Microsoft.NET.Test.Sdk`
|
|||
|
|
- `FluentAssertions`
|
|||
|
|
- `Moq` (if needed for loggers)
|
|||
|
|
- `SixLabors.ImageSharp` and `SixLabors.ImageSharp.Drawing` (for image creation and pixel inspection)
|
|||
|
|
- `Microsoft.Extensions.Logging.Abstractions` (lightweight logging)
|
|||
|
|
- ProjectReference: `../MaddoShared/MaddoShared.csproj`
|
|||
|
|
|
|||
|
|
Helpers (tests)
|
|||
|
|
----------------
|
|||
|
|
- `TempWorkspace` — creates temporary `Source` and `Dest` folders, cleans up on dispose.
|
|||
|
|
- `TestImageFactory` — creates synthetic JPEG/PNG inputs and in-memory logo PNG bytes. Also can write EXIF orientation values.
|
|||
|
|
- `PixelInspector` — loads output using ImageSharp and exposes:
|
|||
|
|
- `CountNonBackgroundPixels(path, Rectangle region, Rgba32 background, int tolerance)`
|
|||
|
|
- `SampleAverageColor(path, Rectangle region)`
|
|||
|
|
- Region helpers: top/bottom/left/right/center/quadrant rectangles for given image sizes
|
|||
|
|
- `CreatorFactory` — builds `PicSettings` defaults and `ImageCreatorImageSharp` instances.
|
|||
|
|
|
|||
|
|
Test cases (high-level)
|
|||
|
|
-----------------------
|
|||
|
|
1. Image resizing: verify big and small output dimensions respect settings.
|
|||
|
|
2. Text positioning: for `Posizione` = ALTO/CENTRO/BASSO and `Allineamento` = SINISTRA/CENTRO/DESTRA assert text pixels appear in expected regions.
|
|||
|
|
3. Text content: baseline (empty) vs non-empty comparisons to ensure text changes output; EXIF-vertical photo selects `TestoFirmaV`.
|
|||
|
|
4. Logo positioning: use a solid-color logo (e.g., pure red PNG) and verify red pixels appear in the expected quadrant for combinations of `LogoPosizioneH` × `LogoPosizioneV` and with margins (absolute and percentage).
|
|||
|
|
5. Logo features: opacity (logo color blending) and color-key transparency.
|
|||
|
|
6. EXIF orientation: ensure rotation is applied and output contains no EXIF orientation tag.
|
|||
|
|
|
|||
|
|
Verification approach
|
|||
|
|
---------------------
|
|||
|
|
- For text: compare non-background pixel count in the target band vs opposite band (thresholded) to avoid brittle exact glyph placement checks.
|
|||
|
|
- For logo: sample the quadrant where the logo should be; count logo-colored pixels and assert above threshold.
|
|||
|
|
- For opacity: sample average color in logo region and assert it is blended when opacity <100%.
|
|||
|
|
|
|||
|
|
Scope boundaries
|
|||
|
|
----------------
|
|||
|
|
- In scope: `ImageCreatorImageSharp` behavior: resize, EXIF rotation, text presence/position, logo position/opactiy, thumbnails.
|
|||
|
|
- Out of scope: `ImageCreatorGDI` (excluded), OCR verification of exact text glyphs, font-subpixel metrics, performance testing.
|
|||
|
|
|
|||
|
|
Implementation notes
|
|||
|
|
--------------------
|
|||
|
|
- Keep tests deterministic by creating solid-color inputs and simple logos.
|
|||
|
|
- Use modest image sizes (e.g., 800×600) so tests run fast.
|
|||
|
|
- Carefully choose thresholds for pixel-count assertions to be robust across fonts and rendering differences.
|
|||
|
|
|
|||
|
|
Run & validate
|
|||
|
|
---------------
|
|||
|
|
- Build: `dotnet build MaddoShared.ImageSharpTests`
|
|||
|
|
- Test: `dotnet test MaddoShared.ImageSharpTests`
|
|||
|
|
|
|||
|
|
Files to add
|
|||
|
|
------------
|
|||
|
|
- `MaddoShared.ImageSharpTests/MaddoShared.ImageSharpTests.csproj`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Helpers/TempWorkspace.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Helpers/TestImageFactory.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Helpers/PixelInspector.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Helpers/CreatorFactory.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Tests/ImageResizingTests.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Tests/TextPositioningTests.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Tests/LogoPositioningTests.cs`
|
|||
|
|
- `MaddoShared.ImageSharpTests/Tests/ExifOrientationTests.cs`
|
|||
|
|
- `docs/image-generation-tests-plan.md` (this file)
|
|||
|
|
|
|||
|
|
Next steps
|
|||
|
|
----------
|
|||
|
|
1. Create the `MaddoShared.ImageSharpTests` project and add the helper files.
|
|||
|
|
2. Implement the first set of tests (resizing + a simple text presence test) to validate the testing harness.
|
|||
|
|
3. Iterate thresholds and add remaining tests.
|
|||
|
|
|