#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('xref-streams');

my $n_tests = 3;

# Handle xref stream with more entries than reported (bug 2872265)
$td->runtest("xref with short size",
             {$td->COMMAND => "qpdf --show-xref xref-with-short-size.pdf"},
             {$td->FILE => "xref-with-short-size.out",
              $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
$td->runtest("recover xref with short size",
             {$td->COMMAND => "qpdf xref-with-short-size.pdf a.pdf"},
             {$td->FILE => "xref-with-short-size-recover.out",
              $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
$td->runtest("show new xref stream",
             {$td->COMMAND => "qpdf --show-xref a.pdf"},
             {$td->FILE => "xref-with-short-size-new.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

cleanup();
$td->report($n_tests);
