From 515d775ee1835609e16536557b56751fd4d4ecf6 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Tue, 18 Aug 2026 15:28:18 +0200 Subject: [PATCH] test(html): read a few files in a second config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reference output renders every file in one config, so a toggle the config does not set is covered nowhere: nothing rendered dark, and the margins we turn on here hid the reflowed text document the library ships by default. A test file may now carry a `ConfigVariant` — a named deviation applied last — and is rendered once more into a sibling directory suffixed with the name. The pdf text mode was the one case of this and becomes the first row of the table, keeping its path. Added: `dark` for one file per view that carries a dark stylesheet (document, slides, spreadsheet, text, filesystem, font), `system` for the media-query wrapper around it, `reflow` for a text document kept out of its page box, and `read-only` for the output a reader gets. The pdf view honors no color scheme, and no test file reaches the image view at all. The reference resources were a few pull requests behind — document.css missed the 3mm inset and the dark stylesheets, text.js the batched line-number sizing — and are regenerated with this. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01EPasn1P1Y4xGehbRdWWFwY --- test/data.cmake | 4 +- test/src/html_output_test.cpp | 103 ++++++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 24 deletions(-) diff --git a/test/data.cmake b/test/data.cmake index b20de084..3f59f449 100644 --- a/test/data.cmake +++ b/test/data.cmake @@ -17,9 +17,9 @@ odr_test_data( odr_test_data( PATH "reference-output/odr-public" URL "https://github.com/opendocument-app/OpenDocument.test.output.git" - REVISION "ea671153a51dd968496e39a874f50e35c4a18138") + REVISION "9f41493817bd7d33ea6aae8dc63011e46f87f1d6") odr_test_data( PATH "reference-output/odr-private" URL "https://github.com/opendocument-app/OpenDocument.test-private.output.git" - REVISION "97f3bb9574850526a0d38241574af087d3f5e915") + REVISION "a86e896770dbd5604df0c7e09c0bfc69dba83f2a") diff --git a/test/src/html_output_test.cpp b/test/src/html_output_test.cpp index 9cc58036..b005140a 100644 --- a/test/src/html_output_test.cpp +++ b/test/src/html_output_test.cpp @@ -10,8 +10,11 @@ #include #include +#include #include #include +#include +#include #include #include @@ -48,17 +51,26 @@ bool document_type_is_comparable(const TestFile &test_file, file_meta.document_type != DocumentType::unknown; } -} // namespace +/// A deviation from the config the reference output is rendered with, applied +/// last. A file that carries one is rendered twice: the default output keeps +/// its path, the variant's goes to a sibling directory suffixed with the +/// variant's name. +struct ConfigVariant { + std::string name; + std::function apply{[](HtmlConfig &) {}}; +}; struct TestParams { TestFile test_file; std::string path; - PdfTextMode pdf_text_mode{PdfTextMode::dual_layer}; + ConfigVariant variant; std::string test_repo; std::string output_path; std::string output_path_prefix; }; +} // namespace + using HtmlOutputTests = testing::TestWithParam; TEST_P(HtmlOutputTests, html_meta) { @@ -178,7 +190,7 @@ TEST_P(HtmlOutputTests, html_meta) { config.format_html = true; config.html_indent = 1; config.html_indent_string = "\t"; - config.pdf_text_mode = params.pdf_text_mode; + params.variant.apply(config); const std::string output_path_tmp = output_path + "/tmp"; fs::create_directories(output_path_tmp); @@ -194,15 +206,14 @@ TEST_P(HtmlOutputTests, html_meta) { namespace { -/// The default `dual_layer` mode carries no suffix so existing (non-PDF and -/// dual-layer) reference outputs keep their paths; single-layer variants are -/// disambiguated with `-single`. -std::string text_mode_suffix(const PdfTextMode pdf_text_mode) { - return pdf_text_mode == PdfTextMode::dual_layer ? "" : "-single"; +/// The default config carries no suffix, so the reference output rendered with +/// it keeps its path; a variant is disambiguated with `-{name}`. +std::string variant_suffix(const ConfigVariant &variant) { + return variant.name.empty() ? "" : "-" + variant.name; } std::string test_params_to_name(const TestParams ¶ms) { - std::string path = params.path + text_mode_suffix(params.pdf_text_mode); + std::string path = params.path + variant_suffix(params.variant); util::string::replace_all(path, "/", "_"); util::string::replace_all(path, "-", "_"); util::string::replace_all(path, "+", "_"); @@ -213,7 +224,7 @@ std::string test_params_to_name(const TestParams ¶ms) { } TestParams create_test_params(const TestFile &test_file, - const PdfTextMode pdf_text_mode) { + const ConfigVariant &variant) { const std::string test_file_path = test_file.short_path; const std::string test_repo = *RelPath(test_file_path).begin(); @@ -222,35 +233,83 @@ TestParams create_test_params(const TestFile &test_file, .join(RelPath(test_repo)) .join(RelPath("output")) .string(); - const std::string output_path_suffix = text_mode_suffix(pdf_text_mode); const std::string output_path = AbsPath(output_path_prefix) .join(RelPath(test_file_path).rebase(RelPath(test_repo))) .string() + - output_path_suffix; + variant_suffix(variant); return { .test_file = test_file, .path = test_file_path, - .pdf_text_mode = pdf_text_mode, + .variant = variant, .test_repo = test_repo, .output_path = output_path, .output_path_prefix = output_path_prefix, }; } +/// The extra configs to render in, each paired with the file to render. A +/// variant is meant to cover a rendering path the default config never takes, +/// so it is pinned to as few files as cover that path — for a color scheme +/// that is one file per *view*, each of which carries its own dark stylesheet, +/// rather than one per format. +std::vector> list_variant_cases() { + const ConfigVariant single{"single", [](HtmlConfig &config) { + config.pdf_text_mode = PdfTextMode::single_layer; + }}; + const ConfigVariant dark{"dark", [](HtmlConfig &config) { + config.color_scheme = HtmlColorScheme::dark; + }}; + const ConfigVariant system{"system", [](HtmlConfig &config) { + config.color_scheme = HtmlColorScheme::system; + }}; + const ConfigVariant reflow{"reflow", [](HtmlConfig &config) { + config.text_document_margin = false; + }}; + const ConfigVariant read_only{ + "read-only", [](HtmlConfig &config) { config.editable = false; }}; + + return { + // The text mode only affects the pdf view, and only the odr engine + // 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. + {"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}, + // `system` writes what `dark` writes, wrapped in a media query; one file + // pins that wrapper. + {"odr-public/txt/lorem ipsum.txt", system}, + + // A text document reflowed to the viewport rather than kept in its page + // box — the default the library ships, and the one the reference output + // stopped showing when the margins were turned on here. + {"odr-public/odt/about.odt", reflow}, + {"odr-public/docx/physics.docx", reflow}, + + // The output a reader gets rather than an editor. + {"odr-public/odt/style-various-1.odt", read_only}, + }; +} + std::vector list_test_params() { + const std::vector> variant_cases = + list_variant_cases(); + std::vector params; for (const TestFile &test_file : TestData::test_files()) { - params.push_back(create_test_params(test_file, PdfTextMode::dual_layer)); - - // PDFs default to `PdfTextMode::dual_layer`. To keep the single-layer path - // under reference-output coverage too, eject an extra `-single` test case - // for one representative PDF (odr engine only, since the text mode only - // affects odr's PDF rendering). - if (test_file.short_path == "odr-private/pdf/978-3-030-65771-0.pdf") { - params.push_back( - create_test_params(test_file, PdfTextMode::single_layer)); + params.push_back(create_test_params(test_file, {})); + + for (const auto &[path, variant] : variant_cases) { + if (path == test_file.short_path) { + params.push_back(create_test_params(test_file, variant)); + } } } return params;