From 327f1547d19940dc8b794822fa6b7ed838d64c50 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 18 Aug 2026 16:32:51 +0200 Subject: [PATCH] test(html): render an image, and one of them in the dark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No test file was an image, so the image view — the page every png, jpg, gif, bmp, webp and svg is rendered into — had no reference output at all, and the corpus-driven capability checks skipped every image type for want of a file. The public test data gains one file per format a browser paints from a data url, all public domain or CC0 from Wikimedia Commons. The png is rendered a second time in the `dark` variant: its transparency is what shows that the image view's color scheme is the ground behind the picture and nothing else. `magic` gains the same files as real input. Its image coverage was synthetic signatures only, which cannot show that a jpeg names itself by whichever application marker its encoder wrote, or that an svg is named by parsing it. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01992btoumrdW4qpNeiD5bCg --- test/data.cmake | 4 ++-- test/src/html_output_test.cpp | 6 +++-- test/src/internal/magic_test.cpp | 41 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/test/data.cmake b/test/data.cmake index 3f59f4499..821b93038 100644 --- a/test/data.cmake +++ b/test/data.cmake @@ -7,7 +7,7 @@ odr_test_data( PATH "input/odr-public" URL "https://github.com/opendocument-app/OpenDocument.test.git" - REVISION "77ed98d72075bbd375be328b7232f40568a32563") + REVISION "1ad8965bfc65529a715d5b0e39743292e879329e") odr_test_data( PATH "input/odr-private" @@ -17,7 +17,7 @@ odr_test_data( odr_test_data( PATH "reference-output/odr-public" URL "https://github.com/opendocument-app/OpenDocument.test.output.git" - REVISION "9f41493817bd7d33ea6aae8dc63011e46f87f1d6") + REVISION "cf8f1e19ae5d70f433114c5ca29716931c29ebfe") odr_test_data( PATH "reference-output/odr-private" diff --git a/test/src/html_output_test.cpp b/test/src/html_output_test.cpp index b005140a0..b81793e8e 100644 --- a/test/src/html_output_test.cpp +++ b/test/src/html_output_test.cpp @@ -275,14 +275,16 @@ std::vector> list_variant_cases() { // renders one. {"odr-private/pdf/978-3-030-65771-0.pdf", single}, - // One file per view honoring a color scheme. The pdf view honors none, - // and no test file reaches the image view at all. + // One file per view honoring a color scheme. The pdf view honors none. {"odr-public/odt/style-various-1.odt", dark}, {"odr-public/odp/style-various-1.odp", dark}, {"odr-public/ods/style-border-1.ods", dark}, {"odr-public/txt/lorem ipsum.txt", dark}, {"odr-public/zip/small.zip", dark}, {"odr-private/otf/OpenSans-Regular.otf", dark}, + // The image view paints the ground the picture sits on and nothing else, + // so the file that shows it is one with transparency. + {"odr-public/png/tango-example-icons.png", dark}, // `system` writes what `dark` writes, wrapped in a media query; one file // pins that wrapper. {"odr-public/txt/lorem ipsum.txt", system}, diff --git a/test/src/internal/magic_test.cpp b/test/src/internal/magic_test.cpp index 79aeb58e8..2a0176d0c 100644 --- a/test/src/internal/magic_test.cpp +++ b/test/src/internal/magic_test.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include using namespace odr; using namespace odr::internal; @@ -58,6 +60,45 @@ TEST(magic, wpd) { "application/vnd.wordperfect"); } +/// What an encoder actually writes, rather than the signature a table says it +/// should: a jpeg names itself with whichever application marker it happens to +/// carry, and a webp only after its RIFF form tag. +TEST(magic, images) { + for (const auto &[path, type, mimetype] : + {std::tuple{"odr-public/png/tango-example-icons.png", + FileType::portable_network_graphics, "image/png"}, + std::tuple{"odr-public/jpg/fantastic-landscape.jpg", FileType::jpeg, + "image/jpeg"}, + std::tuple{"odr-public/gif/knights-tour.gif", + FileType::graphics_interchange_format, "image/gif"}, + std::tuple{"odr-public/bmp/tango-example-icons.bmp", + FileType::bitmap_image_file, "image/bmp"}, + std::tuple{"odr-public/webp/lorine-niedecker.webp", FileType::webp, + "image/webp"}}) { + const File file(TestData::test_file_path(path)); + + EXPECT_EQ(magic::file_type(*file.impl()), type) << path; + EXPECT_EQ(magic::mimetype(file.disk_path().value(), Logger::null()), + mimetype) + << path; + } +} + +/// An svg carries no signature at all - it is named by parsing it, and only the +/// open strategy does that. +TEST(magic, svg) { + for (const std::string path : + {"odr-public/svg/rotating-snakes.svg", + "odr-public/svg/civitas-schinesghe-emblem.svg"}) { + const File file(TestData::test_file_path(path)); + + EXPECT_EQ(magic::file_type(*file.impl()), FileType::unknown) << path; + EXPECT_EQ(magic::mimetype(file.disk_path().value(), Logger::null()), + "image/svg+xml") + << path; + } +} + namespace { FileType detect(const std::string &head) {