diff --git a/test/data.cmake b/test/data.cmake index 3f59f449..821b9303 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 b005140a..b81793e8 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 79aeb58e..2a0176d0 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) {