[librsvg: 15/53] Move the rest of the errors tests to Rust




commit df58a906e021feb371dd15be01becd81e8ab1782
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 13 19:35:19 2020 -0500

    Move the rest of the errors tests to Rust

 tests/Makefile.am   |  8 +------
 tests/errors.c      | 66 -----------------------------------------------------
 tests/src/errors.rs | 38 +++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 74 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f5649ec1..cecf854d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,11 +14,9 @@ EXTRA_DIST +=                \
        $(test_sources) \
        README.md
 
-# Keep "errors" at the end; they are the slowest to run
 test_programs =                \
        api             \
-       rsvg-test       \
-       errors
+       rsvg-test
 
 test_utils_common_sources = \
        test-utils.c    \
@@ -28,10 +26,6 @@ api_SOURCES =                \
        api.c           \
        $(test_utils_common_sources)
 
-errors_SOURCES =       \
-       errors.c        \
-       $(test_utils_common_sources)
-
 rsvg_test_SOURCES = \
        rsvg-test.c     \
        $(test_utils_common_sources)
diff --git a/tests/src/errors.rs b/tests/src/errors.rs
index ccadbf84..af32850d 100644
--- a/tests/src/errors.rs
+++ b/tests/src/errors.rs
@@ -3,7 +3,8 @@
 #![cfg(test)]
 use test_generator::test_resources;
 
-use librsvg::{Loader, LoadingError};
+use cairo;
+use librsvg::{CairoRenderer, Loader, LoadingError, RenderingError};
 
 use crate::utils::fixture_path;
 
@@ -14,3 +15,38 @@ fn loading_crash(name: &str) {
         Err(LoadingError::XmlParseError(_))
     ));
 }
+
+fn rendering_instancing_limit(name: &str) {
+    let handle = Loader::new()
+        .read_path(fixture_path(name))
+        .unwrap_or_else(|e| panic!("could not load: {}", e));
+
+    let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, 500, 500).unwrap();
+    let cr = cairo::Context::new(&surface);
+
+    // Note that at least 515-patttern-billion-laughs.svg requires a viewport of this size
+    // or bigger; a smaller one causes the recursive patterns to get so small that they
+    // are culled out, and so the document doesn't reach the instancing limit.
+    assert!(matches!(
+        CairoRenderer::new(&handle).render_document(
+            &cr,
+            &cairo::Rectangle {
+                x: 0.0,
+                y: 0.0,
+                width: 500.0,
+                height: 500.0,
+            },
+        ),
+        Err(RenderingError::InstancingLimit)
+    ));
+}
+
+#[test_resources("tests/fixtures/errors/323-nested-use.svg")]
+fn instancing_limit1(name: &str) {
+    rendering_instancing_limit(name);
+}
+
+#[test_resources("tests/fixtures/errors/515-pattern-billion-laughs.svg")]
+fn instancing_limit2(name: &str) {
+    rendering_instancing_limit(name);
+}


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