diff options
author | Nicolas Pena <npm@chromium.org> | 2017-06-06 16:12:10 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-07 00:58:34 +0000 |
commit | d9d6c29879780db829694d0023a377581bbc9769 (patch) | |
tree | f1c3b279e183ef709c132780df7187f65c3d246e | |
parent | 7dee685df0309401ad37c30c49a56d8523d1f8bb (diff) | |
download | pdfium-d9d6c29879780db829694d0023a377581bbc9769.tar.xz |
Fix EmptyCreation test
The Contents stream of a page is optional per PDF spec 1.7 Table 3.27.
This CL fixes the empty creation test to acknowledge that.
Change-Id: I1e59a1fedbf00eafabe87962830d62d8883a5e1f
Reviewed-on: https://pdfium-review.googlesource.com/6311
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r-- | core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 26 |
2 files changed, 11 insertions, 22 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 7abf7a4964..2f00c7db09 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -62,10 +62,9 @@ CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} void CPDF_PageContentGenerator::GenerateContent() { CPDF_Document* pDoc = m_pDocument.Get(); CFX_ByteTextBuf buf; - if (!m_pageObjects.empty()) { - if (!ProcessPageObjects(&buf)) - return; - } + if (!ProcessPageObjects(&buf)) + return; + CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict.Get(); CPDF_Object* pContent = pPageDict ? pPageDict->GetObjectFor("Contents") : nullptr; diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index f52848c81d..25377fe6f8 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -138,31 +138,24 @@ const char kExpectedPDF[] = "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n" "endobj\r\n" "4 0 obj\r\n" - "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]" - "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page" + "<</MediaBox\\[ 0 0 640 480\\]/Parent 2 0 R /Resources<<>>" + "/Rotate 0/Type/Page" ">>\r\n" "endobj\r\n" - "5 0 obj\r\n" - "<</Filter/FlateDecode/Length 8>>stream\r\n" - // Character '_' is matching '\0' (see comment below). - "x\x9C\x3____\x1\r\n" - "endstream\r\n" - "endobj\r\n" "xref\r\n" - "0 6\r\n" + "0 5\r\n" "0000000000 65535 f\r\n" "0000000017 00000 n\r\n" "0000000066 00000 n\r\n" "0000000122 00000 n\r\n" "0000000192 00000 n\r\n" - "0000000301 00000 n\r\n" "trailer\r\n" "<<\r\n" "/Root 1 0 R\r\n" "/Info 3 0 R\r\n" - "/Size 6/ID\\[<.*><.*>\\]>>\r\n" + "/Size 5/ID\\[<.*><.*>\\]>>\r\n" "startxref\r\n" - "379\r\n" + "285\r\n" "%%EOF\r\n"; } // namespace @@ -171,15 +164,12 @@ TEST_F(FPDFEditEmbeddertest, EmptyCreation) { EXPECT_TRUE(CreateEmptyDocument()); FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0); EXPECT_NE(nullptr, page); + // The FPDFPage_GenerateContent call should do nothing. EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - // The MatchesRegexp doesn't support embedded NUL ('\0') characters. They are - // replaced by '_' for the purpose of the test. - std::string result = GetString(); - std::replace(result.begin(), result.end(), '\0', '_'); - EXPECT_THAT(result, testing::MatchesRegex( - std::string(kExpectedPDF, sizeof(kExpectedPDF)))); + EXPECT_THAT(GetString(), testing::MatchesRegex(std::string( + kExpectedPDF, sizeof(kExpectedPDF)))); FPDF_ClosePage(page); } |