1
//use crate::predicates::ends_with_pkg_version;
2
mod internal_predicates;
3
use internal_predicates::file;
4

            
5
use assert_cmd::Command;
6
use assert_cmd::assert::IntoOutputPredicate;
7
use assert_cmd::cargo::cargo_bin_cmd;
8
#[cfg(system_deps_have_cairo_pdf)]
9
use chrono::{TimeZone, Utc};
10
use predicates::boolean::*;
11
use predicates::prelude::*;
12
use predicates::str::*;
13
use rsvg::{Length, LengthUnit};
14
use std::env;
15
use std::io::Write;
16
use std::path::{Path, PathBuf};
17
use tempfile::{Builder, NamedTempFile};
18
use url::Url;
19

            
20
// What should be tested here?
21
// The goal is to test the code in rsvg-convert, not the entire library.
22
//
23
//  - command-line options that affect size (width, height, zoom, resolution) ✔
24
//  - pixel dimensions of the output (should be sufficient to do that for PNG) ✔
25
//  - limit on output size (32767 pixels) ✔
26
//  - output formats (PNG, PDF, PS, EPS, SVG) ✔
27
//  - multi-page output (for PDF) ✔
28
//  - output file option ✔
29
//  - SOURCE_DATA_EPOCH environment variable for PDF output ✔
30
//  - background color option ✔
31
//  - optional CSS stylesheet ✔
32
//  - error handling for missing SVG dimensions ✔
33
//  - error handling for export lookup ID ✔
34
//  - error handling for invalid input ✔
35

            
36
struct RsvgConvert {
37
    command: Command,
38

            
39
    // This field is never read; it is just to store the temporary file, which will
40
    // be deleted when the struct is dropped.  So, we mark it with dead_code.
41
    #[allow(dead_code)]
42
    config_file: NamedTempFile,
43
}
44

            
45
impl RsvgConvert {
46
110
    fn new() -> RsvgConvert {
47
110
        let config_file = setup_fontconfig_file();
48
110
        let config_file_path: &Path = config_file.as_ref();
49

            
50
110
        let path_str = config_file_path.to_str().unwrap();
51
110
        eprintln!("FONTCONFIG_FILE={path_str}");
52

            
53
110
        let mut command = cargo_bin_cmd!("rsvg-convert");
54
110
        command.env("FONTCONFIG_FILE", config_file_path);
55

            
56
110
        RsvgConvert {
57
110
            command,
58
110
            config_file,
59
110
        }
60
110
    }
61

            
62
90
    fn new_with_input<P>(file: P) -> RsvgConvert
63
90
    where
64
90
        P: AsRef<Path>,
65
    {
66
90
        let mut rsvg_convert = RsvgConvert::new();
67
90
        match rsvg_convert.command.pipe_stdin(&file) {
68
90
            Ok(_) => (),
69
            Err(e) => panic!("Error opening file '{}': {}", file.as_ref().display(), e),
70
        }
71

            
72
90
        rsvg_convert
73
90
    }
74

            
75
6
    fn accepts_arg(option: &str) {
76
6
        let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
77

            
78
6
        rsvg_convert.command.arg(option).assert().success();
79
6
    }
80

            
81
4
    fn option_yields_output<I, P>(option: &str, output_pred: I)
82
4
    where
83
4
        I: IntoOutputPredicate<P>,
84
4
        P: Predicate<[u8]>,
85
    {
86
4
        let mut rsvg_convert = RsvgConvert::new();
87

            
88
4
        rsvg_convert
89
4
            .command
90
4
            .arg(option)
91
4
            .assert()
92
4
            .success()
93
4
            .stdout(output_pred);
94
4
    }
95
}
96

            
97
/// Creaates a temporary `fonts.conf` for the rsvg-convert tests suite and returns the path
98
/// to that file.
99
///
100
/// Explanation: a few of the tests for rsvg-convert need fonts to be installed, since
101
/// otherwise Cairo/fontconfig won't generate the expected output.  So, we need to
102
///
103
/// * Create a fonts.conf.
104
/// * Ensure that that fonts.conf has a `<dir>` tag with the location of the font files.
105
///
106
/// However the location of the font files is rsvg/tests/resources with respect to the
107
/// toplevel directory of this librsvg source tree.  The librsvg source tree is structured as a Cargo workspace,
108
/// with these in the toplevel:
109
///
110
/// * Cargo.toml
111
/// * rsvg/tests/resources
112
/// * rsvg_convert/Cargo.toml (manifest path for *this* rsvg_convert project)
113
///
114
/// So, at this point, `CARGO_MANIFEST_DIR` points to
115
/// `librsvg/rsvg_convert`, and we need to find
116
/// `../rsvg/tests/resources` and canonicalize it into an absolute
117
/// path.  Then, we need to make a `fonts.conf` with that absolute
118
/// path.
119
110
fn setup_fontconfig_file() -> NamedTempFile {
120
110
    let fonts_dir = rsvg_tests_resources_path().into_os_string();
121
110
    let fonts_dir_bytes = fonts_dir.as_encoded_bytes();
122

            
123
110
    let mut file = NamedTempFile::new().expect("create temporary file for fonts.conf");
124

            
125
110
    write!(
126
110
        file,
127
        r#"<?xml version="1.0"?>
128
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
129
<fontconfig>
130
  <cachedir>/tmp/rsvg_tests_fontconfig_cache</cachedir>
131
"#
132
    )
133
110
    .unwrap();
134
110
    write!(file, "<dir>").unwrap();
135
110
    file.write(fonts_dir_bytes).unwrap();
136
110
    writeln!(file, "</dir>").unwrap();
137
110
    write!(
138
110
        file,
139
        r#"
140
  <!--
141
      From openSUSE's fonts.conf:
142
      Accept deprecated 'sans' alias, replacing it with 'sans-serif'
143
  -->
144
  <match target="pattern">
145
    <test qual="any" name="family">
146
      <string>sans</string>
147
    </test>
148
    <edit name="family" mode="assign" binding="same">
149
      <string>sans-serif</string>
150
    </edit>
151
  </match>
152

            
153
  <!--
154
      Map 'serif' to 'sans-serif' since we don't have a serif font in the test resources yet.
155
  -->
156
  <match target="pattern">
157
    <test qual="any" name="family">
158
      <string>serif</string>
159
    </test>
160
    <edit name="family" mode="assign" binding="same">
161
      <string>sans-serif</string>
162
    </edit>
163
  </match>
164

            
165
  <!--
166
    Names not including any well known alias are given 'sans-serif'
167
  -->
168
  <match target="pattern">
169
    <test qual="all" name="family" compare="not_eq">
170
      <string>sans-serif</string>
171
    </test>
172
    <test qual="all" name="family" compare="not_eq">
173
      <string>serif</string>
174
    </test>
175
    <test qual="all" name="family" compare="not_eq">
176
      <string>monospace</string>
177
    </test>
178
    <edit name="family" mode="append_last">
179
      <string>sans-serif</string>
180
    </edit>
181
  </match>
182

            
183
  <!-- Map generic family names to actual fonts -->
184
  <alias>
185
    <family>sans-serif</family>
186
    <prefer><family>Roboto</family></prefer>
187
  </alias>
188

            
189
</fontconfig>
190
"#
191
    )
192
110
    .unwrap();
193

            
194
110
    file
195
110
}
196

            
197
/// Computes the absolute path for the rsvg/tests/resources directory in the source tree
198
110
fn rsvg_tests_resources_path() -> PathBuf {
199
110
    let relative_resources_path: PathBuf = [
200
110
        env::var("CARGO_MANIFEST_DIR")
201
110
            .expect("Manifest directory unknown")
202
110
            .as_str(),
203
110
        "..",
204
110
        "rsvg",
205
110
        "tests",
206
110
        "resources",
207
110
    ]
208
110
    .iter()
209
110
    .collect();
210

            
211
110
    let absolute_resources_path = relative_resources_path
212
110
        .canonicalize()
213
110
        .expect("canonicalizing rsvg/tests/resources path");
214

            
215
110
    absolute_resources_path
216
110
}
217

            
218
#[test]
219
1
fn converts_svg_from_stdin_to_png() {
220
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
221

            
222
1
    rsvg_convert
223
1
        .command
224
1
        .assert()
225
1
        .success()
226
1
        .stdout(file::is_png());
227
1
}
228

            
229
#[test]
230
1
fn converts_svg_from_stdin_to_png_using_stdin_argument() {
231
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
232

            
233
1
    rsvg_convert
234
1
        .command
235
1
        .arg("-")
236
1
        .assert()
237
1
        .success()
238
1
        .stdout(file::is_png());
239
1
}
240

            
241
#[test]
242
1
fn argument_is_input_filename() {
243
1
    let input = Path::new("tests/fixtures/bug521-with-viewbox.svg");
244
1
    let mut rsvg_convert = RsvgConvert::new();
245

            
246
1
    rsvg_convert
247
1
        .command
248
1
        .arg(input)
249
1
        .assert()
250
1
        .success()
251
1
        .stdout(file::is_png());
252
1
}
253

            
254
#[test]
255
1
fn argument_is_url() {
256
1
    let path = Path::new("tests/fixtures/bug521-with-viewbox.svg")
257
1
        .canonicalize()
258
1
        .unwrap();
259
1
    let url = Url::from_file_path(path).unwrap();
260
1
    let stringified = url.as_str();
261
1
    assert!(stringified.starts_with("file://"));
262

            
263
1
    let mut rsvg_convert = RsvgConvert::new();
264

            
265
1
    rsvg_convert
266
1
        .command
267
1
        .arg(stringified)
268
1
        .assert()
269
1
        .success()
270
1
        .stdout(file::is_png());
271
1
}
272

            
273
#[test]
274
1
fn output_format_png() {
275
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
276

            
277
1
    rsvg_convert
278
1
        .command
279
1
        .arg("--format=png")
280
1
        .assert()
281
1
        .success()
282
1
        .stdout(file::is_png());
283
1
}
284

            
285
#[cfg(system_deps_have_cairo_ps)]
286
#[test]
287
1
fn output_format_ps() {
288
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
289

            
290
1
    rsvg_convert
291
1
        .command
292
1
        .arg("--format=ps")
293
1
        .assert()
294
1
        .success()
295
1
        .stdout(file::is_ps());
296
1
}
297

            
298
#[cfg(system_deps_have_cairo_ps)]
299
#[test]
300
1
fn output_format_eps() {
301
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
302

            
303
1
    rsvg_convert
304
1
        .command
305
1
        .arg("--format=eps")
306
1
        .assert()
307
1
        .success()
308
1
        .stdout(file::is_eps());
309
1
}
310

            
311
#[cfg(system_deps_have_cairo_pdf)]
312
#[test]
313
1
fn output_format_pdf() {
314
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
315

            
316
1
    rsvg_convert
317
1
        .command
318
1
        .arg("--format=pdf")
319
1
        .assert()
320
1
        .success()
321
1
        .stdout(file::is_pdf());
322
1
}
323

            
324
#[cfg(system_deps_have_cairo_pdf)]
325
#[test]
326
1
fn output_format_pdf_1_7() {
327
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
328

            
329
1
    rsvg_convert
330
1
        .command
331
1
        .arg("--format=pdf1.7")
332
1
        .assert()
333
1
        .success()
334
1
        .stdout(file::is_pdf().with_version("1.7"));
335
1
}
336

            
337
#[cfg(system_deps_have_cairo_pdf)]
338
#[test]
339
1
fn output_format_pdf_1_6() {
340
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
341

            
342
1
    rsvg_convert
343
1
        .command
344
1
        .arg("--format=pdf1.6")
345
1
        .assert()
346
1
        .success()
347
1
        .stdout(file::is_pdf().with_version("1.6"));
348
1
}
349

            
350
#[cfg(system_deps_have_cairo_pdf)]
351
#[test]
352
1
fn output_format_pdf_1_5() {
353
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
354

            
355
1
    rsvg_convert
356
1
        .command
357
1
        .arg("--format=pdf1.5")
358
1
        .assert()
359
1
        .success()
360
1
        .stdout(file::is_pdf().with_version("1.5"));
361
1
}
362

            
363
#[cfg(system_deps_have_cairo_pdf)]
364
#[test]
365
1
fn output_format_pdf_1_4() {
366
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
367

            
368
1
    rsvg_convert
369
1
        .command
370
1
        .arg("--format=pdf1.4")
371
1
        .assert()
372
1
        .success()
373
1
        .stdout(file::is_pdf().with_version("1.4"));
374
1
}
375

            
376
#[cfg(system_deps_have_cairo_svg)]
377
#[test]
378
1
fn output_format_svg_short_option() {
379
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
380

            
381
1
    rsvg_convert
382
1
        .command
383
1
        .arg("-f")
384
1
        .arg("svg")
385
1
        .assert()
386
1
        .success()
387
1
        .stdout(file::is_svg());
388
1
}
389

            
390
#[cfg(system_deps_have_cairo_svg)]
391
#[test]
392
1
fn user_specified_width_and_height() {
393
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
394

            
395
1
    rsvg_convert
396
1
        .command
397
1
        .arg("--format")
398
1
        .arg("svg")
399
1
        .arg("--width")
400
1
        .arg("42cm")
401
1
        .arg("--height")
402
1
        .arg("43cm")
403
1
        .assert()
404
1
        .success()
405
1
        .stdout(file::is_svg().with_size(
406
1
            Length::new(42.0, LengthUnit::Cm),
407
1
            Length::new(43.0, LengthUnit::Cm),
408
        ));
409
1
}
410

            
411
#[cfg(system_deps_have_cairo_svg)]
412
#[test]
413
1
fn user_specified_width_and_height_px_output() {
414
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
415

            
416
1
    rsvg_convert
417
1
        .command
418
1
        .arg("--format")
419
1
        .arg("svg")
420
1
        .arg("--width")
421
1
        .arg("1920")
422
1
        .arg("--height")
423
1
        .arg("508mm")
424
1
        .assert()
425
1
        .success()
426
1
        .stdout(file::is_svg().with_size(
427
1
            Length::new(1920.0, LengthUnit::Px),
428
1
            Length::new(1920.0, LengthUnit::Px),
429
        ));
430
1
}
431

            
432
#[cfg(system_deps_have_cairo_svg)]
433
#[test]
434
1
fn user_specified_width_and_height_a4() {
435
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
436

            
437
1
    rsvg_convert
438
1
        .command
439
1
        .arg("--format")
440
1
        .arg("svg")
441
1
        .arg("--page-width")
442
1
        .arg("210mm")
443
1
        .arg("--page-height")
444
1
        .arg("297mm")
445
1
        .arg("--left")
446
1
        .arg("1cm")
447
1
        .arg("--top")
448
1
        .arg("1cm")
449
1
        .arg("--width")
450
1
        .arg("190mm")
451
1
        .arg("--height")
452
1
        .arg("277mm")
453
1
        .assert()
454
1
        .success()
455
1
        .stdout(file::is_svg().with_size(
456
1
            Length::new(210.0, LengthUnit::Mm),
457
1
            Length::new(297.0, LengthUnit::Mm),
458
        ));
459
1
}
460

            
461
#[test]
462
1
fn output_file_option() {
463
1
    let output = {
464
1
        let tempfile = Builder::new().suffix(".png").tempfile().unwrap();
465
1
        tempfile.path().to_path_buf()
466
    };
467
1
    assert!(predicates::path::is_file().not().eval(&output));
468

            
469
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
470

            
471
1
    rsvg_convert
472
1
        .command
473
1
        .arg(format!("--output={}", output.display()))
474
1
        .assert()
475
1
        .success()
476
1
        .stdout(is_empty());
477

            
478
1
    assert!(predicates::path::is_file().eval(&output));
479
1
    std::fs::remove_file(&output).unwrap();
480
1
}
481

            
482
#[test]
483
1
fn output_file_short_option() {
484
1
    let output = {
485
1
        let tempfile = Builder::new().suffix(".png").tempfile().unwrap();
486
1
        tempfile.path().to_path_buf()
487
    };
488
1
    assert!(predicates::path::is_file().not().eval(&output));
489

            
490
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
491

            
492
1
    rsvg_convert
493
1
        .command
494
1
        .arg("-o")
495
1
        .arg(format!("{}", output.display()))
496
1
        .assert()
497
1
        .success()
498
1
        .stdout(is_empty());
499

            
500
1
    assert!(predicates::path::is_file().eval(&output));
501
1
    std::fs::remove_file(&output).unwrap();
502
1
}
503

            
504
#[test]
505
1
fn overwrites_existing_output_file() {
506
1
    let output = {
507
1
        let tempfile = Builder::new().suffix(".png").tempfile().unwrap();
508
1
        tempfile.path().to_path_buf()
509
    };
510
1
    assert!(predicates::path::is_file().not().eval(&output));
511

            
512
1
    for _ in 0..2 {
513
2
        let mut rsvg_convert =
514
2
            RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
515

            
516
2
        rsvg_convert
517
2
            .command
518
2
            .arg(format!("--output={}", output.display()))
519
2
            .assert()
520
2
            .success()
521
2
            .stdout(is_empty());
522

            
523
2
        assert!(predicates::path::is_file().eval(&output));
524
    }
525

            
526
1
    std::fs::remove_file(&output).unwrap();
527
1
}
528

            
529
#[test]
530
1
fn empty_input_yields_error() {
531
1
    let starts_with = starts_with("Error reading SVG");
532
1
    let ends_with = ends_with("Input file is too short").trim();
533
1
    let mut rsvg_convert = RsvgConvert::new();
534

            
535
1
    rsvg_convert
536
1
        .command
537
1
        .assert()
538
1
        .failure()
539
1
        .stderr(starts_with.and(ends_with));
540
1
}
541

            
542
#[test]
543
1
fn empty_svg_yields_error() {
544
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty.svg");
545

            
546
1
    rsvg_convert
547
1
        .command
548
1
        .assert()
549
1
        .failure()
550
1
        .stderr("The SVG stdin has no dimensions\n");
551
1
}
552

            
553
#[test]
554
1
fn multiple_input_files_not_allowed_for_png_output() {
555
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
556
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
557
1
    let mut rsvg_convert = RsvgConvert::new();
558

            
559
1
    rsvg_convert
560
1
        .command
561
1
        .arg(one)
562
1
        .arg(two)
563
1
        .assert()
564
1
        .failure()
565
1
        .stderr(contains(
566
            "Multiple SVG files are only allowed for PDF and (E)PS output",
567
        ));
568
1
}
569

            
570
#[cfg(system_deps_have_cairo_ps)]
571
#[test]
572
1
fn multiple_input_files_accepted_for_eps_output() {
573
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
574
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
575
1
    let mut rsvg_convert = RsvgConvert::new();
576

            
577
1
    rsvg_convert
578
1
        .command
579
1
        .arg("--format=eps")
580
1
        .arg(one)
581
1
        .arg(two)
582
1
        .assert()
583
1
        .success()
584
1
        .stdout(file::is_eps());
585
1
}
586

            
587
#[cfg(system_deps_have_cairo_ps)]
588
#[test]
589
1
fn multiple_input_files_accepted_for_ps_output() {
590
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
591
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
592
1
    let mut rsvg_convert = RsvgConvert::new();
593

            
594
1
    rsvg_convert
595
1
        .command
596
1
        .arg("--format=ps")
597
1
        .arg(one)
598
1
        .arg(two)
599
1
        .assert()
600
1
        .success()
601
1
        .stdout(file::is_ps());
602
1
}
603

            
604
#[cfg(system_deps_have_cairo_pdf)]
605
#[test]
606
1
fn multiple_input_files_create_multi_page_pdf_output() {
607
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
608
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
609
1
    let three = Path::new("tests/fixtures/example.svg");
610
1
    let mut rsvg_convert = RsvgConvert::new();
611

            
612
1
    rsvg_convert
613
1
        .command
614
1
        .arg("--format=pdf")
615
1
        .arg(one)
616
1
        .arg(two)
617
1
        .arg(three)
618
1
        .assert()
619
1
        .success()
620
1
        .stdout(
621
1
            file::is_pdf()
622
1
                .with_page_count(3)
623
1
                .and(file::is_pdf().with_page_size(0, 150.0, 75.0))
624
1
                .and(file::is_pdf().with_page_size(1, 123.0, 123.0))
625
1
                .and(file::is_pdf().with_page_size(2, 75.0, 300.0)),
626
        );
627
1
}
628

            
629
#[cfg(system_deps_have_cairo_pdf)]
630
#[test]
631
1
fn multiple_input_files_create_multi_page_pdf_output_fixed_size() {
632
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
633
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
634
1
    let three = Path::new("tests/fixtures/example.svg");
635
1
    let mut rsvg_convert = RsvgConvert::new();
636

            
637
1
    rsvg_convert
638
1
        .command
639
1
        .arg("--format=pdf")
640
1
        .arg("--page-width=8.5in")
641
1
        .arg("--page-height=11in")
642
1
        .arg("--width=7.5in")
643
1
        .arg("--height=10in")
644
1
        .arg("--left=0.5in")
645
1
        .arg("--top=0.5in")
646
1
        .arg("--keep-aspect-ratio")
647
1
        .arg(one)
648
1
        .arg(two)
649
1
        .arg(three)
650
1
        .assert()
651
1
        .success()
652
1
        .stdout(
653
1
            file::is_pdf()
654
1
                .with_page_count(3)
655
                // https://www.wolframalpha.com/input/?i=convert+11+inches+to+desktop+publishing+points
656
1
                .and(file::is_pdf().with_page_size(0, 612.0, 792.0))
657
1
                .and(file::is_pdf().with_page_size(1, 612.0, 792.0))
658
1
                .and(file::is_pdf().with_page_size(2, 612.0, 792.0)),
659
        );
660
1
}
661

            
662
#[cfg(system_deps_have_cairo_pdf)]
663
#[test]
664
1
fn pdf_has_link() {
665
1
    let input = Path::new("tests/fixtures/a-link.svg");
666
1
    let mut rsvg_convert = RsvgConvert::new();
667

            
668
1
    rsvg_convert
669
1
        .command
670
1
        .arg("--format=pdf")
671
1
        .arg(input)
672
1
        .assert()
673
1
        .success()
674
1
        .stdout(file::is_pdf().with_link("https://example.com"));
675
1
}
676

            
677
#[cfg(system_deps_have_cairo_pdf)]
678
#[test]
679
1
fn pdf_has_link_inside_text() {
680
1
    let input = Path::new("tests/fixtures/text-a-link.svg");
681
1
    let mut rsvg_convert = RsvgConvert::new();
682

            
683
1
    rsvg_convert
684
1
        .command
685
1
        .arg("--format=pdf")
686
1
        .arg(input)
687
1
        .assert()
688
1
        .success()
689
1
        .stdout(
690
1
            file::is_pdf()
691
1
                .with_link("https://example.com")
692
1
                .and(file::is_pdf().with_link("https://another.example.com")),
693
        );
694
1
}
695

            
696
#[cfg(system_deps_have_cairo_pdf)]
697
#[test]
698
1
fn pdf_has_text() {
699
1
    let input = Path::new("tests/fixtures/hello-world.svg");
700
1
    let mut rsvg_convert = RsvgConvert::new();
701

            
702
1
    rsvg_convert
703
1
        .command
704
1
        .arg("--format=pdf")
705
1
        .arg(input)
706
1
        .assert()
707
1
        .success()
708
1
        .stdout(
709
1
            file::is_pdf()
710
1
                .with_text("Hello world!")
711
1
                .and(file::is_pdf().with_text("Hello again!")),
712
        );
713
1
}
714

            
715
#[cfg(system_deps_have_cairo_pdf)]
716
#[test]
717
1
fn env_source_data_epoch_controls_pdf_creation_date() {
718
1
    let input = Path::new("tests/fixtures/bug521-with-viewbox.svg");
719
1
    let date = 1581411039; // seconds since epoch
720
1
    let mut rsvg_convert = RsvgConvert::new();
721

            
722
1
    rsvg_convert
723
1
        .command
724
1
        .env("SOURCE_DATE_EPOCH", format!("{}", date))
725
1
        .arg("--format=pdf")
726
1
        .arg(input)
727
1
        .assert()
728
1
        .success()
729
1
        .stdout(file::is_pdf().with_creation_date(Utc.timestamp_opt(date, 0).unwrap()));
730
1
}
731

            
732
#[cfg(system_deps_have_cairo_pdf)]
733
#[test]
734
1
fn env_source_data_epoch_no_digits() {
735
    // intentionally not testing for the full error string here
736
1
    let input = Path::new("tests/fixtures/bug521-with-viewbox.svg");
737
1
    let mut rsvg_convert = RsvgConvert::new();
738

            
739
1
    rsvg_convert
740
1
        .command
741
1
        .env("SOURCE_DATE_EPOCH", "foobar")
742
1
        .arg("--format=pdf")
743
1
        .arg(input)
744
1
        .assert()
745
1
        .failure()
746
1
        .stderr(starts_with("Environment variable $SOURCE_DATE_EPOCH"));
747
1
}
748

            
749
#[cfg(system_deps_have_cairo_pdf)]
750
#[test]
751
1
fn env_source_data_epoch_trailing_garbage() {
752
    // intentionally not testing for the full error string here
753
1
    let input = Path::new("tests/fixtures/bug521-with-viewbox.svg");
754
1
    let mut rsvg_convert = RsvgConvert::new();
755

            
756
1
    rsvg_convert
757
1
        .command
758
1
        .arg("--format=pdf")
759
1
        .env("SOURCE_DATE_EPOCH", "1234556+")
760
1
        .arg(input)
761
1
        .assert()
762
1
        .failure()
763
1
        .stderr(starts_with("Environment variable $SOURCE_DATE_EPOCH"));
764
1
}
765

            
766
#[cfg(system_deps_have_cairo_pdf)]
767
#[test]
768
1
fn env_source_data_epoch_empty() {
769
    // intentionally not testing for the full error string here
770
1
    let input = Path::new("tests/fixtures/bug521-with-viewbox.svg");
771
1
    let mut rsvg_convert = RsvgConvert::new();
772

            
773
1
    rsvg_convert
774
1
        .command
775
1
        .arg("--format=pdf")
776
1
        .env("SOURCE_DATE_EPOCH", "")
777
1
        .arg(input)
778
1
        .assert()
779
1
        .failure()
780
1
        .stderr(starts_with("Environment variable $SOURCE_DATE_EPOCH"));
781
1
}
782

            
783
#[test]
784
1
fn width_option() {
785
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
786

            
787
1
    rsvg_convert
788
1
        .command
789
1
        .arg("--width=300")
790
1
        .assert()
791
1
        .success()
792
1
        .stdout(file::is_png().with_size(300, 150));
793
1
}
794

            
795
#[test]
796
1
fn height_option() {
797
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
798

            
799
1
    rsvg_convert
800
1
        .command
801
1
        .arg("--height=200")
802
1
        .assert()
803
1
        .success()
804
1
        .stdout(file::is_png().with_size(400, 200));
805
1
}
806

            
807
#[test]
808
1
fn width_and_height_options() {
809
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
810

            
811
1
    rsvg_convert
812
1
        .command
813
1
        .arg("--width=300")
814
1
        .arg("--height=200")
815
1
        .assert()
816
1
        .success()
817
1
        .stdout(file::is_png().with_size(300, 200));
818
1
}
819

            
820
#[test]
821
1
fn unsupported_unit_in_width_and_height() {
822
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
823

            
824
1
    rsvg_convert
825
1
        .command
826
1
        .arg("--height=200ex")
827
1
        .assert()
828
1
        .failure()
829
1
        .stderr(contains("supported units"));
830
1
}
831

            
832
#[test]
833
1
fn invalid_length() {
834
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
835

            
836
1
    rsvg_convert
837
1
        .command
838
1
        .arg("--page-width=foo")
839
1
        .assert()
840
1
        .failure()
841
1
        .stderr(contains("can not be parsed as a length"));
842
1
}
843

            
844
#[test]
845
1
fn zoom_factor() {
846
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
847

            
848
1
    rsvg_convert
849
1
        .command
850
1
        .arg("--zoom=0.8")
851
1
        .assert()
852
1
        .success()
853
1
        .stdout(file::is_png().with_size(160, 80));
854
1
}
855

            
856
#[test]
857
1
fn zoom_factor_and_larger_size() {
858
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
859

            
860
1
    rsvg_convert
861
1
        .command
862
1
        .arg("--width=400")
863
1
        .arg("--height=200")
864
1
        .arg("--zoom=1.5")
865
1
        .assert()
866
1
        .success()
867
1
        .stdout(file::is_png().with_size(300, 150));
868
1
}
869

            
870
#[test]
871
1
fn zoom_factor_and_smaller_size() {
872
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
873

            
874
1
    rsvg_convert
875
1
        .command
876
1
        .arg("--width=400")
877
1
        .arg("--height=200")
878
1
        .arg("--zoom=3.5")
879
1
        .assert()
880
1
        .success()
881
1
        .stdout(file::is_png().with_size(400, 200));
882
1
}
883

            
884
#[test]
885
1
fn x_zoom_option() {
886
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
887

            
888
1
    rsvg_convert
889
1
        .command
890
1
        .arg("--x-zoom=2")
891
1
        .assert()
892
1
        .success()
893
1
        .stdout(file::is_png().with_size(400, 100));
894
1
}
895

            
896
#[test]
897
1
fn x_short_option() {
898
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
899

            
900
1
    rsvg_convert
901
1
        .command
902
1
        .arg("-x")
903
1
        .arg("2.0")
904
1
        .assert()
905
1
        .success()
906
1
        .stdout(file::is_png().with_size(400, 100));
907
1
}
908

            
909
#[test]
910
1
fn y_zoom_option() {
911
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
912

            
913
1
    rsvg_convert
914
1
        .command
915
1
        .arg("--y-zoom=2.0")
916
1
        .assert()
917
1
        .success()
918
1
        .stdout(file::is_png().with_size(200, 200));
919
1
}
920

            
921
#[test]
922
1
fn y_short_option() {
923
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
924

            
925
1
    rsvg_convert
926
1
        .command
927
1
        .arg("-y")
928
1
        .arg("2")
929
1
        .assert()
930
1
        .success()
931
1
        .stdout(file::is_png().with_size(200, 200));
932
1
}
933

            
934
#[test]
935
1
fn huge_zoom_factor_yields_error() {
936
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
937

            
938
1
    rsvg_convert
939
1
        .command
940
1
        .arg("--zoom=1000")
941
1
        .assert()
942
1
        .failure()
943
1
        .stderr(starts_with(
944
            "The resulting image would be larger than 32767 pixels",
945
        ));
946
1
}
947

            
948
#[test]
949
1
fn negative_zoom_factor_yields_error() {
950
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
951

            
952
1
    rsvg_convert
953
1
        .command
954
1
        .arg("--zoom=-2")
955
1
        .assert()
956
1
        .failure()
957
1
        .stderr(contains("Invalid zoom"));
958
1
}
959

            
960
#[test]
961
1
fn invalid_zoom_factor_yields_error() {
962
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug521-with-viewbox.svg");
963

            
964
1
    rsvg_convert
965
1
        .command
966
1
        .arg("--zoom=foo")
967
1
        .assert()
968
1
        .failure()
969
1
        .stderr(contains("invalid value"));
970
1
}
971

            
972
#[test]
973
1
fn default_resolution_is_96dpi() {
974
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
975

            
976
1
    rsvg_convert
977
1
        .command
978
1
        .assert()
979
1
        .success()
980
1
        .stdout(file::is_png().with_size(96, 384));
981
1
}
982

            
983
#[test]
984
1
fn x_resolution() {
985
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
986

            
987
1
    rsvg_convert
988
1
        .command
989
1
        .arg("--dpi-x=300")
990
1
        .assert()
991
1
        .success()
992
1
        .stdout(file::is_png().with_size(300, 384));
993
1
}
994

            
995
#[test]
996
1
fn x_resolution_short_option() {
997
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
998

            
999
1
    rsvg_convert
1
        .command
1
        .arg("-d")
1
        .arg("45")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(45, 384));
