[librsvg: 2/4] Move test_compare_render_output macro to reference_utils.rs Implement setting the test's cairo surfa
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/4] Move test_compare_render_output macro to reference_utils.rs Implement setting the test's cairo surfa
- Date: Fri, 18 Jun 2021 17:39:33 +0000 (UTC)
commit f444b581cb16a749d327d03a0724daa4a22d6189
Author: madds-h <madds hollandart io>
Date: Thu Jun 17 18:56:59 2021 -0500
Move test_compare_render_output macro to reference_utils.rs
Implement setting the test's cairo surface size
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/550>
tests/src/filters.rs | 60 ++++++++++++++++----------------------------
tests/src/reference_utils.rs | 45 +++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 39 deletions(-)
---
diff --git a/tests/src/filters.rs b/tests/src/filters.rs
index b698bd13..9f534c3d 100644
--- a/tests/src/filters.rs
+++ b/tests/src/filters.rs
@@ -1,47 +1,9 @@
use cairo;
use crate::reference_utils::{Compare, Evaluate, Reference};
+use crate::test_compare_render_output;
use crate::utils::{load_svg, render_document, SurfaceSize};
-macro_rules! test_compare_render_output {
- ($test_name:ident, $test:expr, $reference:expr $(,)?) => {
- #[test]
- fn $test_name() {
- let svg = load_svg($test).unwrap();
- let output_surf = render_document(
- &svg,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- let reference = load_svg($reference).unwrap();
- let reference_surf = render_document(
- &reference,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- Reference::from_surface(reference_surf.into_image_surface().unwrap())
- .compare(&output_surf)
- .evaluate(&output_surf, stringify!($test_name));
- }
- };
-}
-
#[test]
fn invalid_filter_reference_cancels_filter_chain() {
// The <rect> has a filter chain with two URLs listed, but the second one doesn't resolve.
@@ -140,6 +102,8 @@ fn non_filter_reference_cancels_filter_chain() {
test_compare_render_output!(
blur_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="blur(5)"/>
@@ -160,6 +124,8 @@ test_compare_render_output!(
test_compare_render_output!(
brightness_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="green" filter="brightness(125%)"/>
@@ -184,6 +150,8 @@ br##"<?xml version="1.0" encoding="UTF-8"?>
test_compare_render_output!(
contrast_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="green" filter="contrast(125%)"/>
@@ -208,6 +176,8 @@ br##"<?xml version="1.0" encoding="UTF-8"?>
test_compare_render_output!(
dropshadow_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="green" filter="drop-shadow(#ff0000 1px 4px 6px)"/>
@@ -235,6 +205,8 @@ br##"<?xml version="1.0" encoding="UTF-8"?>
test_compare_render_output!(
grayscale_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="grayscale(0.75)"/>
@@ -255,6 +227,8 @@ test_compare_render_output!(
test_compare_render_output!(
huerotate_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="green" filter="hue-rotate(128deg)"/>
@@ -275,6 +249,8 @@ test_compare_render_output!(
test_compare_render_output!(
invert_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="invert(0.75)"/>
@@ -299,6 +275,8 @@ test_compare_render_output!(
test_compare_render_output!(
opacity_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="red"/>
@@ -323,6 +301,8 @@ test_compare_render_output!(
test_compare_render_output!(
saturate_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="saturate(0.75)"/>
@@ -343,6 +323,8 @@ test_compare_render_output!(
test_compare_render_output!(
sepia_filter_func,
+ 400,
+ 400,
br##"<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400"
height="400">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="sepia(0.75)"/>
diff --git a/tests/src/reference_utils.rs b/tests/src/reference_utils.rs
index 4dfc8308..fbbe228c 100644
--- a/tests/src/reference_utils.rs
+++ b/tests/src/reference_utils.rs
@@ -181,3 +181,48 @@ where
}
Ok(argb)
}
+
+/// Macro test that compares render outputs
+///
+/// Takes in SurfaceSize width and height, setting the cairo surface
+#[macro_export]
+macro_rules! test_compare_render_output {
+ ($test_name:ident, $width:expr, $height:expr, $test:expr, $reference:expr $(,)?) => {
+ #[test]
+ fn $test_name() {
+ let sx: i32 = $width;
+ let sy: i32 = $height;
+ let svg = load_svg($test).unwrap();
+ let output_surf = render_document(
+ &svg,
+ SurfaceSize(sx, sy),
+ |_| (),
+ cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: sx as f64,
+ height: sy as f64,
+ },
+ )
+ .unwrap();
+
+ let reference = load_svg($reference).unwrap();
+ let reference_surf = render_document(
+ &reference,
+ SurfaceSize(sx, sy),
+ |_| (),
+ cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: sx as f64,
+ height: sy as f64,
+ },
+ )
+ .unwrap();
+
+ Reference::from_surface(reference_surf.into_image_surface().unwrap())
+ .compare(&output_surf)
+ .evaluate(&output_surf, stringify!($test_name));
+ }
+ };
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]