summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2022-05-06 18:36:40 -0500
committerFederico Mena Quintero <federico@gnome.org>2022-05-06 18:59:04 -0500
commit979fb0347256fdd3a8eb057d56ed1a91192a3d5e (patch)
tree6ff015e0c57e56b6a0f57ae5923ec517c8d7e456
parent56ba58c7c6fee059640ba1c6cc11ee0590148296 (diff)
downloadlibrsvg-979fb0347256fdd3a8eb057d56ed1a91192a3d5e.tar.gz
tests/src/geometries.rs: Start a test module for element geometries
This will load the SVG template files from Horizon EDA and check them against known-good descriptions of their elements' geometries. Horizon EDA: https://github.com/horizon-eda/horizon Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/697>
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/src/geometries.rs50
-rw-r--r--tests/src/main.rs3
3 files changed, 54 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cbc6a599..47baec23 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,6 +6,7 @@ test_sources = \
src/compare_surfaces.rs \
src/errors.rs \
src/filters.rs \
+ src/geometries.rs \
src/intrinsic_dimensions.rs \
src/legacy_sizing.rs \
src/loading_crash.rs \
diff --git a/tests/src/geometries.rs b/tests/src/geometries.rs
new file mode 100644
index 00000000..409e2527
--- /dev/null
+++ b/tests/src/geometries.rs
@@ -0,0 +1,50 @@
+//! Tests for the data files from https://github.com/horizon-eda/horizon/
+//!
+//! Horizon is an app Electronic Design Automation. It has SVG templates with specially
+//! named elements; the app extracts their geometries and renders GUI widgets instead of
+//! those elements. So, it is critical that the geometries get computed accurately.
+//!
+//! Horizon's build system pre-computes the geometries of the SVG templates' elements, and
+//! stores them in JSON files. You can see the SVGs and the .subs JSON files in the
+//! tests/fixtures/horizon in the librsvg source tree.
+//!
+//! This test file has machinery to load the SVG templates, and the JSON files with the
+//! expected geometries. The tests check that librsvg computes the same geometries every
+//! time.
+
+use anyhow::{Context, Result};
+use serde::Deserialize;
+use std::{collections::BTreeMap};
+use std::fs;
+use std::path::Path;
+
+// Copy of cairo::Rectangle
+//
+// Somehow I can't make serde's "remote" work here, in combination with the BTreeMap below...
+#[derive(Deserialize, Debug, PartialEq)]
+struct Rectangle {
+ x: f64,
+ y: f64,
+ width: f64,
+ height: f64,
+}
+
+impl From<cairo::Rectangle> for Rectangle {
+ fn from(r: cairo::Rectangle) -> Rectangle {
+ Rectangle {
+ x: r.x,
+ y: r.y,
+ width: r.width,
+ height: r.height,
+ }
+ }
+}
+
+#[derive(Deserialize)]
+struct Geometries(BTreeMap<String, Rectangle>);
+
+fn read_geometries(path: &Path) -> Result<Geometries> {
+ let contents = fs::read_to_string(path).context(format!("could not read {:?}", path))?;
+ Ok(serde_json::from_str(&contents).context(format!("could not parse JSON from {:?}", path))?)
+}
+
diff --git a/tests/src/main.rs b/tests/src/main.rs
index 71bc4a09..467cbb47 100644
--- a/tests/src/main.rs
+++ b/tests/src/main.rs
@@ -17,6 +17,9 @@ mod errors;
mod filters;
#[cfg(test)]
+mod geometries;
+
+#[cfg(test)]
mod intrinsic_dimensions;
#[cfg(test)]