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
fpdf_searchex_embeddertest.cpp
Go to the documentation of this file.
1// Copyright 2019 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 "public/cpp/fpdf_scopers.h"
6#include "public/fpdf_searchex.h"
7#include "testing/embedder_test.h"
8
10
12 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
13 FPDF_PAGE page = LoadPage(0);
14 ASSERT_TRUE(page);
15
16 {
17 ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
18 ASSERT_TRUE(textpage);
19
20 EXPECT_EQ(-2, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -2));
21 EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -1));
22 EXPECT_EQ(0, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 0));
23 EXPECT_EQ(1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 1));
24 EXPECT_EQ(2, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 2));
25 EXPECT_EQ(5, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 5));
26 EXPECT_EQ(10, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 10));
27 EXPECT_EQ(29, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 29));
28 EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 30));
29 }
30
31 UnloadPage(page);
32}
33
36 ASSERT_TRUE(OpenDocument("bug_1139.pdf"));
37 FPDF_PAGE page = LoadPage(0);
38 ASSERT_TRUE(page);
39
40 {
41 ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
42 ASSERT_TRUE(textpage);
43
44 EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -2));
45 EXPECT_EQ(0, FPDFText_GetCharIndexFromTextIndex(textpage.get(), -1));
46 EXPECT_EQ(1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 0));
47 EXPECT_EQ(2, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 1));
48 EXPECT_EQ(3, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 2));
49 EXPECT_EQ(6, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 5));
50 EXPECT_EQ(11, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 10));
51 EXPECT_EQ(30, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 29));
52 EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 30));
53 EXPECT_EQ(-1, FPDFText_GetCharIndexFromTextIndex(textpage.get(), 31));
54 }
55
56 UnloadPage(page);
57}
58
66
68 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
69 FPDF_PAGE page = LoadPage(0);
70 ASSERT_TRUE(page);
71
72 {
73 ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
74 ASSERT_TRUE(textpage);
75
76 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -2));
77 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -1));
78 EXPECT_EQ(0, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 0));
79 EXPECT_EQ(1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 1));
80 EXPECT_EQ(2, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 2));
81 EXPECT_EQ(5, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 5));
82 EXPECT_EQ(10, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 10));
83 EXPECT_EQ(29, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 29));
84 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 30));
85 }
86
87 UnloadPage(page);
88}
89
92 ASSERT_TRUE(OpenDocument("bug_1139.pdf"));
93 FPDF_PAGE page = LoadPage(0);
94 ASSERT_TRUE(page);
95
96 {
97 ScopedFPDFTextPage textpage(FPDFText_LoadPage(page));
98 ASSERT_TRUE(textpage);
99
100 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -2));
101 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), -1));
102 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 0));
103 EXPECT_EQ(0, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 1));
104 EXPECT_EQ(1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 2));
105 EXPECT_EQ(4, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 5));
106 EXPECT_EQ(9, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 10));
107 EXPECT_EQ(28, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 29));
108 EXPECT_EQ(29, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 30));
109 EXPECT_EQ(-1, FPDFText_GetTextIndexFromCharIndex(textpage.get(), 31));
110 }
111
112 UnloadPage(page);
113}
114
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextIndexFromCharIndex(FPDF_TEXTPAGE text_page, int nCharIndex)
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex)
TEST_F(FPDFSearchExEmbedderTest, GetCharIndexFromTextIndex)