[librsvg: 5/15] tests/src/geometries.rs: Start a test module for element geometries
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/15] tests/src/geometries.rs: Start a test module for element geometries
- Date: Tue, 10 May 2022 02:13:50 +0000 (UTC)
commit 979fb0347256fdd3a8eb057d56ed1a91192a3d5e
Author: Federico Mena Quintero <federico gnome org>
Date: Fri May 6 18:36:40 2022 -0500
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>
tests/Makefile.am | 1 +
tests/src/geometries.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/src/main.rs | 3 +++
3 files changed, 54 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cbc6a5995..47baec239 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 000000000..409e25275
--- /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 71bc4a09c..467cbb47b 100644
--- a/tests/src/main.rs
+++ b/tests/src/main.rs
@@ -16,6 +16,9 @@ mod errors;
#[cfg(test)]
mod filters;
+#[cfg(test)]
+mod geometries;
+
#[cfg(test)]
mod intrinsic_dimensions;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]