summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_catalog_unittest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-28 19:23:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-28 19:23:25 +0000
commit971a674ef17526ad37ce55ba90110830b94889d0 (patch)
treed99fabf665cc63825b48dd087daadf664bb80ee8 /fpdfsdk/fpdf_catalog_unittest.cpp
parent7d12532362545273e0ceac93fae2154661323fd1 (diff)
downloadpdfium-971a674ef17526ad37ce55ba90110830b94889d0.tar.xz
Rename fpdfsdk/fpdf* files to be consistent
This CL makes the fpdfsdk/fpdf* files to be consistently prefixed with fpdf_ instead of randomly dropping the _. Change-Id: I23e3c8a0831b56bcd17c788d9fe874b2ab8b24fc Reviewed-on: https://pdfium-review.googlesource.com/29390 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_catalog_unittest.cpp')
-rw-r--r--fpdfsdk/fpdf_catalog_unittest.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_catalog_unittest.cpp b/fpdfsdk/fpdf_catalog_unittest.cpp
new file mode 100644
index 0000000000..b00748b49d
--- /dev/null
+++ b/fpdfsdk/fpdf_catalog_unittest.cpp
@@ -0,0 +1,97 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "public/fpdf_catalog.h"
+
+#include <memory>
+
+#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_number.h"
+#include "core/fpdfapi/parser/cpdf_parser.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+
+#ifdef PDF_ENABLE_XFA
+#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
+#endif // PDF_ENABLE_XFA
+
+class CPDF_TestDocument : public CPDF_Document {
+ public:
+ CPDF_TestDocument() : CPDF_Document(nullptr) {}
+
+ void SetRoot(CPDF_Dictionary* root) {
+ m_pRootDict = root;
+ GetRoot();
+ }
+};
+
+#ifdef PDF_ENABLE_XFA
+class CPDF_TestXFAContext : public CPDFXFA_Context {
+ public:
+ CPDF_TestXFAContext()
+ : CPDFXFA_Context(pdfium::MakeUnique<CPDF_TestDocument>()) {}
+
+ void SetRoot(CPDF_Dictionary* root) {
+ reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root);
+ }
+
+ CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); }
+};
+using CPDF_TestPdfDocument = CPDF_TestXFAContext;
+#else // PDF_ENABLE_XFA
+using CPDF_TestPdfDocument = CPDF_TestDocument;
+#endif // PDF_ENABLE_XFA
+
+class PDFCatalogTest : public testing::Test {
+ public:
+ void SetUp() override {
+ CPDF_ModuleMgr::Get()->Init();
+
+ m_pDoc = pdfium::MakeUnique<CPDF_TestPdfDocument>();
+
+ // Setup the root directory.
+ m_pRootObj = pdfium::MakeUnique<CPDF_Dictionary>();
+ }
+
+ void TearDown() override {
+ m_pDoc.reset();
+ CPDF_ModuleMgr::Destroy();
+ }
+
+ protected:
+ std::unique_ptr<CPDF_TestPdfDocument> m_pDoc;
+ std::unique_ptr<CPDF_Dictionary> m_pRootObj;
+};
+
+TEST_F(PDFCatalogTest, IsTagged) {
+ // Null doc
+ EXPECT_FALSE(FPDFCatalog_IsTagged(nullptr));
+
+ // No root
+ m_pDoc->SetRoot(nullptr);
+ EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get()));
+
+ // Empty root
+ m_pDoc->SetRoot(m_pRootObj.get());
+ EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get()));
+
+ // Root with other key
+ m_pRootObj->SetNewFor<CPDF_String>("OTHER_KEY", "other value", false);
+ EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get()));
+
+ // Root with empty MarkInfo
+ CPDF_Dictionary* markInfoDict =
+ m_pRootObj->SetNewFor<CPDF_Dictionary>("MarkInfo");
+ EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get()));
+
+ // MarkInfo present but Marked is 0
+ markInfoDict->SetNewFor<CPDF_Number>("Marked", 0);
+ EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get()));
+
+ // MarkInfo present and Marked is 1, PDF is considered tagged.
+ markInfoDict->SetNewFor<CPDF_Number>("Marked", 1);
+ EXPECT_TRUE(FPDFCatalog_IsTagged(m_pDoc.get()));
+}