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
fpdf_catalog_embeddertest.cpp
Go to the documentation of this file.
1
// Copyright 2024 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/fpdf_catalog.h"
6
7
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
8
#
include
"core/fpdfapi/parser/cpdf_document.h"
9
#
include
"core/fpdfapi/parser/cpdf_string.h"
10
#
include
"fpdfsdk/cpdfsdk_helpers.h"
11
#
include
"public/fpdf_edit.h"
12
#
include
"testing/embedder_test.h"
13
14
using
FPDFCatalogTest
=
EmbedderTest
;
15
16
TEST_F
(
FPDFCatalogTest
,
SetLanguageInvalidDocument
) {
17
// Document cannot be nullptr.
18
EXPECT_FALSE(
FPDFCatalog_SetLanguage
(
nullptr
,
"en-US"
)
);
19
20
ScopedFPDFDocument doc(
FPDF_CreateNewDocument
(
)
);
21
CPDF_Document
* cpdf_doc = CPDFDocumentFromFPDFDocument(doc.get());
22
23
// Language cannot be null.
24
ASSERT_TRUE(cpdf_doc
->
GetRoot
(
)
);
25
EXPECT_FALSE(FPDFCatalog_SetLanguage(doc.get(),
nullptr
));
26
27
// Catalog cannot be nullptr.
28
cpdf_doc
->
SetRootForTesting
(
nullptr
);
29
EXPECT_FALSE(FPDFCatalog_SetLanguage(doc.get(),
"en-US"
));
30
}
31
32
TEST_F
(
FPDFCatalogTest
,
SetLanguageNewDocument
) {
33
ScopedFPDFDocument doc(
FPDF_CreateNewDocument
(
)
);
34
35
const
CPDF_Dictionary
* catalog =
36
CPDFDocumentFromFPDFDocument(doc.get())->GetRoot();
37
ASSERT_TRUE(catalog);
38
39
// The new document shouldn't have any entry for /Lang.
40
EXPECT_FALSE(catalog
->
GetStringFor
(
"Lang"
));
41
42
// Add a new entry.
43
EXPECT_TRUE(FPDFCatalog_SetLanguage(doc.get(),
"en-US"
));
44
45
RetainPtr
<
const
CPDF_String> result_language = catalog->GetStringFor(
"Lang"
);
46
ASSERT_TRUE(result_language);
47
EXPECT_EQ(
"en-US"
, result_language->GetString());
48
}
49
50
TEST_F
(
FPDFCatalogTest
,
SetLanguageExistingDocument
) {
51
ASSERT_TRUE(OpenDocument(
"tagged_table.pdf"
));
52
53
const
CPDF_Dictionary
* catalog =
54
CPDFDocumentFromFPDFDocument(document())->GetRoot();
55
ASSERT_TRUE(catalog);
56
57
// The PDF already has an existing entry for /Lang.
58
RetainPtr
<
const
CPDF_String> result_language = catalog->GetStringFor(
"Lang"
);
59
ASSERT_TRUE(result_language);
60
EXPECT_EQ(
"en-US"
, result_language->GetString());
61
62
// Replace the existing entry.
63
EXPECT_TRUE(FPDFCatalog_SetLanguage(document(),
"hu"
));
64
65
result_language = catalog
->
GetStringFor
(
"Lang"
);
66
ASSERT_TRUE(result_language);
67
EXPECT_EQ(
"hu"
, result_language->GetString());
68
}
CPDF_Dictionary::GetStringFor
RetainPtr< const CPDF_String > GetStringFor(const ByteString &key) const
Definition
cpdf_dictionary.cpp:236
CPDF_Dictionary::DictMap
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
Definition
cpdf_dictionary.h:31
CPDF_Document
Definition
cpdf_document.h:29
CPDF_Document::SetRootForTesting
void SetRootForTesting(RetainPtr< CPDF_Dictionary > root)
Definition
cpdf_document.cpp:639
CPDF_Document::GetRoot
const CPDF_Dictionary * GetRoot() const
Definition
cpdf_document.h:97
EmbedderTest
Definition
embedder_test.h:40
fxcrt::RetainPtr
Definition
retain_ptr.h:28
FPDFCatalog_SetLanguage
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFCatalog_SetLanguage(FPDF_DOCUMENT document, FPDF_BYTESTRING language)
Definition
fpdf_catalog.cpp:28
FPDFCatalogTest
EmbedderTest FPDFCatalogTest
Definition
fpdf_catalog_embeddertest.cpp:14
FPDF_CreateNewDocument
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument()
Definition
fpdf_editpage.cpp:155
TEST_F
TEST_F(FPDFParserDecodeEmbedderTest, Bug552046)
Definition
fpdf_parser_decode_embeddertest.cpp:16
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fpdfsdk
fpdf_catalog_embeddertest.cpp
Generated on
for Qt by
1.18.0