5#include "core/fpdfdoc/cpdf_annotlist.h"
9#include <initializer_list>
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/retain_ptr.h"
23#include "core/fxcrt/widestring.h"
24#include "testing/gtest/include/gtest/gtest.h"
30 void SetUp() override {
33 document_ = std::make_unique<CPDF_TestDocument>();
34 document_->SetRoot(pdfium::MakeRetain<CPDF_Dictionary>());
35 page_ = pdfium::MakeRetain<CPDF_Page>(
36 document_.get(), pdfium::MakeRetain<CPDF_Dictionary>());
39 void TearDown() override {
47 void AddTextAnnotation(
const ByteString& contents) {
49 page_->GetOrCreateAnnotsArray()->AppendNew<CPDF_Dictionary>();
55 std::unique_ptr<CPDF_TestDocument> document_;
59ByteString MakeByteString(
std::initializer_list<uint8_t> bytes) {
60 return ByteString(
std::data(bytes),
std::size(bytes));
63ByteString GetRawContents(
const CPDF_Annot* annotation) {
68WideString GetDecodedContents(
const CPDF_Annot* annotation) {
76 const ByteString kContents = MakeByteString({
'A',
'a', 0xE4, 0xA0});
77 AddTextAnnotation(kContents);
79 CPDF_AnnotList list(page_);
81 ASSERT_EQ(2u, list.Count());
82 EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
83 EXPECT_EQ(WideString
::FromUTF8(
"Aaä€"), GetDecodedContents(list.GetAt(1)));
87 const ByteString kContents =
88 MakeByteString({0xFE, 0xFF, 0x00,
'A', 0x00,
'a', 0x00, 0xE4, 0x20, 0xAC,
89 0xD8, 0x3C, 0xDF, 0xA8});
90 AddTextAnnotation(kContents);
92 CPDF_AnnotList list(page_);
94 ASSERT_EQ(2u, list.Count());
95 EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
97 EXPECT_EQ(WideString
::FromUTF8(
"Aaä€🎨"), GetDecodedContents(list.GetAt(1)));
101 AddTextAnnotation(
"");
103 CPDF_AnnotList list(page_);
105 EXPECT_EQ(1u, list.Count());
109 const ByteString kContents = MakeByteString({0xFE, 0xFF});
110 AddTextAnnotation(kContents);
112 CPDF_AnnotList list(page_);
114 EXPECT_EQ(1u, list.Count());
118 const ByteString kContents =
119 MakeByteString({0xFE, 0xFF, 0x00, 0x1B,
'j',
'a', 0x00, 0x1B});
120 AddTextAnnotation(kContents);
122 CPDF_AnnotList list(page_);
124 EXPECT_EQ(1u, list.Count());
const CPDF_Dictionary * GetAnnotDict() const
WideString GetUnicodeTextFor(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
static WideString FromUTF8(ByteStringView str)
TEST_F(CPDFAnnotListTest, CreatePopupAnnotFromPdfEncoded)