summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-02 15:58:55 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-02 15:58:55 -0500
commite948a4ee08b78e27da37bc12244fa1b66d927dc7 (patch)
tree9d66e81e97358328bb16effbec800eca04027af7 /core/src/fpdfapi/fpdf_parser
parente65be3a55628294d0f45da456d856b4539f0cb15 (diff)
downloadpdfium-e948a4ee08b78e27da37bc12244fa1b66d927dc7.tar.xz
Add a test for the HexDecode method.
I moved the declaration to be public, instead of having it implicit in one file and defined in a seperate cpp file. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1410873009 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp20
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp52
2 files changed, 62 insertions, 10 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 255d0ce29c..e68fcb6800 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -42,10 +42,10 @@ const FX_WORD PDFDocEncoding[256] = {
0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb,
0x00fc, 0x00fd, 0x00fe, 0x00ff};
-FX_DWORD _A85Decode(const uint8_t* src_buf,
- FX_DWORD src_size,
- uint8_t*& dest_buf,
- FX_DWORD& dest_size) {
+FX_DWORD A85Decode(const uint8_t* src_buf,
+ FX_DWORD src_size,
+ uint8_t*& dest_buf,
+ FX_DWORD& dest_size) {
dest_size = 0;
dest_buf = NULL;
if (src_size == 0) {
@@ -117,10 +117,10 @@ FX_DWORD _A85Decode(const uint8_t* src_buf,
}
return pos;
}
-FX_DWORD _HexDecode(const uint8_t* src_buf,
- FX_DWORD src_size,
- uint8_t*& dest_buf,
- FX_DWORD& dest_size) {
+FX_DWORD HexDecode(const uint8_t* src_buf,
+ FX_DWORD src_size,
+ uint8_t*& dest_buf,
+ FX_DWORD& dest_size) {
FX_DWORD i;
for (i = 0; i < src_size; i++)
if (src_buf[i] == '>') {
@@ -380,10 +380,10 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
estimated_size, new_buf, new_size);
} else if (decoder == FX_BSTRC("ASCII85Decode") ||
decoder == FX_BSTRC("A85")) {
- offset = _A85Decode(last_buf, last_size, new_buf, new_size);
+ offset = A85Decode(last_buf, last_size, new_buf, new_size);
} else if (decoder == FX_BSTRC("ASCIIHexDecode") ||
decoder == FX_BSTRC("AHx")) {
- offset = _HexDecode(last_buf, last_size, new_buf, new_size);
+ offset = HexDecode(last_buf, last_size, new_buf, new_size);
} else if (decoder == FX_BSTRC("RunLengthDecode") ||
decoder == FX_BSTRC("RL")) {
if (bImageAcc && i == DecoderList.GetSize() - 1) {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
new file mode 100644
index 0000000000..f01e21293c
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp
@@ -0,0 +1,52 @@
+// 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 "../../../include/fpdfapi/fpdf_parser.h"
+
+TEST(fpdf_parser_decode, HexDecode) {
+ {
+ // Empty src string.
+ uint8_t* dest = nullptr;
+ FX_DWORD dest_size;
+ uint8_t src[] = "";
+ EXPECT_EQ(0, HexDecode(src, 0, dest, dest_size));
+ EXPECT_EQ(0, dest_size);
+ EXPECT_EQ('\0', dest[0]);
+ }
+
+ {
+ // Regular conversion.
+ uint8_t* dest = nullptr;
+ FX_DWORD dest_size;
+ uint8_t src[] = "12Ac>zzz";
+ EXPECT_EQ(5, HexDecode(src, 8, dest, dest_size));
+ EXPECT_EQ(2, dest_size);
+ EXPECT_EQ(18, dest[0]);
+ EXPECT_EQ(172, dest[1]);
+ }
+
+ {
+ // Non-multiple length.
+ uint8_t* dest = nullptr;
+ FX_DWORD dest_size;
+ uint8_t src[] = "12A>zzz";
+ EXPECT_EQ(4, HexDecode(src, 8, dest, dest_size));
+ EXPECT_EQ(2, dest_size);
+ EXPECT_EQ(18, dest[0]);
+ EXPECT_EQ(160, dest[1]);
+ }
+
+ {
+ // Skips unknown characters.
+ uint8_t* dest = nullptr;
+ FX_DWORD dest_size;
+ uint8_t src[] = "12tk \tAc>zzz";
+ EXPECT_EQ(10, HexDecode(src, 13, dest, dest_size));
+ EXPECT_EQ(2, dest_size);
+ EXPECT_EQ(18, dest[0]);
+ EXPECT_EQ(172, dest[1]);
+ }
+}