File: filter-asciihexdecode.t

package info (click to toggle)
libpdf-api2-perl 2.047-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,228 kB
  • sloc: perl: 42,227; makefile: 11
file content (55 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download | duplicates (6)
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
use Test::More tests => 7;

use warnings;
use strict;

use PDF::API2::Basic::PDF::Filter::ASCIIHexDecode;

my $in = 'This is a test string.';
my $out = '546869732069732061207465737420737472696e672e';

is(PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->outfilt($in),
   $out,
   q{ASCIIHexDecode test string is encoded correctly});

is(PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->infilt($out),
   $in,
   q{ASCIIHexDecode test string is decoded correctly});


# Add the end-of-document marker
$out .= '>';

is(PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->outfilt($in, 1),
   $out,
   q{ASCIIHexDecode test string with EOD marker is encoded correctly});

is(PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->infilt($out),
   $in,
   q{ASCIIHexDecode test string with EOD marker is decoded correctly});


# Ensure the filter is case-insensitive
$out = uc($out);
is(PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->infilt($out),
   $in,
   q{ASCIIHexDecode is case-insensitive});


# Check for death if invalid characters are included
{
    local $@;
    eval { PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->infilt('This is not valid input') };
    ok($@, q{ASCIIHexDecode dies if invalid characters are passed to infilt});
}

# PDF 1.7, section 7.4.2:
# "If the filter encounters the EOD marker after reading an odd number
# of hexadecimal digits, it shall behave as if a 0 (zero) followed the
# last digit"
my $odd_out = 'FF00F>';
my $expected_bytes = '255 0 240';
my $actual_bytes = join(' ', map { ord } split //, PDF::API2::Basic::PDF::Filter::ASCIIHexDecode->infilt($odd_out));
is($actual_bytes,
   $expected_bytes,
   q{ASCIIHexDecode handles odd numbers of characters correctly});