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