summaryrefslogtreecommitdiff
path: root/examples/qtest/mod-info.test
blob: 145bf133af823e0ec73f8ac9e475003e0573d1f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env perl
require 5.008;
BEGIN { $^W = 1; }
use strict;
use File::Copy;

chdir("mod-info");

require TestDriver;

my $td = new TestDriver('pdf-mod-info');

my $prg = "pdf-mod-info";
my $qpdf = $ENV{'QPDF_BIN'} or die;

cleanup();

$td->runtest("usage #1",
	     {$td->COMMAND => "$prg -in target.pdf"},
	     {$td->FILE => "usage.out",
	      $td->EXIT_STATUS => 2},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("usage #2",
	     {$td->COMMAND => "$prg -key abc -val def"},
	     {$td->FILE => "usage.out",
	      $td->EXIT_STATUS => 2},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("usage #3",
	     {$td->COMMAND => "$prg -key abc -val def abc"},
	     {$td->FILE => "usage.out",
	      $td->EXIT_STATUS => 2},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("usage #4",
	     {$td->COMMAND => "$prg -in source1.pdf -key date -val 01/01/01 -val 12/12/12"},
	     {$td->FILE => "usage.out",
	      $td->EXIT_STATUS => 2},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("dump #1",
	     {$td->COMMAND => "$prg --dump -in files/source1.pdf"},
	     {$td->FILE => "dump.out",
	      $td->EXIT_STATUS => 0},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("dump #2",
	     {$td->COMMAND => "$prg --dump -in files/no-info.pdf"},
	     {$td->STRING => "",
	      $td->EXIT_STATUS => 0},
	     $td->NORMALIZE_NEWLINES);

$td->runtest("dump #3",
	     {$td->COMMAND => "$prg --dump -in files/empty-info.pdf"},
	     {$td->STRING => "",
	      $td->EXIT_STATUS => 0});

run_and_cmp("modify Subject",
	    "$prg -in files/source1.pdf -out out.pdf -key Subject " .
	    "-val \"Export Business\"",
	    "", "out.pdf", "files/1.qdf");

run_and_cmp("add Subject, remove Producer, modify CreationDate",
	    "$prg -in files/source2.pdf -out out.pdf -key Subject " .
	    "-val \"Tammlin\" -key Producer -key CreationDate -val 12/12",
	    "", "out.pdf", "files/2.qdf");

run_and_cmp("add Subject (empty-info file)",
	    "$prg -in files/empty-info.pdf -out out.pdf -key Subject " .
	    "-val Tammlin",
	    "", "out.pdf", "files/3.qdf");

copy("files/no-info.pdf", "no-info.pdf") or die "can't copy no-info: $!";
run_and_cmp("in-place Producer added (no-info file)",
	    "$prg -in no-info.pdf -key Producer -val \"Obivan Kinobi\"",
	    "", "no-info.pdf", "files/4.qdf");

cleanup();

$td->report(15);

sub cleanup
{
    unlink (<*.pdf>);
}

sub run_and_cmp
{
    my ($dsc, $cmd, $out, $fout, $fexp) = @_;
    $td->runtest($dsc,
		 {$td->COMMAND => "$cmd --static-id"},
		 {$td->STRING => $out,
		  $td->EXIT_STATUS => 0});
    $td->runtest("$dsc output",
		 {$td->COMMAND => "$qpdf --static-id" .
		      " --no-original-object-ids -qdf $fout -"},
		 {$td->FILE => $fexp,
		  $td->EXIT_STATUS => 0});
}