summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-02 16:35:28 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-02 16:35:28 -0500
commitc89c6195373b63e99b9cd432c5a181bfb3ad8dbe (patch)
treef103208a02061659416f4e905fb5ead96b3a84a9
parent99818557c8ed64d00fcc23a1e87e1ebf41ed5e85 (diff)
downloadpdfium-chromium/2553.tar.xz
Add test for CPDF_StreamParser::ReadHexString.chromium/2555chromium/2554chromium/2553
This CL adds a unit test for the ReadHexString method. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1408213008 .
-rw-r--r--BUILD.gn1
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp48
-rw-r--r--core/src/fpdfapi/fpdf_page/pageint.h6
-rw-r--r--pdfium.gyp1
4 files changed, 56 insertions, 0 deletions
diff --git a/BUILD.gn b/BUILD.gn
index cdf6d6dc8a..511065d3cd 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -716,6 +716,7 @@ test("pdfium_unittests") {
sources = [
"core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp",
"core/src/fpdfapi/fpdf_font/fpdf_font_unittest.cpp",
+ "core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp",
"core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp",
"core/src/fxcodec/codec/fx_codec_jpx_unittest.cpp",
"core/src/fxcrt/fx_basic_bstring_unittest.cpp",
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp
new file mode 100644
index 0000000000..3fc012f29c
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp
@@ -0,0 +1,48 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "pageint.h"
+
+TEST(fpdf_page_parser_old, ReadHexString) {
+ {
+ // Position out of bounds.
+ uint8_t data[] = "12ab>";
+ CPDF_StreamParser parser(data, 5);
+ parser.SetPos(6);
+ EXPECT_EQ("", parser.ReadHexString());
+ }
+
+ {
+ // Regular conversion.
+ uint8_t data[] = "1A2b>abcd";
+ CPDF_StreamParser parser(data, 5);
+ EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
+ EXPECT_EQ(5, parser.GetPos());
+ }
+
+ {
+ // Missing ending >
+ uint8_t data[] = "1A2b";
+ CPDF_StreamParser parser(data, 5);
+ EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
+ EXPECT_EQ(5, parser.GetPos());
+ }
+
+ {
+ // Uneven number of bytes.
+ uint8_t data[] = "1A2>asdf";
+ CPDF_StreamParser parser(data, 5);
+ EXPECT_EQ("\x1a\x20", parser.ReadHexString());
+ EXPECT_EQ(4, parser.GetPos());
+ }
+
+ {
+ uint8_t data[] = ">";
+ CPDF_StreamParser parser(data, 5);
+ EXPECT_EQ("", parser.ReadHexString());
+ EXPECT_EQ(1, parser.GetPos());
+ }
+}
diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h
index 1b41633346..e787d6973a 100644
--- a/core/src/fpdfapi/fpdf_page/pageint.h
+++ b/core/src/fpdfapi/fpdf_page/pageint.h
@@ -10,8 +10,12 @@
#include <map>
#include "../../../../third_party/base/nonstd_unique_ptr.h"
+#include "../../../include/fpdfapi/fpdf_page.h"
#include "../../../include/fpdfapi/fpdf_pageobj.h"
+class CPDF_AllStates;
+class CPDF_ParseOptions;
+
#define PARSE_STEP_LIMIT 100
class CPDF_StreamParser {
@@ -41,6 +45,8 @@ class CPDF_StreamParser {
void SkipPathObject();
protected:
+ friend class fpdf_page_parser_old_ReadHexString_Test;
+
void GetNextWord(FX_BOOL& bIsNumber);
CFX_ByteString ReadString();
CFX_ByteString ReadHexString();
diff --git a/pdfium.gyp b/pdfium.gyp
index 7c8c02e4da..8687e76cac 100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -716,6 +716,7 @@
'sources': [
'core/src/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp',
'core/src/fpdfapi/fpdf_font/fpdf_font_unittest.cpp',
+ 'core/src/fpdfapi/fpdf_page/fpdf_page_parser_old_unittest.cpp',
'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp',
'core/src/fxcodec/codec/fx_codec_jpx_unittest.cpp',
'core/src/fxcrt/fx_basic_bstring_unittest.cpp',