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
cpdf_annotlist_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2023 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_annotlist.h"
6
7
#
include
<
stdint
.
h
>
8
9
#
include
<
initializer_list
>
10
#
include
<
memory
>
11
12
#
include
"constants/annotation_common.h"
13
#
include
"core/fpdfapi/page/cpdf_page.h"
14
#
include
"core/fpdfapi/page/test_with_page_module.h"
15
#
include
"core/fpdfapi/parser/cpdf_array.h"
16
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
17
#
include
"core/fpdfapi/parser/cpdf_name.h"
18
#
include
"core/fpdfapi/parser/cpdf_string.h"
19
#
include
"core/fpdfapi/parser/cpdf_test_document.h"
20
#
include
"core/fpdfdoc/cpdf_annot.h"
21
#
include
"core/fxcrt/bytestring.h"
22
#
include
"core/fxcrt/compiler_specific.h"
23
#
include
"core/fxcrt/retain_ptr.h"
24
#
include
"core/fxcrt/widestring.h"
25
#
include
"testing/gtest/include/gtest/gtest.h"
26
27
namespace
{
28
29
class
CPDFAnnotListTest :
public
TestWithPageModule
{
30
public
:
31
void
SetUp() override {
32
TestWithPageModule
::
SetUp
();
33
34
document_ = std::make_unique<CPDF_TestDocument>();
35
document_->SetRoot(pdfium::MakeRetain<CPDF_Dictionary>());
36
page_ = pdfium::MakeRetain<CPDF_Page>(
37
document_.get(), pdfium::MakeRetain<CPDF_Dictionary>());
38
}
39
40
void
TearDown() override {
41
page_.Reset();
42
document_.reset();
43
44
TestWithPageModule
::
TearDown
();
45
}
46
47
protected
:
48
void
AddTextAnnotation(
const
ByteString
& contents) {
49
RetainPtr
<
CPDF_Dictionary
> annotation =
50
page_->GetOrCreateAnnotsArray()->AppendNew<CPDF_Dictionary>();
51
annotation->SetNewFor<CPDF_Name>(
pdfium
::
annotation
::
kSubtype
,
"Text"
);
52
annotation->SetNewFor<CPDF_String>(
pdfium
::
annotation
::
kContents
, contents);
53
}
54
55
std::unique_ptr<CPDF_TestDocument> document_;
56
RetainPtr
<CPDF_Page> page_;
57
};
58
59
ByteString
MakeByteString(
std
::initializer_list<uint8_t> bytes) {
60
// SAFETY: compiler determines size of initializer_list.
61
return
UNSAFE_BUFFERS
(
ByteString
(
std
::data(bytes),
std
::size(bytes)));
62
}
63
64
ByteString
GetRawContents(
const
CPDF_Annot
* annotation) {
65
return
annotation
->
GetAnnotDict
(
)
->
GetByteStringFor
(
66
pdfium
::
annotation
::
kContents
)
;
67
}
68
69
WideString
GetDecodedContents(
const
CPDF_Annot
* annotation) {
70
return
annotation
->
GetAnnotDict
(
)
->
GetUnicodeTextFor
(
71
pdfium
::
annotation
::
kContents
)
;
72
}
73
74
}
// namespace
75
76
TEST_F
(CPDFAnnotListTest,
CreatePopupAnnotFromPdfEncoded
) {
77
const
ByteString
kContents = MakeByteString({
'A'
,
'a'
, 0xE4, 0xA0});
78
AddTextAnnotation(kContents);
79
80
CPDF_AnnotList list(page_);
81
82
ASSERT_EQ(2u, list.Count());
83
EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
84
EXPECT_EQ(
WideString
::
FromUTF8
(
"Aaä€"
), GetDecodedContents(list.GetAt(1)));
85
}
86
87
TEST_F
(CPDFAnnotListTest,
CreatePopupAnnotFromUnicode
) {
88
const
ByteString
kContents =
89
MakeByteString({0xFE, 0xFF, 0x00,
'A'
, 0x00,
'a'
, 0x00, 0xE4, 0x20, 0xAC,
90
0xD8, 0x3C, 0xDF, 0xA8});
91
AddTextAnnotation(kContents);
92
93
CPDF_AnnotList list(page_);
94
95
ASSERT_EQ(2u, list.Count());
96
EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
97
98
EXPECT_EQ(
WideString
::
FromUTF8
(
"Aaä€🎨"
), GetDecodedContents(list.GetAt(1)));
99
}
100
101
TEST_F
(CPDFAnnotListTest,
CreatePopupAnnotFromEmptyPdfEncoded
) {
102
AddTextAnnotation(
""
);
103
104
CPDF_AnnotList list(page_);
105
106
EXPECT_EQ(1u, list.Count());
107
}
108
109
TEST_F
(CPDFAnnotListTest,
CreatePopupAnnotFromEmptyUnicode
) {
110
const
ByteString
kContents = MakeByteString({0xFE, 0xFF});
111
AddTextAnnotation(kContents);
112
113
CPDF_AnnotList list(page_);
114
115
EXPECT_EQ(1u, list.Count());
116
}
117
118
TEST_F
(CPDFAnnotListTest,
CreatePopupAnnotFromEmptyUnicodedWithEscape
) {
119
const
ByteString
kContents =
120
MakeByteString({0xFE, 0xFF, 0x00, 0x1B,
'j'
,
'a'
, 0x00, 0x1B});
121
AddTextAnnotation(kContents);
122
123
CPDF_AnnotList list(page_);
124
125
EXPECT_EQ(1u, list.Count());
126
}
ByteString
fxcrt::ByteString ByteString
Definition
bytestring.h:180
CPDF_Annot
Definition
cpdf_annot.h:32
CPDF_Annot::GetAnnotDict
const CPDF_Dictionary * GetAnnotDict() const
Definition
cpdf_annot.h:83
CPDF_Dictionary::GetUnicodeTextFor
WideString GetUnicodeTextFor(const ByteString &key) const
Definition
cpdf_dictionary.cpp:115
CPDF_Dictionary::GetByteStringFor
ByteString GetByteStringFor(const ByteString &key) const
Definition
cpdf_dictionary.cpp:104
CPDF_Dictionary::DictMap
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
Definition
cpdf_dictionary.h:31
TestWithPageModule
Definition
test_with_page_module.h:10
TestWithPageModule::TearDown
void TearDown() override
Definition
test_with_page_module.cpp:13
TestWithPageModule::SetUp
void SetUp() override
Definition
test_with_page_module.cpp:9
fxcrt::RetainPtr
Definition
retain_ptr.h:28
fxcrt::WideString::FromUTF8
static WideString FromUTF8(ByteStringView str)
Definition
widestring.cpp:738
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
UNSAFE_BUFFERS
#define UNSAFE_BUFFERS(...)
Definition
compiler_specific.h:95
TEST_F
TEST_F(CPDFAnnotListTest, CreatePopupAnnotFromPdfEncoded)
Definition
cpdf_annotlist_unittest.cpp:76
pdfium::annotation::kSubtype
const char kSubtype[]
Definition
annotation_common.cpp:12
pdfium::annotation::kContents
const char kContents[]
Definition
annotation_common.cpp:14
pdfium
Definition
annotation_common.cpp:7
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfdoc
cpdf_annotlist_unittest.cpp
Generated on
for Qt by
1.18.0