1
1
//! Tests for crashes in the rendering stage.
2
//!
3
//! Ensures that redering a particular SVG doesn't crash, but we don't care
4
//! about the resulting image or even whether there were errors during rendering.
5

            
6
use rsvg::{CairoRenderer, Loader};
7

            
8
use std::path::PathBuf;
9

            
10
37
fn render_crash(filename: &str) {
11
37
    let mut full_filename = PathBuf::new();
12
37
    full_filename.push("tests/fixtures/render-crash");
13
37
    full_filename.push(filename);
14

            
15
37
    let handle = Loader::new()
16
        .read_path(&full_filename)
17
        .unwrap_or_else(|e| panic!("could not load: {}", e));
18

            
19
37
    let surface = cairo::ImageSurface::create(cairo::Format::ARgb32, 100, 100).unwrap();
20
37
    let cr = cairo::Context::new(&surface).expect("Failed to create a cairo context");
21

            
22
    // We just test for crashes during rendering, and don't care about success/error.
23
74
    let _ = CairoRenderer::new(&handle)
24
74
        .render_document(&cr, &cairo::Rectangle::new(0.0, 0.0, 100.0, 100.0));
25
37
}
26

            
27
macro_rules! t {
28
    ($test_name:ident, $filename:expr) => {
29
        #[test]
30
74
        fn $test_name() {
31
37
            render_crash($filename);
32
74
        }
33
    };
34
}
35

            
36
#[rustfmt::skip]
37
mod tests {
38
    use super::*;
39

            
40
    t!(bug187_set_gradient_on_empty_path_svg,           "bug187-set-gradient-on-empty-path.svg");
41
    t!(bug193_filters_conv_05_f_svg,                    "bug193-filters-conv-05-f.svg");
42
    t!(bug227_negative_dasharray_value_svg,             "bug227-negative-dasharray-value.svg");
43
    t!(bug266_filters_with_error_attributes_svg,        "bug266-filters-with-error-attributes.svg");
44
    t!(bug277_filter_on_empty_group_svg,                "bug277-filter-on-empty-group.svg");
45
    t!(bug292_clip_empty_group_svg,                     "bug292-clip-empty-group.svg");
46
    t!(bug293_mask_empty_group_svg,                     "bug293-mask-empty-group.svg");
47
    t!(bug324_empty_svg_svg,                            "bug324-empty-svg.svg");
48
    t!(bug337_font_ex_svg,                              "bug337-font-ex.svg");
49
    t!(bug338_zero_sized_image_svg,                     "bug338-zero-sized-image.svg");
50
    t!(bug340_marker_with_zero_sized_vbox_svg,          "bug340-marker-with-zero-sized-vbox.svg");
51
    t!(bug342_use_references_ancestor_svg,              "bug342-use-references-ancestor.svg");
52
    t!(bug343_fecomponenttransfer_child_in_error_svg,   "bug343-feComponentTransfer-child-in-error.svg");
53
    t!(bug344_too_large_viewbox_svg,                    "bug344-too-large-viewbox.svg");
54
    t!(bug345_too_large_size_svg,                       "bug345-too-large-size.svg");
55
    t!(bug395_femorphology_negative_scaling_svg,        "bug395-feMorphology-negative-scaling.svg");
56
    t!(bug497_path_with_all_invalid_commands_svg,       "bug497-path-with-all-invalid-commands.svg");
57
    t!(bug581491_zero_sized_text_svg,                   "bug581491-zero-sized-text.svg");
58
    t!(bug588_big_viewbox_yields_invalid_transform_svg, "bug588-big-viewbox-yields-invalid-transform.svg");
59
    t!(bug591_vbox_overflow_svg,                        "bug591-vbox-overflow.svg");
60
    t!(bug593_mask_empty_bbox_svg,                      "bug593-mask-empty-bbox.svg");
61
    t!(bug721_pattern_cycle_from_child_svg,             "bug721-pattern-cycle-from-child.svg");
62
    t!(bug721_pattern_cycle_from_other_child_svg,       "bug721-pattern-cycle-from-other-child.svg");
63
    t!(bug777155_zero_sized_pattern_svg,                "bug777155-zero-sized-pattern.svg");
64
    t!(bug928_empty_fetile_bounds_svg,                  "bug928-empty-feTile-bounds.svg");
65
    t!(bug932_too_big_font_size,                        "bug932-too-big-font-size.svg");
66
    t!(bug1059_feoffset_overflow,                       "bug1059-feoffset-overflow.svg");
67
    t!(bug1060_zero_sized_image_from_data_uri,          "bug1060-zero-sized-image-from-data-uri.svg");
68
    t!(bug1062_feturbulence_limit_numoctaves,           "bug1062-feTurbulence-limit-numOctaves.svg");
69
    t!(femerge_color_interpolation_srgb_svg,            "feMerge-color-interpolation-srgb.svg");
70
    t!(filters_non_invertible_paffine_svg,              "filters-non-invertible-paffine.svg");
71
    t!(gradient_with_empty_bbox_svg,                    "gradient-with-empty-bbox.svg");
72
    t!(gradient_with_no_children_svg,                   "gradient-with-no-children.svg");
73
    t!(pattern_with_empty_bbox_svg,                     "pattern-with-empty-bbox.svg");
74
    t!(pattern_with_no_children_svg,                    "pattern-with-no-children.svg");
75
    t!(pixelrectangle_duplicate_crash_svg,              "PixelRectangle-duplicate-crash.svg");
76
    t!(recursive_feimage_svg,                           "recursive-feimage.svg");
77
}