tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 1 | // 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 | |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 5 | #include "public/fpdf_flatten.h" |
| 6 | #include "public/fpdfview.h" |
| 7 | #include "testing/embedder_test.h" |
| 8 | #include "testing/gtest/include/gtest/gtest.h" |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 9 | |
| 10 | namespace { |
| 11 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 12 | class FPDFFlattenEmbedderTest : public EmbedderTest {}; |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 13 | |
| 14 | } // namespace |
| 15 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 16 | TEST_F(FPDFFlattenEmbedderTest, FlatNothing) { |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 17 | 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 Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 24 | TEST_F(FPDFFlattenEmbedderTest, FlatNormal) { |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 25 | 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 Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 32 | TEST_F(FPDFFlattenEmbedderTest, FlatPrint) { |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 33 | 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 Zhang | 3d3cf80 | 2018-10-02 18:01:26 +0000 | [diff] [blame] | 39 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 40 | TEST_F(FPDFFlattenEmbedderTest, BUG_890322) { |
Lei Zhang | 3d3cf80 | 2018-10-02 18:01:26 +0000 | [diff] [blame] | 41 | 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 Zhang | 0233af4 | 2018-10-18 17:46:52 +0000 | [diff] [blame] | 56 | |
Lei Zhang | ab41f25 | 2018-12-23 03:10:50 +0000 | [diff] [blame] | 57 | TEST_F(FPDFFlattenEmbedderTest, BUG_896366) { |
Lei Zhang | 0233af4 | 2018-10-18 17:46:52 +0000 | [diff] [blame] | 58 | 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 | } |