Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/src/html_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,16 @@ std::vector<std::pair<std::string, ConfigVariant>> 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},
Expand Down
41 changes: 41 additions & 0 deletions test/src/internal/magic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <gtest/gtest.h>

#include <sstream>
#include <string>
#include <tuple>

using namespace odr;
using namespace odr::internal;
Expand Down Expand Up @@ -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) {
Expand Down
Loading