ladybird/Tests/LibPDF/TestPDF.cpp
Ben Wiederhake f890b70eae Tests: Prefer TRY_OR_FAIL() and MUST() over EXPECT(!.is_error())
Note that in some cases (in particular SQL::Result and PDFErrorOr),
there is no Formatter defined for the error type, hence TRY_OR_FAIL
cannot work as-is. Furthermore, this commit leaves untouched the places
where MUST could be replaced by TRY_OR_FAIL.

Inspired by:
https://github.com/SerenityOS/serenity/pull/18710#discussion_r1186892445
2023-05-14 15:39:38 -06:00

51 lines
1.3 KiB
C++

/*
* 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());
}