[librsvg/svenfoo/remove-pangoft2-dependency] Move the test for #347 to Rust




commit 186f31845867d088fdf4d78c06c09ce7ebf11b03
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 17 18:35:02 2021 -0600

    Move the test for #347 to Rust
    
    This is a test for a particular layer's position; #347 was about text
    elements not getting their bounds computed correctly.
    
    Note that the original test in C had this:
    
        if (fixture->has_position) {
            g_assert_cmpint (fixture->x, ==, position.x);
            g_assert_cmpint (fixture->y, ==, position.y);
        }
    
    Even though fixture->x is a double, it is being cast to an int to
    compare it to position.x (RsvgPositionData uses ints).
    
    The test effectively does "is the position.y between 48 and 49", so
    that's what we use in the Rust test.

 tests/api.c       |  7 -------
 tests/src/bugs.rs | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 9 deletions(-)
---
diff --git a/tests/api.c b/tests/api.c
index 90d75301..bd5f417c 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -1555,13 +1555,6 @@ static DimensionsFixtureData dimensions_fixtures[] =
         0, 0, 44, 45,
         FALSE, TRUE
     },
-    {
-        "/dimensions/sub/text_position",
-        "dimensions/347-wrapper.svg",
-        "#LabelA",
-        80, 48.90, 0, 0,
-        TRUE, FALSE
-    },
     {
         "/dimensions/with_viewbox",
         "dimensions/521-with-viewbox.svg",
diff --git a/tests/src/bugs.rs b/tests/src/bugs.rs
index c94588ea..320d364b 100644
--- a/tests/src/bugs.rs
+++ b/tests/src/bugs.rs
@@ -1,9 +1,13 @@
+#![cfg(test)]
+use test_generator::test_resources;
+
 use cairo;
-use librsvg::{LoadingError, SvgHandle};
+use float_cmp::approx_eq;
+use librsvg::{CairoRenderer, Loader, LoadingError, SvgHandle};
 use matches::matches;
 
 use crate::reference_utils::{Compare, Evaluate, Reference};
-use crate::utils::{load_svg, render_document, SurfaceSize};
+use crate::utils::{load_svg, render_document, setup_font_map, SurfaceSize};
 
 // https://gitlab.gnome.org/GNOME/librsvg/issues/335
 #[test]
@@ -318,3 +322,35 @@ fn doubly_recursive_use() {
 
     test_renders_as_empty(&svg, "308-doubly-recursive-use");
 }
+
+// https://gitlab.gnome.org/GNOME/librsvg/-/issues/347
+#[test_resources("tests/fixtures/dimensions/347-wrapper.svg")]
+fn test_text_bounds(name: &str) {
+    setup_font_map();
+
+    let handle = Loader::new()
+        .read_path(name)
+        .unwrap_or_else(|e| panic!("could not load: {}", e));
+
+    let renderer = CairoRenderer::new(&handle).test_mode();
+
+    let (ink_r, _) = renderer
+        .geometry_for_layer(
+            Some("#LabelA"),
+            &cairo::Rectangle {
+                x: 0.0,
+                y: 0.0,
+                width: 248.0,
+                height: 176.0,
+            },
+        )
+        .unwrap();
+
+    assert!(approx_eq!(f64, ink_r.x, 80.0));
+
+    // This is kind of suspicious, but we don't know the actual height of the
+    // text set at y=49 in the test SVG.  However, this test is more "text
+    // elements compute sensible bounds"; the bug #347 was that their ink_rect
+    // was not being computed correctly at all.
+    assert!(ink_r.y > 48.0 && ink_r.y < 49.0);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]