1
}
#[test]
1
fn y_resolution() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--dpi-y=300")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(96, 1200));
1
}
#[test]
1
fn y_resolution_short_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-p")
1
        .arg("45")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(96, 180));
1
}
#[test]
1
fn x_and_y_resolution() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--dpi-x=300")
1
        .arg("--dpi-y=150")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(300, 600));
1
}
#[test]
1
fn zero_resolution_is_invalid() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--dpi-x=0")
1
        .arg("--dpi-y=0")
1
        .assert()
1
        .failure()
1
        .stderr(contains("Invalid resolution"));
1
}
#[test]
1
fn negative_resolution_is_invalid() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--dpi-x=-100")
1
        .arg("--dpi-y=-100")
1
        .assert()
1
        .failure()
1
        .stderr(contains("Invalid resolution"));
1
}
#[test]
1
fn unparsable_resolution_is_invalid() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--dpi-x=blah")
1
        .arg("--dpi-y=blah")
1
        .assert()
1
        .failure()
1
        .stderr(contains("invalid value")); // this comes from clap
1
}
#[test]
1
fn zero_offset_png() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--page-width=640")
1
        .arg("--page-height=480")
1
        .arg("--width=200")
1
        .arg("--height=100")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/zero-offset-png.png"));
1
}
#[test]
1
fn offset_png() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--page-width=640")
1
        .arg("--page-height=480")
