From 29561e53b60c680e4f6fca9d91047952b2de7906 Mon Sep 17 00:00:00 2001 From: xlou Date: Tue, 6 Feb 2018 00:11:23 +0000 Subject: Add rendering embeddertests for FPDF_ImportNPagesToOne. One test is added to render the output pdf of FPDF_ImportNPagesToOne, and check the width, height and hash value of the rendered image. Change-Id: Idd3f953d62ecd4e85ad52a9323eb13243dc49597 Reviewed-on: https://pdfium-review.googlesource.com/25330 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- fpdfsdk/fpdfppo_embeddertest.cpp | 26 +++++- testing/resources/hello_world_multi_pages.in | 98 ---------------------- testing/resources/hello_world_multi_pages.pdf | 114 -------------------------- testing/resources/rectangles_multi_pages.in | 98 ++++++++++++++++++++++ testing/resources/rectangles_multi_pages.pdf | 114 ++++++++++++++++++++++++++ 5 files changed, 236 insertions(+), 214 deletions(-) delete mode 100644 testing/resources/hello_world_multi_pages.in delete mode 100644 testing/resources/hello_world_multi_pages.pdf create mode 100644 testing/resources/rectangles_multi_pages.in create mode 100644 testing/resources/rectangles_multi_pages.pdf diff --git a/fpdfsdk/fpdfppo_embeddertest.cpp b/fpdfsdk/fpdfppo_embeddertest.cpp index deb87b533a..2a4c774bae 100644 --- a/fpdfsdk/fpdfppo_embeddertest.cpp +++ b/fpdfsdk/fpdfppo_embeddertest.cpp @@ -1,6 +1,8 @@ // 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 #include #include "public/cpp/fpdf_deleters.h" @@ -59,7 +61,7 @@ TEST_F(FPDFPPOEmbeddertest, ImportPages) { } TEST_F(FPDFPPOEmbeddertest, ImportNPages) { - ASSERT_TRUE(OpenDocument("hello_world_multi_pages.pdf")); + ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf")); std::unique_ptr output_doc_2up( FPDF_ImportNPagesToOne(document(), 612, 792, 2, 1)); @@ -80,7 +82,7 @@ TEST_F(FPDFPPOEmbeddertest, ImportNPages) { } TEST_F(FPDFPPOEmbeddertest, BadNupParams) { - ASSERT_TRUE(OpenDocument("hello_world_multi_pages.pdf")); + ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf")); FPDF_DOCUMENT output_doc_zero_row = FPDF_ImportNPagesToOne(document(), 612, 792, 0, 3); @@ -98,6 +100,26 @@ TEST_F(FPDFPPOEmbeddertest, BadNupParams) { // TODO(Xlou): Add more tests to check output doc content of // FPDF_ImportNPagesToOne() +TEST_F(FPDFPPOEmbeddertest, NupRenderImage) { + ASSERT_TRUE(OpenDocument("rectangles_multi_pages.pdf")); + const int kPageCount = 2; + constexpr const char* kExpectedMD5s[kPageCount] = { + "4d225b961da0f1bced7c83273e64c9b6", "fb18142190d770cfbc329d2b071aee4d"}; + std::unique_ptr output_doc_3up( + FPDF_ImportNPagesToOne(document(), 792, 612, 3, 1)); + ASSERT_TRUE(output_doc_3up); + ASSERT_EQ(kPageCount, FPDF_GetPageCount(output_doc_3up.get())); + for (int i = 0; i < kPageCount; ++i) { + std::unique_ptr page( + FPDF_LoadPage(output_doc_3up.get(), i)); + ASSERT_TRUE(page); + std::unique_ptr bitmap( + RenderPageWithFlags(page.get(), nullptr, 0)); + EXPECT_EQ(792, FPDFBitmap_GetWidth(bitmap.get())); + EXPECT_EQ(612, FPDFBitmap_GetHeight(bitmap.get())); + EXPECT_EQ(kExpectedMD5s[i], HashBitmap(bitmap.get())); + } +} TEST_F(FPDFPPOEmbeddertest, BadRepeatViewerPref) { ASSERT_TRUE(OpenDocument("repeat_viewer_ref.pdf")); diff --git a/testing/resources/hello_world_multi_pages.in b/testing/resources/hello_world_multi_pages.in deleted file mode 100644 index 125b8ea090..0000000000 --- a/testing/resources/hello_world_multi_pages.in +++ /dev/null @@ -1,98 +0,0 @@ -{{header}} -{{object 1 0}} << - /Type /Catalog - /Pages 2 0 R ->> -endobj -{{object 2 0}} << - /Type /Pages - /MediaBox [ 0 0 200 250 ] - /Count 5 - /Kids [ 3 0 R 5 0 R 7 0 R 9 0 R 11 0 R ] ->> -endobj -{{object 3 0}} << - /Type /Page - /Parent 2 0 R - /Contents 4 0 R ->> -endobj -{{object 4 0}} << ->> -stream -q -1 1 0 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -{{object 5 0}} << - /Type /Page - /Parent 2 0 R - /Rotate 90 - /Contents 6 0 R ->> -endobj -{{object 6 0}} << ->> -stream -q -0 1 1 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -{{object 7 0}} << - /Type /Page - /Parent 2 0 R - /Contents 8 0 R ->> -endobj -{{object 8 0}} << ->> -stream -q -1 0 0 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -{{object 9 0}} << - /Type /Page - /Parent 2 0 R - /Contents 10 0 R ->> -{{object 10 0}} << ->> -stream -q -0 1 0 rg -100 0 30 50 re B* -100 150 50 30 re B* -Q -endstream -endobj -endobj -{{object 11 0}} << - /Type /Page - /Parent 2 0 R - /Contents 12 0 R ->> -endobj -{{object 12 0}} << ->> -stream -q -0 0 0 rg -0 90 80 60 re B* -100 150 50 30 re B* -Q -endstream -endobj -{{xref}} -{{trailer}} -{{startxref}} -%%EOF diff --git a/testing/resources/hello_world_multi_pages.pdf b/testing/resources/hello_world_multi_pages.pdf deleted file mode 100644 index bacb1dd3a8..0000000000 --- a/testing/resources/hello_world_multi_pages.pdf +++ /dev/null @@ -1,114 +0,0 @@ -%PDF-1.7 -% ò¤ô -1 0 obj << - /Type /Catalog - /Pages 2 0 R ->> -endobj -2 0 obj << - /Type /Pages - /MediaBox [ 0 0 200 250 ] - /Count 5 - /Kids [ 3 0 R 5 0 R 7 0 R 9 0 R 11 0 R ] ->> -endobj -3 0 obj << - /Type /Page - /Parent 2 0 R - /Contents 4 0 R ->> -endobj -4 0 obj << ->> -stream -q -1 1 0 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -5 0 obj << - /Type /Page - /Parent 2 0 R - /Rotate 90 - /Contents 6 0 R ->> -endobj -6 0 obj << ->> -stream -q -0 1 1 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -7 0 obj << - /Type /Page - /Parent 2 0 R - /Contents 8 0 R ->> -endobj -8 0 obj << ->> -stream -q -1 0 0 rg -100 0 30 50 re B* -70 67 50 30 re B* -Q -endstream -endobj -9 0 obj << - /Type /Page - /Parent 2 0 R - /Contents 10 0 R ->> -10 0 obj << ->> -stream -q -0 1 0 rg -100 0 30 50 re B* -100 150 50 30 re B* -Q -endstream -endobj -endobj -11 0 obj << - /Type /Page - /Parent 2 0 R - /Contents 12 0 R ->> -endobj -12 0 obj << ->> -stream -q -0 0 0 rg -0 90 80 60 re B* -100 150 50 30 re B* -Q -endstream -endobj -xref -0 13 -0000000000 65535 f -0000000015 00000 n -0000000068 00000 n -0000000186 00000 n -0000000255 00000 n -0000000342 00000 n -0000000424 00000 n -0000000511 00000 n -0000000580 00000 n -0000000667 00000 n -0000000730 00000 n -0000000827 00000 n -0000000898 00000 n -trailer<< /Root 1 0 R /Size 13 >> -startxref -987 -%%EOF diff --git a/testing/resources/rectangles_multi_pages.in b/testing/resources/rectangles_multi_pages.in new file mode 100644 index 0000000000..125b8ea090 --- /dev/null +++ b/testing/resources/rectangles_multi_pages.in @@ -0,0 +1,98 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R +>> +endobj +{{object 2 0}} << + /Type /Pages + /MediaBox [ 0 0 200 250 ] + /Count 5 + /Kids [ 3 0 R 5 0 R 7 0 R 9 0 R 11 0 R ] +>> +endobj +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /Contents 4 0 R +>> +endobj +{{object 4 0}} << +>> +stream +q +1 1 0 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +{{object 5 0}} << + /Type /Page + /Parent 2 0 R + /Rotate 90 + /Contents 6 0 R +>> +endobj +{{object 6 0}} << +>> +stream +q +0 1 1 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +{{object 7 0}} << + /Type /Page + /Parent 2 0 R + /Contents 8 0 R +>> +endobj +{{object 8 0}} << +>> +stream +q +1 0 0 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +{{object 9 0}} << + /Type /Page + /Parent 2 0 R + /Contents 10 0 R +>> +{{object 10 0}} << +>> +stream +q +0 1 0 rg +100 0 30 50 re B* +100 150 50 30 re B* +Q +endstream +endobj +endobj +{{object 11 0}} << + /Type /Page + /Parent 2 0 R + /Contents 12 0 R +>> +endobj +{{object 12 0}} << +>> +stream +q +0 0 0 rg +0 90 80 60 re B* +100 150 50 30 re B* +Q +endstream +endobj +{{xref}} +{{trailer}} +{{startxref}} +%%EOF diff --git a/testing/resources/rectangles_multi_pages.pdf b/testing/resources/rectangles_multi_pages.pdf new file mode 100644 index 0000000000..bacb1dd3a8 --- /dev/null +++ b/testing/resources/rectangles_multi_pages.pdf @@ -0,0 +1,114 @@ +%PDF-1.7 +% ò¤ô +1 0 obj << + /Type /Catalog + /Pages 2 0 R +>> +endobj +2 0 obj << + /Type /Pages + /MediaBox [ 0 0 200 250 ] + /Count 5 + /Kids [ 3 0 R 5 0 R 7 0 R 9 0 R 11 0 R ] +>> +endobj +3 0 obj << + /Type /Page + /Parent 2 0 R + /Contents 4 0 R +>> +endobj +4 0 obj << +>> +stream +q +1 1 0 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +5 0 obj << + /Type /Page + /Parent 2 0 R + /Rotate 90 + /Contents 6 0 R +>> +endobj +6 0 obj << +>> +stream +q +0 1 1 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +7 0 obj << + /Type /Page + /Parent 2 0 R + /Contents 8 0 R +>> +endobj +8 0 obj << +>> +stream +q +1 0 0 rg +100 0 30 50 re B* +70 67 50 30 re B* +Q +endstream +endobj +9 0 obj << + /Type /Page + /Parent 2 0 R + /Contents 10 0 R +>> +10 0 obj << +>> +stream +q +0 1 0 rg +100 0 30 50 re B* +100 150 50 30 re B* +Q +endstream +endobj +endobj +11 0 obj << + /Type /Page + /Parent 2 0 R + /Contents 12 0 R +>> +endobj +12 0 obj << +>> +stream +q +0 0 0 rg +0 90 80 60 re B* +100 150 50 30 re B* +Q +endstream +endobj +xref +0 13 +0000000000 65535 f +0000000015 00000 n +0000000068 00000 n +0000000186 00000 n +0000000255 00000 n +0000000342 00000 n +0000000424 00000 n +0000000511 00000 n +0000000580 00000 n +0000000667 00000 n +0000000730 00000 n +0000000827 00000 n +0000000898 00000 n +trailer<< /Root 1 0 R /Size 13 >> +startxref +987 +%%EOF -- cgit v1.2.3