#!/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('page-api');

$td->runtest("basic page API",
             {$td->COMMAND => "test_driver 15 page_api_1.pdf"},
             {$td->STRING => "test 15 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "page_api_1-out.pdf"});
$td->runtest("manual page manipulation",
             {$td->COMMAND => "test_driver 16 page_api_1.pdf"},
             {$td->STRING => "test 16 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "page_api_1-out2.pdf"});
$td->runtest("duplicate page",
             {$td->COMMAND => "test_driver 17 page_api_2.pdf"},
             {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("delete and re-add a page",
             {$td->COMMAND => "test_driver 18 page_api_1.pdf"},
             {$td->STRING => "test 18 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "page_api_1-out3.pdf"});
$td->runtest("duplicate page",
             {$td->COMMAND => "test_driver 19 page_api_1.pdf"},
             {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("remove page we don't have",
             {$td->COMMAND => "test_driver 22 page_api_1.pdf"},
             {$td->FILE => "page_api_1.out2", $td->EXIT_STATUS => 2},
             $td->NORMALIZE_NEWLINES);
$td->runtest("flatten rotation",
             {$td->COMMAND => "qpdf --static-id --qdf".
                  " --no-original-object-ids" .
                  " --flatten-rotation boxes.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "boxes-flattened.pdf"});
$td->runtest("get box methods",
             {$td->COMMAND => "test_driver 94 boxes2.pdf"},
             {$td->STRING => "test 94 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

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