[librsvg] viewport.rs: Start adding tests
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] viewport.rs: Start adding tests
- Date: Wed, 27 Sep 2017 19:48:22 +0000 (UTC)
commit 01a4b0a2d4985c7dc25afcfac0709e9d5eefb439
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Sep 27 14:40:08 2017 -0500
viewport.rs: Start adding tests
rust/src/viewport.rs | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 120 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/viewport.rs b/rust/src/viewport.rs
index 0a56546..6a8cfc6 100644
--- a/rust/src/viewport.rs
+++ b/rust/src/viewport.rs
@@ -123,3 +123,123 @@ fn in_viewport<F>(ctx: &mut ViewportCtx,
ctx.pop_discrete_layer();
ctx.pop_view_box();
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use parsers::Parse;
+
+ #[derive(Default, PartialEq)]
+ struct Ctx {
+ pub view_box_size: Option<(f64, f64)>,
+ pub clipping_rect: Option<(f64, f64, f64, f64)>,
+ pub affine: Option<cairo::Matrix>,
+
+ pub expected_view_box_size: Option<(f64, f64)>,
+ pub expected_clipping_rect: Option<(f64, f64, f64, f64)>,
+ pub expected_affine: Option<cairo::Matrix>,
+ }
+
+ impl ViewportCtx for Ctx {
+ fn push_view_box(&mut self, width: f64, height: f64) {
+ self.view_box_size = Some((width, height));
+ }
+
+ fn pop_view_box(&mut self) {
+ }
+
+ fn push_discrete_layer(&mut self) {
+ }
+
+ fn pop_discrete_layer(&mut self) {
+ }
+
+ fn add_clipping_rect(&mut self, x: f64, y: f64, w: f64, h: f64) {
+ self.clipping_rect = Some((x, y, w, h));
+ }
+
+ fn set_affine(&mut self, affine: cairo::Matrix) {
+ self.affine = Some(affine);
+ }
+ }
+
+ fn call_in_viewport(vx: f64, vy: f64, vw: f64, vh: f64,
+ clip_before_layer_push: bool,
+ do_clip: bool,
+ vbox: Option<ViewBox>,
+ preserve_aspect_ratio: AspectRatio,
+ affine: cairo::Matrix,
+ ctx: &mut Ctx) {
+ in_viewport(ctx,
+ vx, vy, vw, vh,
+ clip_before_layer_push,
+ do_clip,
+ vbox,
+ preserve_aspect_ratio,
+ affine,
+ || ());
+
+ assert_eq!(ctx.view_box_size, ctx.expected_view_box_size);
+ assert_eq!(ctx.clipping_rect, ctx.expected_clipping_rect);
+ assert_eq!(ctx.affine, ctx.expected_affine);
+ }
+
+ #[test]
+ fn clip_after_layer_push() {
+ let mut affine = cairo::Matrix::identity();
+ affine.scale(0.20, 0.20);
+
+ let mut ctx = Ctx {
+ view_box_size: None,
+ clipping_rect: None,
+ affine: None,
+
+ expected_view_box_size: Some((50.0, 50.0)),
+ expected_clipping_rect: Some((10.0, 10.0, 10.0, 10.0)),
+ expected_affine: Some(affine)
+ };
+
+ call_in_viewport(10.0, 10.0, 10.0, 10.0,
+ false,
+ true,
+ Some(ViewBox(cairo::Rectangle {
+ x: 50.0,
+ y: 50.0,
+ width: 50.0,
+ height: 50.0,
+ })),
+ AspectRatio::parse("xMidYMid meet", ()).unwrap(),
+ cairo::Matrix::identity(),
+ &mut ctx);
+ }
+
+ #[test]
+ fn clip_before_layer_push() {
+ let mut affine = cairo::Matrix::identity();
+ affine.translate(10.0, 10.0);
+ affine.scale(0.40, 0.40);
+
+ let mut ctx = Ctx {
+ view_box_size: None,
+ clipping_rect: None,
+ affine: None,
+
+ expected_view_box_size: Some((50.0, 50.0)),
+ expected_clipping_rect: Some((0.0, 0.0, 50.0, 50.0)),
+ expected_affine: Some(affine)
+ };
+
+ call_in_viewport(10.0, 10.0, 20.0, 20.0,
+ true,
+ true,
+ Some(ViewBox(cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: 50.0,
+ height: 50.0,
+ })),
+ AspectRatio::parse("xMidYMid meet", ()).unwrap(),
+ cairo::Matrix::identity(),
+ &mut ctx);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]