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/compiler_specific.h"
23#include "core/fxcrt/retain_ptr.h"
24#include "core/fxcrt/widestring.h"
25#include "testing/gtest/include/gtest/gtest.h"
31 void SetUp() override {
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>());
40 void TearDown() override {
48 void AddTextAnnotation(
const ByteString& contents) {
50 page_->GetOrCreateAnnotsArray()->AppendNew<CPDF_Dictionary>();
55 std::unique_ptr<CPDF_TestDocument> document_;
59ByteString MakeByteString(
std::initializer_list<uint8_t> bytes) {
77 const ByteString kContents = MakeByteString({
'A',
'a', 0xE4, 0xA0});
78 AddTextAnnotation(kContents);
80 CPDF_AnnotList list(page_);
82 ASSERT_EQ(2u, list.Count());
83 EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
89 MakeByteString({0xFE, 0xFF, 0x00,
'A', 0x00,
'a', 0x00, 0xE4, 0x20, 0xAC,
90 0xD8, 0x3C, 0xDF, 0xA8});
91 AddTextAnnotation(kContents);
93 CPDF_AnnotList list(page_);
95 ASSERT_EQ(2u, list.Count());
96 EXPECT_EQ(kContents, GetRawContents(list.GetAt(1)));
102 AddTextAnnotation(
"");
104 CPDF_AnnotList list(page_);
106 EXPECT_EQ(1u, list.Count());
110 const ByteString kContents = MakeByteString({0xFE, 0xFF});
111 AddTextAnnotation(kContents);
113 CPDF_AnnotList list(page_);
115 EXPECT_EQ(1u, list.Count());
120 MakeByteString({0xFE, 0xFF, 0x00, 0x1B,
'j',
'a', 0x00, 0x1B});
121 AddTextAnnotation(kContents);
123 CPDF_AnnotList list(page_);
125 EXPECT_EQ(1u, list.Count());
fxcrt::ByteString ByteString
const CPDF_Dictionary * GetAnnotDict() const
WideString GetUnicodeTextFor(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
static WideString FromUTF8(ByteStringView str)
#define UNSAFE_BUFFERS(...)
TEST_F(CPDFAnnotListTest, CreatePopupAnnotFromPdfEncoded)
fxcrt::WideString WideString