blob: 97c78b128e0c63195f13e2c24bf40db4d39639ad [file] [log] [blame]
tsepezd0ecd892016-11-08 17:30:04 -08001// Copyright 2016 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
tsepezd0ecd892016-11-08 17:30:04 -08005#include "public/fpdf_flatten.h"
6#include "public/fpdfview.h"
7#include "testing/embedder_test.h"
8#include "testing/gtest/include/gtest/gtest.h"
tsepezd0ecd892016-11-08 17:30:04 -08009
10namespace {
11
Lei Zhangab41f252018-12-23 03:10:50 +000012class FPDFFlattenEmbedderTest : public EmbedderTest {};
tsepezd0ecd892016-11-08 17:30:04 -080013
14} // namespace
15
Lei Zhangab41f252018-12-23 03:10:50 +000016TEST_F(FPDFFlattenEmbedderTest, FlatNothing) {
tsepezd0ecd892016-11-08 17:30:04 -080017 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
18 FPDF_PAGE page = LoadPage(0);
19 EXPECT_TRUE(page);
20 EXPECT_EQ(FLATTEN_NOTHINGTODO, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
21 UnloadPage(page);
22}
23
Lei Zhangab41f252018-12-23 03:10:50 +000024TEST_F(FPDFFlattenEmbedderTest, FlatNormal) {
tsepezd0ecd892016-11-08 17:30:04 -080025 EXPECT_TRUE(OpenDocument("annotiter.pdf"));
26 FPDF_PAGE page = LoadPage(0);
27 EXPECT_TRUE(page);
28 EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_NORMALDISPLAY));
29 UnloadPage(page);
30}
31
Lei Zhangab41f252018-12-23 03:10:50 +000032TEST_F(FPDFFlattenEmbedderTest, FlatPrint) {
tsepezd0ecd892016-11-08 17:30:04 -080033 EXPECT_TRUE(OpenDocument("annotiter.pdf"));
34 FPDF_PAGE page = LoadPage(0);
35 EXPECT_TRUE(page);
36 EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
37 UnloadPage(page);
38}
Lei Zhang3d3cf802018-10-02 18:01:26 +000039
Lei Zhangab41f252018-12-23 03:10:50 +000040TEST_F(FPDFFlattenEmbedderTest, BUG_890322) {
Lei Zhang3d3cf802018-10-02 18:01:26 +000041 static const char md5_hash[] = "6c674642154408e877d88c6c082d67e9";
42 EXPECT_TRUE(OpenDocument("bug_890322.pdf"));
43 FPDF_PAGE page = LoadPage(0);
44 ASSERT_TRUE(page);
45
46 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
47 CompareBitmap(bitmap.get(), 200, 200, md5_hash);
48
49 EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
50 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
51
52 UnloadPage(page);
53
54 VerifySavedDocument(200, 200, md5_hash);
55}
Lei Zhang0233af42018-10-18 17:46:52 +000056
Lei Zhangab41f252018-12-23 03:10:50 +000057TEST_F(FPDFFlattenEmbedderTest, BUG_896366) {
Lei Zhang0233af42018-10-18 17:46:52 +000058 static const char md5_hash[] = "f71ab085c52c8445ae785eca3ec858b1";
59 EXPECT_TRUE(OpenDocument("bug_896366.pdf"));
60 FPDF_PAGE page = LoadPage(0);
61 ASSERT_TRUE(page);
62
63 ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page, FPDF_ANNOT);
64 CompareBitmap(bitmap.get(), 612, 792, md5_hash);
65
66 EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
67 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
68
69 UnloadPage(page);
70
71 VerifySavedDocument(612, 792, md5_hash);
72}