• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fpdfapi/page/cpdf_streamparser.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 
TEST(cpdf_streamparser,ReadHexString)8 TEST(cpdf_streamparser, ReadHexString) {
9   {
10     // Position out of bounds.
11     uint8_t data[] = "12ab>";
12     CPDF_StreamParser parser(data, 5);
13     parser.SetPos(6);
14     EXPECT_EQ("", parser.ReadHexString());
15   }
16 
17   {
18     // Regular conversion.
19     uint8_t data[] = "1A2b>abcd";
20     CPDF_StreamParser parser(data, 5);
21     EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
22     EXPECT_EQ(5u, parser.GetPos());
23   }
24 
25   {
26     // Missing ending >
27     uint8_t data[] = "1A2b";
28     CPDF_StreamParser parser(data, 5);
29     EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
30     EXPECT_EQ(5u, parser.GetPos());
31   }
32 
33   {
34     // Uneven number of bytes.
35     uint8_t data[] = "1A2>asdf";
36     CPDF_StreamParser parser(data, 5);
37     EXPECT_EQ("\x1a\x20", parser.ReadHexString());
38     EXPECT_EQ(4u, parser.GetPos());
39   }
40 
41   {
42     uint8_t data[] = ">";
43     CPDF_StreamParser parser(data, 5);
44     EXPECT_EQ("", parser.ReadHexString());
45     EXPECT_EQ(1u, parser.GetPos());
46   }
47 }
48