[librsvg: 1/3] SvgPredicate: make eval() actually test if some bytes are an SVG document
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/3] SvgPredicate: make eval() actually test if some bytes are an SVG document
- Date: Wed, 8 Dec 2021 01:31:19 +0000 (UTC)
commit f3d7df9229f9db777bff7ef9fbba3f3ecd18bc6d
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Dec 7 15:07:46 2021 -0600
SvgPredicate: make eval() actually test if some bytes are an SVG document
It was just validating the bytes as UTF-8.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/640>
tests/src/cmdline/rsvg_convert.rs | 2 +-
tests/src/predicates/svg.rs | 22 ++++++++++------------
2 files changed, 11 insertions(+), 13 deletions(-)
---
diff --git a/tests/src/cmdline/rsvg_convert.rs b/tests/src/cmdline/rsvg_convert.rs
index 877d8214..3e62140d 100644
--- a/tests/src/cmdline/rsvg_convert.rs
+++ b/tests/src/cmdline/rsvg_convert.rs
@@ -153,7 +153,7 @@ fn output_format_svg_short_option() {
.arg("svg")
.assert()
.success()
- .stdout(file::is_svg().with_svg_format());
+ .stdout(file::is_svg());
}
#[cfg(system_deps_have_cairo_svg)]
diff --git a/tests/src/predicates/svg.rs b/tests/src/predicates/svg.rs
index f9409126..40412204 100644
--- a/tests/src/predicates/svg.rs
+++ b/tests/src/predicates/svg.rs
@@ -1,9 +1,7 @@
-use librsvg::Length;
-use predicates::boolean::AndPredicate;
+use gio::MemoryInputStream;
+use glib::Bytes;
use predicates::prelude::*;
use predicates::reflection::{Case, Child, PredicateReflection, Product};
-use predicates::str::StartsWithPredicate;
-use predicates::str::*;
use std::cmp;
use std::fmt;
use std::str;
@@ -13,7 +11,7 @@ use libxml::xpath::Context;
use librsvg::doctest_only::Both;
use librsvg::rsvg_convert_only::ULength;
-use librsvg::Parse;
+use librsvg::{Length, Loader, LoadingError, Parse, SvgHandle};
/// Checks that the variable of type [u8] can be parsed as a SVG file.
#[derive(Debug)]
@@ -29,21 +27,21 @@ impl SvgPredicate {
}),
}
}
+}
- pub fn with_svg_format(
- self: Self,
- ) -> AndPredicate<StartsWithPredicate, ContainsPredicate, str> {
- predicate::str::starts_with("<?xml ").and(predicate::str::contains("<svg "))
- }
+fn svg_from_bytes(data: &[u8]) -> Result<SvgHandle, LoadingError> {
+ let bytes = Bytes::from(data);
+ let stream = MemoryInputStream::from_bytes(&bytes);
+ Loader::new().read_stream(&stream, None::<&gio::File>, None::<&gio::Cancellable>)
}
impl Predicate<[u8]> for SvgPredicate {
fn eval(&self, data: &[u8]) -> bool {
- str::from_utf8(data).is_ok()
+ svg_from_bytes(data).is_ok()
}
fn find_case<'a>(&'a self, _expected: bool, data: &[u8]) -> Option<Case<'a>> {
- match str::from_utf8(data) {
+ match svg_from_bytes(data) {
Ok(_) => None,
Err(e) => Some(Case::new(Some(self), false).add_product(Product::new("Error", e))),
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]