summaryrefslogtreecommitdiff
path: root/Tests/LibPDF/TestPDF.cpp
blob: 8b4325c0108d5ed7670494ac36a272cff3cf8330 (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
/*
 * Copyright (c) 2021, Simon Woertz <simon@woertz.at>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/DeprecatedString.h>
#include <AK/Forward.h>
#include <LibCore/MappedFile.h>
#include <LibPDF/Document.h>
#include <LibTest/Macros.h>
#include <LibTest/TestCase.h>

TEST_CASE(linearized_pdf)
{
    auto file = Core::MappedFile::map("linearized.pdf"sv).release_value();
    auto document = MUST(PDF::Document::create(file->bytes()));
    MUST(document->initialize());
    EXPECT_EQ(document->get_page_count(), 1U);
}

TEST_CASE(non_linearized_pdf)
{
    auto file = Core::MappedFile::map("non-linearized.pdf"sv).release_value();
    auto document = MUST(PDF::Document::create(file->bytes()));
    MUST(document->initialize());
    EXPECT_EQ(document->get_page_count(), 1U);
}

TEST_CASE(complex_pdf)
{
    auto file = Core::MappedFile::map("complex.pdf"sv).release_value();
    auto document = MUST(PDF::Document::create(file->bytes()));
    MUST(document->initialize());
    EXPECT_EQ(document->get_page_count(), 3U);
}

TEST_CASE(empty_file_issue_10702)
{
    AK::ReadonlyBytes empty;
    auto document = PDF::Document::create(empty);
    EXPECT(document.is_error());
}

TEST_CASE(truncated_pdf_header_issue_10717)
{
    AK::DeprecatedString string { "%PDF-2.11%" };
    auto document = PDF::Document::create(string.bytes());
    EXPECT(document.is_error());
}