Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -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 | |
| 5 | #include "public/fpdf_edit.h" |
| 6 | #include "public/fpdfview.h" |
| 7 | #include "testing/embedder_test.h" |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 8 | #include "testing/gmock/include/gmock/gmock-matchers.h" |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 10 | #include "testing/test_support.h" |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 11 | |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 12 | class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {}; |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 13 | |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 14 | namespace { |
| 15 | const char kExpectedPDF[] = |
| 16 | "%PDF-1.7\r\n" |
| 17 | "%\xA1\xB3\xC5\xD7\r\n" |
| 18 | "1 0 obj\r\n" |
| 19 | "<</Pages 2 0 R /Type/Catalog>>\r\n" |
| 20 | "endobj\r\n" |
| 21 | "2 0 obj\r\n" |
| 22 | "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n" |
| 23 | "endobj\r\n" |
| 24 | "3 0 obj\r\n" |
| 25 | "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n" |
| 26 | "endobj\r\n" |
| 27 | "4 0 obj\r\n" |
| 28 | "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]" |
| 29 | "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page" |
| 30 | ">>\r\n" |
| 31 | "endobj\r\n" |
| 32 | "5 0 obj\r\n" |
| 33 | "<</Filter/FlateDecode/Length 8>>stream\r\n" |
| 34 | // Character '_' is matching '\0' (see comment below). |
| 35 | "x\x9C\x3____\x1\r\n" |
| 36 | "endstream\r\n" |
| 37 | "endobj\r\n" |
| 38 | "xref\r\n" |
| 39 | "0 6\r\n" |
| 40 | "0000000000 65535 f\r\n" |
| 41 | "0000000017 00000 n\r\n" |
| 42 | "0000000066 00000 n\r\n" |
| 43 | "0000000122 00000 n\r\n" |
| 44 | "0000000192 00000 n\r\n" |
| 45 | "0000000301 00000 n\r\n" |
| 46 | "trailer\r\n" |
| 47 | "<<\r\n" |
| 48 | "/Root 1 0 R\r\n" |
| 49 | "/Info 3 0 R\r\n" |
| 50 | "/Size 6/ID\\[<.*><.*>\\]>>\r\n" |
| 51 | "startxref\r\n" |
| 52 | "379\r\n" |
| 53 | "%%EOF\r\n"; |
| 54 | } // namespace |
| 55 | |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 56 | TEST_F(FPDFEditEmbeddertest, EmptyCreation) { |
| 57 | EXPECT_TRUE(CreateEmptyDocument()); |
weili | 9b777de | 2016-08-19 16:19:46 -0700 | [diff] [blame] | 58 | FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0); |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 59 | EXPECT_NE(nullptr, page); |
| 60 | EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
Tom Sepez | 0aec19b | 2016-01-07 12:22:44 -0800 | [diff] [blame] | 61 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
etienneb | 7712c26 | 2016-04-26 08:13:45 -0700 | [diff] [blame] | 62 | |
| 63 | // The MatchesRegexp doesn't support embedded NUL ('\0') characters. They are |
| 64 | // replaced by '_' for the purpose of the test. |
| 65 | std::string result = GetString(); |
| 66 | std::replace(result.begin(), result.end(), '\0', '_'); |
| 67 | EXPECT_THAT(result, testing::MatchesRegex( |
| 68 | std::string(kExpectedPDF, sizeof(kExpectedPDF)))); |
weili | 9b777de | 2016-08-19 16:19:46 -0700 | [diff] [blame] | 69 | FPDF_ClosePage(page); |
Tom Sepez | d483eb4 | 2016-01-06 10:03:59 -0800 | [diff] [blame] | 70 | } |