summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-02 16:12:41 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-02 16:12:41 -0500
commit4d6f03a5aa4053640066e829a7450c3177cb2770 (patch)
treed281161eb7198c15e25adc67b58814307fea9aa2 /core/src/fpdfapi/fpdf_parser
parentdebf3ad2dbe4aa6448cd2c3049e668ba32ceeb00 (diff)
downloadpdfium-4d6f03a5aa4053640066e829a7450c3177cb2770.tar.xz
Merge to XFA: 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. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1410873009 . (cherry picked from commit e948a4ee08b78e27da37bc12244fa1b66d927dc7) Review URL: https://codereview.chromium.org/1432513002 .
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]);
+ }
+}