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_defaultappearance_unittest.cpp
Go to the documentation of this file.
1// Copyright 2018 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/fpdfdoc/cpdf_defaultappearance.h"
6
7#include <iterator>
8
9#include "core/fpdfapi/parser/cpdf_simple_parser.h"
10#include "testing/gtest/include/gtest/gtest.h"
11#include "testing/test_support.h"
12#include "third_party/base/containers/span.h"
13
15 static const struct FindTagTestStruct {
16 const unsigned char* input;
17 unsigned int input_size;
18 const char* token;
19 int num_params;
20 bool result;
21 unsigned int result_pos;
22 } test_data[] = {
23 // Empty strings.
24 STR_IN_TEST_CASE("", "Tj", 1, false, 0),
25 STR_IN_TEST_CASE("", "", 1, false, 0),
26 // Empty token.
27 STR_IN_TEST_CASE(" T j", "", 1, false, 5),
28 // No parameter.
29 STR_IN_TEST_CASE("Tj", "Tj", 1, false, 2),
30 STR_IN_TEST_CASE("(Tj", "Tj", 1, false, 3),
31 // Partial token match.
32 STR_IN_TEST_CASE("\r12\t34 56 78Tj", "Tj", 1, false, 15),
33 // Regular cases with various parameters.
34 STR_IN_TEST_CASE("\r\0abd Tj", "Tj", 1, true, 0),
35 STR_IN_TEST_CASE("12 4 Tj 3 46 Tj", "Tj", 1, true, 2),
36 STR_IN_TEST_CASE("er^ 2 (34) (5667) Tj", "Tj", 2, true, 5),
37 STR_IN_TEST_CASE("<344> (232)\t343.4\n12 45 Tj", "Tj", 3, true, 11),
38 STR_IN_TEST_CASE("1 2 3 4 5 6 7 8 cm", "cm", 6, true, 3),
39 };
40
41 for (size_t i = 0; i < std::size(test_data); ++i) {
42 CPDF_SimpleParser parser(
43 pdfium::make_span(test_data[i].input, test_data[i].input_size));
44 EXPECT_EQ(test_data[i].result,
46 &parser, test_data[i].token, test_data[i].num_params))
47 << " for case " << i;
48 EXPECT_EQ(test_data[i].result_pos, parser.GetCurPos()) << " for case " << i;
49 }
50}
static bool FindTagParamFromStartForTesting(CPDF_SimpleParser *parser, ByteStringView token, int nParams)
uint32_t GetCurPos() const
TEST(FXCRYPT, MD5GenerateEmtpyData)
#define STR_IN_TEST_CASE(input_literal,...)