Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2783)

Unified Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp

Issue 1409013005: Add base test for RebuildCrossRef function. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: one more comment Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/resources/parser_rebuildxref_correct.pdf » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
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 827d1cec286a07ebe86f10fa01410c2d7edca7b4..73b46b52c2cbe78bef5628790ade1f4955d33c20 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));
+ }
+}
« no previous file with comments | « no previous file | testing/resources/parser_rebuildxref_correct.pdf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698