diff options
author | etienneb <etienneb@chromium.org> | 2016-04-26 08:13:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-26 08:13:45 -0700 |
commit | 7712c26b05c85399afbf8cb3d363836e678ad443 (patch) | |
tree | bf5d419c19ae802eec16aea3fa791640872ed9ed /fpdfsdk | |
parent | 3081cc07898dd19a0a00d406ac3555c111940dce (diff) | |
download | pdfium-7712c26b05c85399afbf8cb3d363836e678ad443.tar.xz |
Fix unittest with embedded NUL character.
There is an embedded NUL character (previously line 40).
The test was working because the beginning ot the string is identical.
But, the rest of the string wasn't compare at all.
TESTED: manually
etienneb@burger:~/src/pdfium/pdfium$ out/Debug/pdfium_embeddertests --gtest_filter=*.EmptyCreation
Note: Google Test filter = *.EmptyCreation
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FPDFEditEmbeddertest
[ RUN ] FPDFEditEmbeddertest.EmptyCreation
[ OK ] FPDFEditEmbeddertest.EmptyCreation (13 ms)
[----------] 1 test from FPDFEditEmbeddertest (13 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (13 ms total)
[ PASSED ] 1 test.
R=dsinclair
BUG=589955
Review URL: https://codereview.chromium.org/1916083002
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 480ef51dbd..720dcdec01 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -11,50 +11,60 @@ class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {}; +namespace { +const char kExpectedPDF[] = + "%PDF-1.7\r\n" + "%\xA1\xB3\xC5\xD7\r\n" + "1 0 obj\r\n" + "<</Pages 2 0 R /Type/Catalog>>\r\n" + "endobj\r\n" + "2 0 obj\r\n" + "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n" + "endobj\r\n" + "3 0 obj\r\n" + "<</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" + ">>\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" + "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" + "startxref\r\n" + "379\r\n" + "%%EOF\r\n"; +} // namespace + TEST_F(FPDFEditEmbeddertest, EmptyCreation) { EXPECT_TRUE(CreateEmptyDocument()); FPDF_PAGE page = FPDFPage_New(document(), 1, 640.0, 480.0); EXPECT_NE(nullptr, page); EXPECT_TRUE(FPDFPage_GenerateContent(page)); EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); - EXPECT_THAT(GetString(), - testing::MatchesRegex( - "%PDF-1.7\r\n" - "%\xA1\xB3\xC5\xD7\r\n" - "1 0 obj\r\n" - "<</Pages 2 0 R /Type/Catalog>>\r\n" - "endobj\r\n" - "2 0 obj\r\n" - "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n" - "endobj\r\n" - "3 0 obj\r\n" - "<</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" - ">>\r\n" - "endobj\r\n" - "5 0 obj\r\n" - "<</Filter/FlateDecode/Length 8>>stream\r\n" - "x\x9C\x3\0\0\0\0\x1\r\n" - "endstream\r\n" - "endobj\r\n" - "xref\r\n" - "0 6\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" - "startxref\r\n" - "379\r\n" - "%%EOF\r\n")); + + // 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)))); FPDFPage_Delete(document(), 1); } |