summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Li <weili@chromium.org>2015-11-05 13:39:14 -0800
committerWei Li <weili@chromium.org>2015-11-05 13:39:14 -0800
commit823c26ae904b3431475c750d0bda1ab1be7e2fdc (patch)
treeff084a3b9addb78cd491f5059864ee8303657be1
parent5570d23890cc7bae4903a29fbcf8ac543ba1a2c7 (diff)
downloadpdfium-823c26ae904b3431475c750d0bda1ab1be7e2fdc.tar.xz
Merge to XFA: Add base test for RebuildCrossRef function.
This tests whether RebuildCrossRef could handle well-formatted pdf file. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1409013005 . (cherry picked from commit 4544797e8998a31e7bc3f5439a5982f7f66dff26) Review URL: https://codereview.chromium.org/1413343004 .
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp41
-rw-r--r--testing/resources/parser_rebuildxref_correct.pdf55
2 files changed, 96 insertions, 0 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
index 827d1cec28..73b46b52c2 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
@@ -5,6 +5,28 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "../../../include/fpdfapi/fpdf_parser.h"
+#include "../../../include/fxcrt/fx_stream.h"
+
+class CPDF_TestParser : public CPDF_Parser {
+ public:
+ CPDF_TestParser() {}
+ ~CPDF_TestParser() {}
+
+ bool InitTest(const FX_CHAR* path) {
+ IFX_FileRead* pFileAccess = FX_CreateFileRead(path);
+ if (!pFileAccess)
+ return false;
+
+ // For the test file, the header is set at the beginning.
+ m_Syntax.InitParser(pFileAccess, 0);
+ return true;
+ }
+
+ private:
+ // Add test case as private friend so that RebuildCrossRef in CPDF_Parser
+ // can be accessed.
+ FRIEND_TEST(fpdf_parser_parser, RebuildCrossRefCorrectly);
+};
// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal.
// Come up or wait for something better.
@@ -168,3 +190,22 @@ TEST(fpdf_parser_parser, ReadHexString) {
EXPECT_EQ(1, parser.SavePos());
}
}
+
+TEST(fpdf_parser_parser, RebuildCrossRefCorrectly) {
+ CPDF_TestParser parser;
+ ASSERT_TRUE(
+ parser.InitTest("testing/resources/parser_rebuildxref_correct.pdf"));
+
+ ASSERT_TRUE(parser.RebuildCrossRef());
+ const FX_FILESIZE offsets[] = {0, 15, 61, 154, 296, 374, 450};
+ const FX_WORD versions[] = {0, 0, 2, 4, 6, 8, 0};
+ static_assert(FX_ArraySize(offsets) == FX_ArraySize(versions),
+ "numbers of offsets and versions should be same.");
+ ASSERT_EQ(FX_ArraySize(offsets), parser.m_CrossRef.GetSize());
+ ASSERT_EQ(FX_ArraySize(versions), parser.m_ObjVersion.GetSize());
+
+ for (int i = 0; i < FX_ArraySize(offsets); ++i) {
+ EXPECT_EQ(offsets[i], parser.m_CrossRef.GetAt(i));
+ EXPECT_EQ(versions[i], parser.m_ObjVersion.GetAt(i));
+ }
+}
diff --git a/testing/resources/parser_rebuildxref_correct.pdf b/testing/resources/parser_rebuildxref_correct.pdf
new file mode 100644
index 0000000000..5e4f60bc38
--- /dev/null
+++ b/testing/resources/parser_rebuildxref_correct.pdf
@@ -0,0 +1,55 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 2 R
+>>
+2 2 obj <<
+ /Type /Pages
+ /MediaBox [ 0 0 200 200 ]
+ /Count 1
+ /Kids [ 3 4 R ]
+>>
+endobj
+3 4 obj <<
+ /Type /Page
+ /Parent 2 2 R
+ /Resources <<
+ /Font <<
+ /F1 4 6 R
+ /F2 5 8 R
+ >>
+ >>
+ /Contents 6 0 R
+>>
+endobj
+4 6 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Times-Roman
+>>
+endobj
+5 8 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+6 0 obj <<
+>>
+stream
+BT
+20 50 Td
+/F1 12 Tf
+(Hello, world!) Tj
+0 50 Td
+/F2 16 Tf
+(Goodbye, world!) Tj
+ET
+endstream
+endobj
+trailer <<
+ /Size 6
+ /Root 1 0 R
+>>
+%%EOF