1
        .arg("--width=200")
1
        .arg("--height=100")
1
        .arg("--left=100")
1
        .arg("--top=50")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/offset-png.png"));
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn unscaled_pdf_size() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .assert()
1
        .success()
1
        .stdout(file::is_pdf().with_page_size(0, 72.0, 72.0));
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn pdf_size_width_height() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--width=2in")
1
        .arg("--height=3in")
1
        .assert()
1
        .success()
1
        .stdout(file::is_pdf().with_page_size(0, 144.0, 216.0));
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn pdf_size_width_height_proportional() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--width=2in")
1
        .arg("--height=3in")
1
        .arg("--keep-aspect-ratio")
1
        .assert()
1
        .success()
1
        .stdout(file::is_pdf().with_page_size(0, 144.0, 144.0));
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn pdf_page_size() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--page-width=210mm")
1
        .arg("--page-height=297mm")
1
        .assert()
1
        .success()
1
        .stdout(file::is_pdf().with_page_size(0, 210.0 / 25.4 * 72.0, 297.0 / 25.4 * 72.0));
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn multiple_input_files_create_multi_page_pdf_size_override() {
1
    let one = Path::new("tests/fixtures/bug521-with-viewbox.svg");
1
    let two = Path::new("tests/fixtures/sub-rect-no-unit.svg");
1
    let three = Path::new("tests/fixtures/example.svg");
1
    let mut rsvg_convert = RsvgConvert::new();
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--width=300pt")
1
        .arg("--height=200pt")
1
        .arg(one)
1
        .arg(two)
1
        .arg(three)
1
        .assert()
1
        .success()
1
        .stdout(
1
            file::is_pdf()
1
                .with_page_count(3)
1
                .and(file::is_pdf().with_page_size(0, 300.0, 200.0))
1
                .and(file::is_pdf().with_page_size(1, 300.0, 200.0))
1
                .and(file::is_pdf().with_page_size(2, 300.0, 200.0)),
        );
1
}
#[cfg(system_deps_have_cairo_pdf)]
#[test]
1
fn missing_page_size_yields_error() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--page-width=210mm")
1
        .assert()
