blob: 2b244c4093b1f16883fa484074845c7e5f4442d0 [file] [log] [blame]
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "build/build_config.h"
#include "public/fpdf_flatten.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class FPDFFlattenEmbedderTest : public EmbedderTest {};
} // namespace
TEST_F(FPDFFlattenEmbedderTest, FlatNothing) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
FPDF_PAGE page = LoadPage(0);
EXPECT_TRUE(page);
EXPECT_EQ(FLATTEN_NOTHINGTODO, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
UnloadPage(page);
}
TEST_F(FPDFFlattenEmbedderTest, FlatNormal) {
EXPECT_TRUE(OpenDocument("annotiter.pdf"));
FPDF_PAGE page = LoadPage(0);
EXPECT_TRUE(page);
EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
UnloadPage(page);
}
TEST_F(FPDFFlattenEmbedderTest, FlatPrint) {
EXPECT_TRUE(OpenDocument("annotiter.pdf"));
FPDF_PAGE page = LoadPage(0);
EXPECT_TRUE(page);
EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
UnloadPage(page);
}
// TODO(crbug.com/pdfium/11): Fix this test and enable.
#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
#define MAYBE_BUG_861842 DISABLED_BUG_861842
#else
#define MAYBE_BUG_861842 BUG_861842
#endif
TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_861842) {
#if defined(OS_WIN)
static const char kCheckboxHash[] = "95fba3cb7bce7e0d3c94279f60984e17";
#elif defined(OS_MACOSX)
static const char kCheckboxHash[] = "0a1d1d63d4452bc26a1c5c547d309655";
#else
static const char kCheckboxHash[] = "594265790b81df2d93120d33b72a6ada";
#endif
EXPECT_TRUE(OpenDocument("bug_861842.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
CompareBitmap(bitmap.get(), 100, 120, kCheckboxHash);
EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
UnloadPage(page);
// TODO(crbug.com/861842): This should not render blank.
static const char kBlankPageHash[] = "48400809c3862dae64b0cd00d51057a4";
VerifySavedDocument(100, 120, kBlankPageHash);
}
// TODO(crbug.com/pdfium/11): Fix this test and enable.
#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
#define MAYBE_BUG_890322 DISABLED_BUG_890322
#else
#define MAYBE_BUG_890322 BUG_890322
#endif
TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_890322) {
static const char md5_hash[] = "6c674642154408e877d88c6c082d67e9";
EXPECT_TRUE(OpenDocument("bug_890322.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
CompareBitmap(bitmap.get(), 200, 200, md5_hash);
EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
UnloadPage(page);
VerifySavedDocument(200, 200, md5_hash);
}
// TODO(crbug.com/pdfium/11): Fix this test and enable.
#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
#define MAYBE_BUG_896366 DISABLED_BUG_896366
#else
#define MAYBE_BUG_896366 BUG_896366
#endif
TEST_F(FPDFFlattenEmbedderTest, MAYBE_BUG_896366) {
static const char md5_hash[] = "f71ab085c52c8445ae785eca3ec858b1";
EXPECT_TRUE(OpenDocument("bug_896366.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
CompareBitmap(bitmap.get(), 612, 792, md5_hash);
EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
UnloadPage(page);
VerifySavedDocument(612, 792, md5_hash);
}