1
1
//! Tests for loading errors.
2
//!
3
//! Note that all the tests in this module are `#[ignore]`.  This is because they
4
//! take a much longer time to run than normal tests, as they depend upon actually
5
//! hitting the limits in librsvg for the number of loaded elements, or the number
6
//! of referenced elements during rendering.
7
//!
8
//! There is a *big* difference in the run-time of these tests when compiled with
9
//! `--release` versus `--debug`.  So, we will only run them in release-mode tests.
10

            
11
#![cfg(test)]
12

            
13
use rsvg::{CairoRenderer, ImplementationLimit, Loader, LoadingError, RenderingError};
14

            
15
#[ignore]
16
#[test]
17
2
fn too_many_elements() {
18
1
    let name = "tests/fixtures/errors/bug515-too-many-elements.svgz";
19

            
20
1
    assert!(matches!(
21
1
        Loader::new().read_path(name),
22
        Err(LoadingError::LimitExceeded(
23
            ImplementationLimit::TooManyLoadedElements
24
        ))
25
    ));
26
2
}
27

            
28
2
fn rendering_instancing_limit(name: &str) {
29
2
    let handle = Loader::new()
30
        .read_path(name)
31
        .unwrap_or_else(|e| panic!("could not load: {}", e));
32

            
33
2
    let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, 500, 500).unwrap();
34
2
    let cr = cairo::Context::new(&surface).expect("Failed to create a cairo context");
35

            
36
    // Note that at least 515-patttern-billion-laughs.svg requires a viewport of this size
37
    // or bigger; a smaller one causes the recursive patterns to get so small that they
38
    // are culled out, and so the document doesn't reach the instancing limit.
39
4
    match CairoRenderer::new(&handle)
40
2
        .render_document(&cr, &cairo::Rectangle::new(0.0, 0.0, 500.0, 500.0))
41
    {
42
        Ok(_) => (),
43
        Err(RenderingError::LimitExceeded(ImplementationLimit::TooManyReferencedElements)) => (),
44
        _ => panic!("unexpected error code"),
45
    }
46
2
}
47

            
48
#[ignore]
49
#[test]
50
2
fn instancing_limit1() {
51
1
    rendering_instancing_limit("tests/fixtures/errors/bug323-nested-use.svg");
52
2
}
53

            
54
#[ignore]
55
#[test]
56
2
fn instancing_limit2() {
57
1
    rendering_instancing_limit("tests/fixtures/errors/bug515-pattern-billion-laughs.svg");
58
2
}