1
        .failure()
1
        .stderr(contains("both").and(contains("options")));
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dimensions-in.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--format=pdf")
1
        .arg("--page-height=297mm")
1
        .assert()
1
        .failure()
1
        .stderr(contains("both").and(contains("options")));
1
}
#[test]
1
fn does_not_clip_partial_coverage_pixels() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug677-partial-pixel.svg");
1
    rsvg_convert
1
        .command
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(2, 2));
1
}
#[test]
1
fn background_color_option_with_valid_color() {
1
    RsvgConvert::accepts_arg("--background-color=LimeGreen");
1
}
#[test]
1
fn background_color_option_none() {
1
    RsvgConvert::accepts_arg("--background-color=None");
1
}
#[test]
1
fn background_color_short_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-b")
1
        .arg("#aabbcc")
1
        .assert()
1
        .success();
1
}
#[test]
1
fn background_color_option_invalid_color_yields_error() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--background-color=foobar")
1
        .assert()
1
        .failure()
1
        .stderr(contains("Invalid").and(contains("color")));
1
}
#[test]
1
fn background_color_is_rendered() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/lime-square.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--background-color=purple")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-square-background-ref.png"));
1
}
#[test]
1
fn background_color_rgb() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=rgb(0, 255, 0)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-ref.png"));
1
}
#[test]
1
fn background_color_rgba() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=rgba(0, 255, 0, 0.5)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-transparent-ref.png"));
1
}
#[test]
1
fn background_color_hsl() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=hsl(120, 100%, 50%)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-ref.png"));
1
}
#[test]
1
fn background_color_hsla() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=hsla(120, 100%, 50%, 0.5)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-transparent-ref.png"));
1
}
#[test]
1
fn background_color_hwb() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=hwb(120 0% 0%)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-ref.png"));
1
}
#[test]
1
fn background_color_hwba() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--width=10")
1
        .arg("--height=10")
