#!/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('writer-version');

my $n_tests = 7;

# Min/Force version
$td->runtest("set min version",
             {$td->COMMAND => "qpdf --verbose --min-version=1.6 good1.pdf a.pdf"},
             {$td->STRING => "qpdf: wrote file a.pdf\n",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check version",
             {$td->COMMAND => "qpdf --check a.pdf"},
             {$td->FILE => "min-version.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("force version",
             {$td->COMMAND => "qpdf --force-version=1.4 a.pdf b.pdf"},
             {$td->STRING => "",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check version",
             {$td->COMMAND => "qpdf --check b.pdf"},
             {$td->FILE => "forced-version.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
unlink "a.pdf", "b.pdf" or die;
$td->runtest("C API: min/force versions",
             {$td->COMMAND => "qpdf-ctest 14 object-stream.pdf '' a.pdf b.pdf"},
             {$td->STRING => "C test 14 done\n",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("C check version 1",
             {$td->COMMAND => "qpdf-ctest 1 a.pdf '' ''"},
             {$td->FILE => "c-min-version.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("C check version 2",
             {$td->COMMAND => "qpdf --check b.pdf"},
             {$td->FILE => "forced-version.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

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