[librsvg: 11/53] Make load_svg return a Result, not unwrap directly
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 11/53] Make load_svg return a Result, not unwrap directly
- Date: Fri, 23 Oct 2020 02:19:06 +0000 (UTC)
commit 64bdf6b2a5ee4dba7e394543d7cd9ac2362498ea
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Oct 13 17:33:39 2020 -0500
Make load_svg return a Result, not unwrap directly
We'll need this for the errors tests.
librsvg_crate/tests/standalone/api.rs | 12 +++--
librsvg_crate/tests/standalone/bugs.rs | 14 +++---
.../tests/standalone/intrinsic_dimensions.rs | 51 ++++++++++++++--------
librsvg_crate/tests/standalone/primitives.rs | 20 ++++++---
librsvg_crate/tests/standalone/utils.rs | 9 ++--
5 files changed, 67 insertions(+), 39 deletions(-)
---
diff --git a/librsvg_crate/tests/standalone/api.rs b/librsvg_crate/tests/standalone/api.rs
index 6c88ff54..256e6813 100644
--- a/librsvg_crate/tests/standalone/api.rs
+++ b/librsvg_crate/tests/standalone/api.rs
@@ -13,7 +13,8 @@ fn has_element_with_id_works() {
<rect id="foo" x="10" y="10" width="30" height="30"/>
</svg>
"#,
- );
+ )
+ .unwrap();
assert!(svg.has_element_with_id("#foo").unwrap());
assert!(!svg.has_element_with_id("#bar").unwrap());
@@ -49,7 +50,8 @@ fn render_layer() {
<rect id="bar" x="20" y="20" width="30" height="30" fill="#0000ff"/>
</svg>
"##,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -104,7 +106,8 @@ fn untransformed_element() {
</g>
</svg>
"##,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -182,7 +185,8 @@ fn set_stylesheet() {
<rect id="foo" x="10" y="20" width="30" height="40" fill="black"/>
</svg>
"##,
- );
+ )
+ .unwrap();
svg.set_stylesheet("rect { fill: #00ff00; }")
.expect("should be a valid stylesheet");
diff --git a/librsvg_crate/tests/standalone/bugs.rs b/librsvg_crate/tests/standalone/bugs.rs
index 4e9b1263..c4de96ec 100644
--- a/librsvg_crate/tests/standalone/bugs.rs
+++ b/librsvg_crate/tests/standalone/bugs.rs
@@ -13,7 +13,7 @@ fn inf_width() {
[l<g mask="url(sHaf:ax-fwiw0\inside\ax-ide\ax-flow#o0" styli="fility:!.5;">>
</g>
</svg>"#,
- );
+ ).unwrap();
let _output_surf = render_document(
&svg,
@@ -40,7 +40,8 @@ fn nonexistent_image_shouldnt_cancel_rendering() {
<rect x="10" y="10" width="30" height="30" fill="blue"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -92,7 +93,8 @@ fn href_attribute_overrides_xlink_href() {
<use xlink:href="#one" href="#two"/>
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -136,7 +138,8 @@ fn nonexistent_filter_leaves_object_unfiltered() {
<rect x="100" y="100" width="100" height="100" fill="lime" filter="url(#nonexistent)"/>
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -204,7 +207,8 @@ fn recursive_paint_servers_fallback_to_color() {
<rect fill="url(#l) lime" x="100" y="100" width="100" height="100" />
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
diff --git a/librsvg_crate/tests/standalone/intrinsic_dimensions.rs
b/librsvg_crate/tests/standalone/intrinsic_dimensions.rs
index fe6dce38..85ed952d 100644
--- a/librsvg_crate/tests/standalone/intrinsic_dimensions.rs
+++ b/librsvg_crate/tests/standalone/intrinsic_dimensions.rs
@@ -15,7 +15,8 @@ fn no_intrinsic_dimensions() {
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"/>
"#,
- );
+ )
+ .unwrap();
assert_eq!(
CairoRenderer::new(&svg).intrinsic_dimensions(),
@@ -33,7 +34,8 @@ fn has_intrinsic_dimensions() {
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="10cm" height="20" viewBox="0 0 100 200"/>
"#,
- );
+ )
+ .unwrap();
assert_eq!(
CairoRenderer::new(&svg).intrinsic_dimensions(),
@@ -58,7 +60,8 @@ fn root_geometry_with_percent_viewport() {
<rect x="10" y="20" width="30" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -89,7 +92,8 @@ fn layer_geometry_with_offset_viewport() {
<rect x="10" y="20" width="30" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -120,7 +124,8 @@ fn layer_geometry_with_viewbox_and_offset_viewport() {
<rect x="110" y="120" width="30" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -151,7 +156,8 @@ fn layer_geometry_with_no_width_height() {
<rect x="110" y="120" width="30" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -182,7 +188,8 @@ fn layer_geometry_with_no_intrinsic_dimensions() {
<rect x="110" y="120" width="50" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -216,7 +223,8 @@ fn layer_geometry_with_percentage_viewport() {
<rect x="10" y="20" width="50" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -249,7 +257,8 @@ fn layer_geometry_with_percent_viewport() {
<rect id="foo" x="10" y="20" width="30" height="40"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -283,7 +292,8 @@ fn layer_geometry_viewport_viewbox() {
<rect id="two" x="0" y="200" width="100" height="200" fill="rgb(0,0,255)"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let renderer = CairoRenderer::new(&svg);
@@ -314,7 +324,8 @@ fn layer_geometry_for_nonexistent_element() {
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>
"#,
- );
+ )
+ .unwrap();
let viewport = cairo::Rectangle {
x: 0.0,
@@ -337,7 +348,8 @@ fn layer_geometry_for_invalid_id() {
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>
"#,
- );
+ )
+ .unwrap();
let viewport = cairo::Rectangle {
x: 0.0,
@@ -371,7 +383,8 @@ fn render_to_viewport_with_different_size() {
<rect x="8" y="8" width="32" height="32" fill="blue"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -415,7 +428,8 @@ fn render_to_offsetted_viewport() {
<rect x="8" y="8" width="32" height="32" fill="blue"/>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -457,7 +471,8 @@ fn render_to_viewport_with_transform() {
</g>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -510,7 +525,8 @@ fn clip_on_transformed_viewport() {
</g>
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -579,7 +595,8 @@ fn mask_on_transformed_viewport() {
</g>
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
diff --git a/librsvg_crate/tests/standalone/primitives.rs b/librsvg_crate/tests/standalone/primitives.rs
index 077596e2..d9959dad 100644
--- a/librsvg_crate/tests/standalone/primitives.rs
+++ b/librsvg_crate/tests/standalone/primitives.rs
@@ -14,7 +14,8 @@ fn simple_opacity_with_transform() {
</g>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -59,7 +60,8 @@ fn simple_opacity_with_offset_viewport() {
</g>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -105,7 +107,8 @@ fn simple_opacity_with_scale() {
</g>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -154,7 +157,8 @@ fn markers_with_scale() {
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -208,7 +212,8 @@ fn opacity_inside_transformed_group() {
</g>
</svg>
"#,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -258,7 +263,8 @@ fn compound_opacity() {
</g>
</svg>
"##,
- );
+ )
+ .unwrap();
let output_surf = render_document(
&svg,
@@ -328,7 +334,7 @@ fn nested_masks() {
</svg>
"##,
- );
+ ).unwrap();
let output_surf = render_document(
&svg,
diff --git a/librsvg_crate/tests/standalone/utils.rs b/librsvg_crate/tests/standalone/utils.rs
index 312bd25d..b0bb148c 100644
--- a/librsvg_crate/tests/standalone/utils.rs
+++ b/librsvg_crate/tests/standalone/utils.rs
@@ -3,8 +3,7 @@ use cairo;
use gio;
use glib;
-use librsvg;
-use librsvg::{CairoRenderer, Loader, RenderingError, SvgHandle};
+use librsvg::{CairoRenderer, Loader, LoadingError, RenderingError, SvgHandle};
use rsvg_internals::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
@@ -15,13 +14,11 @@ use std::fs::{self, File};
use std::io::BufReader;
use std::path::PathBuf;
-pub fn load_svg(input: &'static [u8]) -> SvgHandle {
+pub fn load_svg(input: &'static [u8]) -> Result<SvgHandle, LoadingError> {
let bytes = glib::Bytes::from_static(input);
let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
- Loader::new()
- .read_stream(&stream, None::<&gio::File>, None::<&gio::Cancellable>)
- .unwrap()
+ Loader::new().read_stream(&stream, None::<&gio::File>, None::<&gio::Cancellable>)
}
#[derive(Copy, Clone)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]