1
        .arg("--background-color=hwb(120 0% 0% / 0.5)")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/lime-transparent-ref.png"));
1
}
5
fn test_unsupported_background_color(color: &str) {
5
    let color_arg = format!("--background-color={color}");
5
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/empty-10x10.svg");
5
    rsvg_convert
5
        .command
5
        .arg("--width=10")
5
        .arg("--height=10")
5
        .arg(&color_arg)
5
        .assert()
5
        .failure()
5
        .stderr(contains("Invalid value").and(contains("unsupported color syntax")));
5
}
#[test]
1
fn unsupported_background_color() {
1
    let colors = [
1
        "lab(62.2345% -34.9638 47.7721)",
1
        "lch(62.2345% 59.2 126.2)",
1
        "oklab(66.016% -0.1084 0.1114)",
1
        "oklch(0.66016 0.15546 134.231)",
1
        "color(display-p3 -0.6112 1.0079 -0.2192)",
1
    ];
5
    for c in &colors {
5
        test_unsupported_background_color(c);
5
    }
1
}
#[test]
1
fn stylesheet_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--stylesheet=tests/fixtures/empty.css")
1
        .assert()
1
        .success();
1
}
#[test]
1
fn stylesheet_short_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-s")
1
        .arg("tests/fixtures/empty.css")
