Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_simple_parser_unittest.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
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/parser/cpdf_simple_parser.h"
6
7#include <iterator>
8
9#include "core/fpdfapi/parser/fpdf_parser_utility.h"
10#include "core/fxcrt/fx_memcpy_wrappers.h"
11#include "core/fxcrt/span.h"
12#include "testing/gtest/include/gtest/gtest.h"
13#include "testing/test_support.h"
14
16 static const pdfium::StrFuncTestData test_data[] = {
17 // Empty src string.
18 STR_IN_OUT_CASE("", ""),
19 // Content with whitespaces only.
20 STR_IN_OUT_CASE(" \t \0 \n", ""),
21 // Content with comments only.
22 STR_IN_OUT_CASE("%this is a test case\r\n%2nd line", ""),
23 // Mixed whitespaces and comments.
24 STR_IN_OUT_CASE(" \t \0%try()%haha\n %another line \aa", ""),
25 // Name.
26 STR_IN_OUT_CASE("/", ""),
27 STR_IN_OUT_CASE("/99", ""),
28 STR_IN_OUT_CASE("/99}", "/99"),
29 STR_IN_OUT_CASE(" /Tester ", "/Tester"),
30 // String.
31 STR_IN_OUT_CASE("\t(nice day)!\n ", "(nice day)"),
32 // String with nested braces.
33 STR_IN_OUT_CASE("\t(It is a (long) day)!\n ", "(It is a (long) day)"),
34 // String with escaped chars.
35 STR_IN_OUT_CASE("\t(It is a \\‍(long\\‍) day!)hi\n ",
36 "(It is a \\‍(long\\‍) day!)"),
37 // Angle brackets.
38 STR_IN_OUT_CASE("<", "<"),
39 STR_IN_OUT_CASE(">", ">"),
40 // Hex string.
41 STR_IN_OUT_CASE(" \n<4545acdfedertt>abc ", "<4545acdfedertt>"),
42 STR_IN_OUT_CASE(" \n<4545a<ed>ertt>abc ", "<4545a<ed>"),
43 // Dictionary.
44 STR_IN_OUT_CASE("<</oc 234 /color 2 3 R>>", "<<"),
45 STR_IN_OUT_CASE("\t\t<< /abc>>", "<<"),
46 // Parentheses.
47 STR_IN_OUT_CASE("(\\", "(\\"),
48 // Handling ending delimiters.
49 STR_IN_OUT_CASE("> little bear", ">"),
50 STR_IN_OUT_CASE(") another bear", ")"),
51 STR_IN_OUT_CASE(">> end ", ">>"),
52 // No ending delimiters.
53 STR_IN_OUT_CASE("(sdfgfgbcv", "(sdfgfgbcv"),
54 // Other delimiters.
55 STR_IN_OUT_CASE("}", "}"),
56 // Regular cases.
57 STR_IN_OUT_CASE("apple pear", "apple"),
58 STR_IN_OUT_CASE(" pi=3.1415 ", "pi=3.1415"),
59 STR_IN_OUT_CASE(" p t x c ", "p"),
60 STR_IN_OUT_CASE(" pt\0xc ", "pt"),
61 STR_IN_OUT_CASE(" $^&&*\t\0sdff ", "$^&&*"),
62 STR_IN_OUT_CASE("\n\r+3.5656 -11.0", "+3.5656"),
63 };
64 size_t i = 0;
65 for (const pdfium::StrFuncTestData& data : test_data) {
66 CPDF_SimpleParser parser(data.input_span());
67 EXPECT_EQ(parser.GetWord(), ByteStringView(data.expected_span()))
68 << " for case " << i;
69 ++i;
70 }
71}
72
74 const char kInput[] = "1 beginbfchar\n<01> <>\nendbfchar\n1 beginbfchar";
75
76 CPDF_SimpleParser parser(pdfium::as_byte_span(kInput));
77 EXPECT_EQ(parser.GetWord(), "1");
78 EXPECT_EQ(parser.GetWord(), "beginbfchar");
79 EXPECT_EQ(parser.GetWord(), "<01>");
80 EXPECT_EQ(parser.GetWord(), "<>");
81 EXPECT_EQ(parser.GetWord(), "endbfchar");
82 EXPECT_EQ(parser.GetWord(), "1");
83 EXPECT_EQ(parser.GetWord(), "beginbfchar");
84 EXPECT_EQ(parser.GetWord(), "");
85}
ByteStringView GetWord()
TEST(FXCRYPT, MD5GenerateEmtpyData)
fxcrt::ByteStringView ByteStringView
#define STR_IN_OUT_CASE(input_literal, expected_literal,...)