Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfgas_rtfbreak_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2017 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
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"xfa/fgas/layout/cfgas_rtfbreak.h"
8
9
#
include
<
memory
>
10
#
include
<
utility
>
11
12
#
include
"core/fxcrt/fx_codepage.h"
13
#
include
"core/fxge/cfx_font.h"
14
#
include
"core/fxge/cfx_gemodule.h"
15
#
include
"testing/gtest/include/gtest/gtest.h"
16
#
include
"xfa/fgas/font/cfgas_fontmgr.h"
17
#
include
"xfa/fgas/font/cfgas_gefont.h"
18
#
include
"xfa/fgas/layout/cfgas_char.h"
19
20
class
CFGAS_RTFBreakTest
:
public
testing
::
Test
{
21
public
:
22
void
SetUp
()
override
{
23
const
wchar_t
kFontFamily[] = L"Arimo Bold";
24
font_ = CFGAS_GEFont::LoadFont(kFontFamily, 0, FX_CodePage::kDefANSI);
25
ASSERT_TRUE(font_);
26
}
27
28
std
::
unique_ptr
<
CFGAS_RTFBreak
>
CreateBreak
(
29
Mask
<
CFGAS_Break
::
LayoutStyle
> layout_styles) {
30
auto
rtf_break =
std
::make_unique<CFGAS_RTFBreak>(layout_styles);
31
rtf_break->SetFont(font_);
32
return
rtf_break;
33
}
34
35
private
:
36
RetainPtr
<CFGAS_GEFont> font_;
37
};
38
39
// As soon as you get one of the control characters the break is complete
40
// and must be consumed before you get any more characters ....
41
42
TEST_F
(
CFGAS_RTFBreakTest
,
AddChars
) {
43
auto
rtf_break = CreateBreak(
CFGAS_Break
::
LayoutStyle
::
kExpandTab
);
44
WideString
str
(
L"Input String."
)
;
45
for
(
wchar_t
ch : str)
46
EXPECT_EQ(CFGAS_Char::BreakType::kNone, rtf_break->AppendChar(ch));
47
48
EXPECT_EQ(
CFGAS_Char
::
BreakType
::
kParagraph
, rtf_break->AppendChar(L'\n'));
49
ASSERT_EQ(1, rtf_break->CountBreakPieces());
50
EXPECT_EQ(str
+
L"\n", rtf_break->GetBreakPieceUnstable(0)->GetString());
51
52
rtf_break->ClearBreakPieces();
53
rtf_break->Reset();
54
EXPECT_EQ(0, rtf_break->GetCurrentLineForTesting()->GetLineEnd());
55
56
str
=
L"Second str.";
57
for
(
wchar_t
ch : str)
58
EXPECT_EQ(CFGAS_Char::BreakType::kNone, rtf_break->AppendChar(ch));
59
60
// Force the end of the break at the end of the string.
61
rtf_break->EndBreak(
CFGAS_Char
::
BreakType
::
kParagraph
);
62
ASSERT_EQ(1, rtf_break->CountBreakPieces());
63
EXPECT_EQ(str, rtf_break->GetBreakPieceUnstable(0)->GetString());
64
}
65
66
TEST_F
(
CFGAS_RTFBreakTest
,
ControlCharacters
) {
67
auto
rtf_break = CreateBreak(
CFGAS_Break
::
LayoutStyle
::
kExpandTab
);
68
EXPECT_EQ(
CFGAS_Char
::
BreakType
::
kLine
, rtf_break->AppendChar(L'\v'));
69
EXPECT_EQ(
CFGAS_Char
::
BreakType
::
kPage
, rtf_break->AppendChar(L'\f'));
70
EXPECT_EQ(
CFGAS_Char
::
BreakType
::
kParagraph
,
71
rtf_break->AppendChar(
pdfium
::
unicode
::
kParagraphSeparator
));
72
EXPECT_EQ(
CFGAS_Char
::
BreakType
::
kParagraph
, rtf_break->AppendChar(L'\n'));
73
74
ASSERT_EQ(1, rtf_break->CountBreakPieces());
75
EXPECT_EQ(L"\v", rtf_break->GetBreakPieceUnstable(0)->GetString());
76
}
77
78
TEST_F
(
CFGAS_RTFBreakTest
,
BidiLine
) {
79
auto
rtf_break = CreateBreak(
CFGAS_Break
::
LayoutStyle
::
kExpandTab
);
80
rtf_break->SetLineBreakTolerance(1);
81
rtf_break->SetFontSize(12);
82
83
// SAFETY: known fixed-length string.
84
WideString
input =
85
WideString
::
FromUTF8
(
UNSAFE_BUFFERS
(ByteStringView(
"\xa\x0\xa\xa"
, 4)));
86
for
(
wchar_t
ch : input)
87
rtf_break->AppendChar(ch);
88
89
std::vector<CFGAS_Char> chars =
90
rtf_break->GetCurrentLineForTesting()->m_LineChars;
91
CFGAS_Char::BidiLine(&chars, chars.size());
92
EXPECT_EQ(3u, chars.size());
93
}
TEST_F
TEST_F(CFGAS_RTFBreakTest, AddChars)
Definition
cfgas_rtfbreak_unittest.cpp:42
CFGAS_Break
Definition
cfgas_break.h:21
CFGAS_Break::LayoutStyle
LayoutStyle
Definition
cfgas_break.h:23
CFGAS_Break::LayoutStyle::kExpandTab
@ kExpandTab
Definition
cfgas_break.h:26
CFGAS_Char
Definition
cfgas_char.h:19
CFGAS_Char::BreakType
BreakType
Definition
cfgas_char.h:21
CFGAS_Char::BreakType::kPage
@ kPage
Definition
cfgas_char.h:26
CFGAS_Char::BreakType::kParagraph
@ kParagraph
Definition
cfgas_char.h:25
CFGAS_Char::BreakType::kLine
@ kLine
Definition
cfgas_char.h:24
CFGAS_RTFBreakTest
Definition
cfgas_rtfbreak_unittest.cpp:20
CFGAS_RTFBreakTest::CreateBreak
std::unique_ptr< CFGAS_RTFBreak > CreateBreak(Mask< CFGAS_Break::LayoutStyle > layout_styles)
Definition
cfgas_rtfbreak_unittest.cpp:28
CFGAS_RTFBreakTest::SetUp
void SetUp() override
Definition
cfgas_rtfbreak_unittest.cpp:22
fxcrt::Mask
Definition
mask.h:15
fxcrt::RetainPtr
Definition
retain_ptr.h:28
fxcrt::WideString::FromUTF8
static WideString FromUTF8(ByteStringView str)
Definition
widestring.cpp:738
fxcrt::WideString::WideString
WideString(const wchar_t *ptr)
Definition
widestring.cpp:407
fxcrt::WideString::operator=
WideString & operator=(const wchar_t *str)
Definition
widestring.cpp:447
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
UNSAFE_BUFFERS
#define UNSAFE_BUFFERS(...)
Definition
compiler_specific.h:95
fxcrt::operator+
WideString operator+(const WideString &str1, const wchar_t *str2)
Definition
widestring.h:165
pdfium::unicode
Definition
fx_unicode.h:97
pdfium::unicode::kParagraphSeparator
constexpr wchar_t kParagraphSeparator
Definition
fx_unicode.h:101
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fgas
layout
cfgas_rtfbreak_unittest.cpp
Generated on
for Qt by
1.18.0