OLD | NEW |
---|---|
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "public/fpdf_edit.h" | 5 #include "public/fpdf_edit.h" |
6 #include "public/fpdfview.h" | 6 #include "public/fpdfview.h" |
7 #include "testing/embedder_test.h" | 7 #include "testing/embedder_test.h" |
8 #include "testing/gmock/include/gmock/gmock-matchers.h" | 8 #include "testing/gmock/include/gmock/gmock-matchers.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/test_support.h" | 10 #include "testing/test_support.h" |
11 | 11 |
12 class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {}; | 12 class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {}; |
13 | 13 |
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 "x\x9C\x3xxxx\x1\r\n" | |
Tom Sepez
2016/04/25 20:20:40
Can we add a comment here along the lines of "Not
etienneb
2016/04/25 20:30:31
Which character do you prefer?
. _ ? \01
I won'
| |
35 "endstream\r\n" | |
36 "endobj\r\n" | |
37 "xref\r\n" | |
38 "0 6\r\n" | |
39 "0000000000 65535 f\r\n" | |
40 "0000000017 00000 n\r\n" | |
41 "0000000066 00000 n\r\n" | |
42 "0000000122 00000 n\r\n" | |
43 "0000000192 00000 n\r\n" | |
44 "0000000301 00000 n\r\n" | |
45 "trailer\r\n" | |
46 "<<\r\n" | |
47 "/Root 1 0 R\r\n" | |
48 "/Info 3 0 R\r\n" | |
49 "/Size 6/ID\\[<.*><.*>\\]>>\r\n" | |
50 "startxref\r\n" | |
51 "379\r\n" | |
52 "%%EOF\r\n"; | |
53 } // namespace | |
54 | |
14 TEST_F(FPDFEditEmbeddertest, EmptyCreation) { | 55 TEST_F(FPDFEditEmbeddertest, EmptyCreation) { |
15 EXPECT_TRUE(CreateEmptyDocument()); | 56 EXPECT_TRUE(CreateEmptyDocument()); |
16 FPDF_PAGE page = FPDFPage_New(document(), 1, 640.0, 480.0); | 57 FPDF_PAGE page = FPDFPage_New(document(), 1, 640.0, 480.0); |
17 EXPECT_NE(nullptr, page); | 58 EXPECT_NE(nullptr, page); |
18 EXPECT_TRUE(FPDFPage_GenerateContent(page)); | 59 EXPECT_TRUE(FPDFPage_GenerateContent(page)); |
19 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); | 60 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
20 EXPECT_THAT(GetString(), | 61 |
21 testing::MatchesRegex( | 62 // The MatchesRegexp doesn't support embedded NUL characters. |
22 "%PDF-1.7\r\n" | 63 std::string result = GetString(); |
23 "%\xA1\xB3\xC5\xD7\r\n" | 64 std::replace(result.begin(), result.end(), '\0', 'x'); |
24 "1 0 obj\r\n" | 65 EXPECT_THAT(result, testing::MatchesRegex( |
25 "<</Pages 2 0 R /Type/Catalog>>\r\n" | 66 std::string(kExpectedPDF, sizeof(kExpectedPDF)))); |
26 "endobj\r\n" | |
27 "2 0 obj\r\n" | |
28 "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n" | |
29 "endobj\r\n" | |
30 "3 0 obj\r\n" | |
31 "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n" | |
32 "endobj\r\n" | |
33 "4 0 obj\r\n" | |
34 "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]" | |
35 "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page" | |
36 ">>\r\n" | |
37 "endobj\r\n" | |
38 "5 0 obj\r\n" | |
39 "<</Filter/FlateDecode/Length 8>>stream\r\n" | |
40 "x\x9C\x3\0\0\0\0\x1\r\n" | |
41 "endstream\r\n" | |
42 "endobj\r\n" | |
43 "xref\r\n" | |
44 "0 6\r\n" | |
45 "0000000000 65535 f\r\n" | |
46 "0000000017 00000 n\r\n" | |
47 "0000000066 00000 n\r\n" | |
48 "0000000122 00000 n\r\n" | |
49 "0000000192 00000 n\r\n" | |
50 "0000000301 00000 n\r\n" | |
51 "trailer\r\n" | |
52 "<<\r\n" | |
53 "/Root 1 0 R\r\n" | |
54 "/Info 3 0 R\r\n" | |
55 "/Size 6/ID\\[<.*><.*>\\]>>\r\n" | |
56 "startxref\r\n" | |
57 "379\r\n" | |
58 "%%EOF\r\n")); | |
59 FPDFPage_Delete(document(), 1); | 67 FPDFPage_Delete(document(), 1); |
60 } | 68 } |
OLD | NEW |