1
        .assert()
1
        .success();
1
}
#[test]
1
fn stylesheet_option_error() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--stylesheet=foobar")
1
        .assert()
1
        .failure()
1
        .stderr(starts_with("Error reading stylesheet"));
1
}
#[test]
1
fn export_id_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/geometry-element.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--export-id=foo")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(40, 50));
1
}
#[test]
1
fn export_id_with_zero_stroke_width() {
    // https://gitlab.gnome.org/GNOME/librsvg/-/issues/601
    //
    // This tests a bug that manifested itself easily with the --export-id option, but it
    // is not a bug with the option itself.  An object with stroke_width=0 was causing
    // an extra point at the origin to be put in the bounding box, so the final image
    // spanned the origin to the actual visible bounds of the rendered object.
    //
    // We can probably test this more cleanly once we have a render tree.
1
    let mut rsvg_convert =
1
        RsvgConvert::new_with_input("tests/fixtures/bug601-zero-stroke-width.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--export-id=foo")
1
        .assert()
1
        .success()
1
        .stdout(
1
            file::is_png()
1
                .with_contents("tests/fixtures/bug601-zero-stroke-width-render-only-foo.png"),
        );
1
}
#[test]
1
fn export_id_short_option() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-i")
1
        .arg("two")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(100, 200));
