1 // Copyright 2017 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 <memory> 8 9 #include "core/fpdfapi/page/test_with_page_module.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 11 #include "core/fpdfapi/parser/cpdf_document.h" 12 #include "core/fpdfapi/parser/cpdf_number.h" 13 #include "core/fpdfapi/parser/cpdf_parser.h" 14 #include "core/fpdfapi/parser/cpdf_string.h" 15 #include "core/fpdfapi/parser/cpdf_test_document.h" 16 #include "fpdfsdk/cpdfsdk_helpers.h" 17 #include "public/cpp/fpdf_scopers.h" 18 #include "testing/gtest/include/gtest/gtest.h" 19 20 class PDFCatalogTest : public TestWithPageModule { 21 public: SetUp()22 void SetUp() override { 23 TestWithPageModule::SetUp(); 24 auto pTestDoc = std::make_unique<CPDF_TestDocument>(); 25 m_pDoc.reset(FPDFDocumentFromCPDFDocument(pTestDoc.release())); 26 m_pRootObj = pdfium::MakeRetain<CPDF_Dictionary>(); 27 } 28 TearDown()29 void TearDown() override { 30 m_pDoc.reset(); 31 TestWithPageModule::TearDown(); 32 } 33 34 protected: 35 ScopedFPDFDocument m_pDoc; 36 RetainPtr<CPDF_Dictionary> m_pRootObj; 37 }; 38 TEST_F(PDFCatalogTest,IsTagged)39TEST_F(PDFCatalogTest, IsTagged) { 40 // Null doc 41 EXPECT_FALSE(FPDFCatalog_IsTagged(nullptr)); 42 43 CPDF_TestDocument* pTestDoc = static_cast<CPDF_TestDocument*>( 44 CPDFDocumentFromFPDFDocument(m_pDoc.get())); 45 46 // No root 47 pTestDoc->SetRoot(nullptr); 48 EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get())); 49 50 // Empty root 51 pTestDoc->SetRoot(m_pRootObj); 52 EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get())); 53 54 // Root with other key 55 m_pRootObj->SetNewFor<CPDF_String>("OTHER_KEY", "other value", false); 56 EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get())); 57 58 // Root with empty MarkInfo 59 auto markInfoDict = m_pRootObj->SetNewFor<CPDF_Dictionary>("MarkInfo"); 60 EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get())); 61 62 // MarkInfo present but Marked is 0 63 markInfoDict->SetNewFor<CPDF_Number>("Marked", 0); 64 EXPECT_FALSE(FPDFCatalog_IsTagged(m_pDoc.get())); 65 66 // MarkInfo present and Marked is 1, PDF is considered tagged. 67 markInfoDict->SetNewFor<CPDF_Number>("Marked", 1); 68 EXPECT_TRUE(FPDFCatalog_IsTagged(m_pDoc.get())); 69 } 70