Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
15
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
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
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}
RetainPtr< const CPDF_String > GetStringFor(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
void SetRootForTesting(RetainPtr< CPDF_Dictionary > root)
const CPDF_Dictionary * GetRoot() const
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFCatalog_SetLanguage(FPDF_DOCUMENT document, FPDF_BYTESTRING language)
EmbedderTest FPDFCatalogTest
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument()
TEST_F(FPDFParserDecodeEmbedderTest, Bug552046)