1
}
#[test]
1
fn export_id_with_hash_prefix() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-i")
1
        .arg("#two")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(100, 200));
1
}
#[test]
1
fn export_id_option_error() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/dpi.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--export-id=foobar")
1
        .assert()
1
        .failure()
1
        .stderr(starts_with("File stdin does not have an object with id \""));
1
}
#[test]
1
fn unlimited_option() {
1
    RsvgConvert::accepts_arg("--unlimited");
1
}
#[test]
1
fn unlimited_short_option() {
1
    RsvgConvert::accepts_arg("-u");
1
}
#[test]
1
fn keep_aspect_ratio_option() {
1
    let input = Path::new("tests/fixtures/dpi.svg");
1
    let mut rsvg_convert = RsvgConvert::new_with_input(input);
1
    rsvg_convert
1
        .command
1
        .arg("--width=500")
1
        .arg("--height=1000")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(500, 1000));
1
    let mut rsvg_convert = RsvgConvert::new_with_input(input);
1
    rsvg_convert
1
        .command
1
        .arg("--width=500")
1
        .arg("--height=1000")
1
        .arg("--keep-aspect-ratio")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(250, 1000));
1
}
#[test]
1
fn keep_aspect_ratio_short_option() {
1
    let input = Path::new("tests/fixtures/dpi.svg");
1
    let mut rsvg_convert = RsvgConvert::new_with_input(input);
1
    rsvg_convert
1
        .command
1
        .arg("--width=1000")
1
        .arg("--height=500")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(1000, 500));
