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 "testing/gtest/include/gtest/gtest.h"
12#include "testing/test_support.h"
13#include "third_party/base/containers/span.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(" /Tester ", "/Tester"),
27 // String.
28 STR_IN_OUT_CASE("\t(nice day)!\n ", "(nice day)"),
29 // String with nested braces.
30 STR_IN_OUT_CASE("\t(It is a (long) day)!\n ", "(It is a (long) day)"),
31 // String with escaped chars.
32 STR_IN_OUT_CASE("\t(It is a \\‍(long\\‍) day!)hi\n ",
33 "(It is a \\‍(long\\‍) day!)"),
34 // Hex string.
35 STR_IN_OUT_CASE(" \n<4545acdfedertt>abc ", "<4545acdfedertt>"),
36 STR_IN_OUT_CASE(" \n<4545a<ed>ertt>abc ", "<4545a<ed>"),
37 // Dictionary.
38 STR_IN_OUT_CASE("<</oc 234 /color 2 3 R>>", "<<"),
39 STR_IN_OUT_CASE("\t\t<< /abc>>", "<<"),
40 // Handling ending delimiters.
41 STR_IN_OUT_CASE("> little bear", ">"),
42 STR_IN_OUT_CASE(") another bear", ")"),
43 STR_IN_OUT_CASE(">> end ", ">>"),
44 // No ending delimiters.
45 STR_IN_OUT_CASE("(sdfgfgbcv", "(sdfgfgbcv"),
46 // Regular cases.
47 STR_IN_OUT_CASE("apple pear", "apple"),
48 STR_IN_OUT_CASE(" pi=3.1415 ", "pi=3.1415"),
49 STR_IN_OUT_CASE(" p t x c ", "p"),
50 STR_IN_OUT_CASE(" pt\0xc ", "pt"),
51 STR_IN_OUT_CASE(" $^&&*\t\0sdff ", "$^&&*"),
52 STR_IN_OUT_CASE("\n\r+3.5656 -11.0", "+3.5656"),
53 };
54 for (size_t i = 0; i < std::size(test_data); ++i) {
55 const pdfium::StrFuncTestData& data = test_data[i];
56 CPDF_SimpleParser parser(pdfium::make_span(data.input, data.input_size));
57 ByteStringView word = parser.GetWord();
58 EXPECT_EQ(data.expected_size, word.GetLength()) << " for case " << i;
59 if (data.expected_size != word.GetLength())
60 continue;
61 EXPECT_EQ(0, FXSYS_memcmp(data.expected, word.unterminated_c_str(),
62 data.expected_size))
63 << " for case " << i;
64 }
65}
TEST(FXCRYPT, MD5GenerateEmtpyData)
const unsigned char * input
#define STR_IN_OUT_CASE(input_literal, expected_literal,...)