1
    let mut rsvg_convert = RsvgConvert::new_with_input(input);
1
    rsvg_convert
1
        .command
1
        .arg("--width=1000")
1
        .arg("--height=500")
1
        .arg("-a")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_size(125, 500));
1
}
#[test]
1
fn overflowing_size_is_detected() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/bug591-vbox-overflow.svg");
1
    rsvg_convert.command.assert().failure().stderr(starts_with(
        "The resulting image would be larger than 32767 pixels",
    ));
1
}
#[test]
1
fn accept_language_given() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/accept-language.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--accept-language=es-MX")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/accept-language-es.png"));
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/accept-language.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--accept-language=de")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/accept-language-de.png"));
1
}
#[test]
1
fn accept_language_fallback() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/accept-language.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--accept-language=fr")
1
        .assert()
1
        .success()
1
        .stdout(file::is_png().with_contents("tests/fixtures/accept-language-fallback.png"));
1
}
#[test]
1
fn accept_language_invalid_tag() {
    // underscores are not valid in BCP47 language tags
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/accept-language.svg");
1
    rsvg_convert
1
        .command
1
        .arg("--accept-language=foo_bar")
1
        .assert()
1
        .failure()
1
        .stderr(contains("invalid language tag"));
1
}
#[test]
1
fn keep_image_data_option() {
1
    RsvgConvert::accepts_arg("--keep-image-data");
1
}
#[test]
1
fn no_keep_image_data_option() {
1
    RsvgConvert::accepts_arg("--no-keep-image-data");
1
}
2
fn is_version_output() -> RegexPredicate {
2
    predicates::str::is_match(r"rsvg-convert version \d+\.\d+\.\d+").unwrap()
2
}
#[test]
1
fn version_option() {
1
    RsvgConvert::option_yields_output("--version", is_version_output())
1
}
#[test]
1
fn version_short_option() {
1
    RsvgConvert::option_yields_output("-v", is_version_output())
1
}
2
fn is_usage_output() -> OrPredicate<ContainsPredicate, ContainsPredicate, str> {
2
    contains("Usage:").or(contains("USAGE:"))
2
}
#[test]
1
fn help_option() {
1
    RsvgConvert::option_yields_output("--help", is_usage_output())
1
}
#[test]
1
fn help_short_option() {
1
    RsvgConvert::option_yields_output("-?", is_usage_output())
1
}
#[test]
1
fn multiple_stdin_arguments_not_allowed() {
1
    let mut rsvg_convert = RsvgConvert::new_with_input("tests/fixtures/accept-language.svg");
1
    rsvg_convert
1
        .command
1
        .arg("-")
1
        .arg("-")
1
        .assert()
1
        .failure()
1
        .stderr(contains("Only one input file can be read from stdin"));
1
}