summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/parser/cpdf_document.h8
-rw-r--r--core/fpdfapi/parser/cpdf_document_unittest.cpp31
-rw-r--r--fpdfsdk/fpdf_doc_unittest.cpp8
3 files changed, 17 insertions, 30 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index 94d20504c5..db659b38c8 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -61,8 +61,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
}
CPDF_Parser* GetParser() const { return m_pParser.get(); }
- const CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
- CPDF_Dictionary* GetRoot() { return m_pRootDict; }
+ CPDF_Dictionary* GetRoot() const { return m_pRootDict.Get(); }
CPDF_Dictionary* GetInfo();
void DeletePage(int iPage);
@@ -148,10 +147,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
void ResetTraversal();
std::unique_ptr<CPDF_Parser> m_pParser;
-
- // TODO(tsepez): figure out why tests break if this is an UnownedPtr.
- CPDF_Dictionary* m_pRootDict; // Not owned.
-
+ UnownedPtr<CPDF_Dictionary> m_pRootDict;
UnownedPtr<CPDF_Dictionary> m_pInfoDict;
// Vector of pairs to know current position in the page tree. The index in the
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp
index f06a7f42d3..fa52d3bc7f 100644
--- a/core/fpdfapi/parser/cpdf_document_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -87,20 +87,16 @@ class CPDF_TestDocumentForPages : public CPDF_Document {
CPDF_Dictionary* pagesDict =
CreatePageTreeNode(std::move(allPages), this, kNumTestPages);
- m_pOwnedRootDict = pdfium::MakeUnique<CPDF_Dictionary>();
- m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this,
- pagesDict->GetObjNum());
- m_pRootDict = m_pOwnedRootDict.get();
+ m_pRootDict = NewIndirect<CPDF_Dictionary>();
+ m_pRootDict->SetNewFor<CPDF_Reference>("Pages", this,
+ pagesDict->GetObjNum());
m_PageList.resize(kNumTestPages);
}
void SetTreeSize(int size) {
- m_pOwnedRootDict->SetNewFor<CPDF_Number>("Count", size);
+ m_pRootDict->SetNewFor<CPDF_Number>("Count", size);
m_PageList.resize(size);
}
-
- private:
- std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
};
class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
@@ -116,17 +112,15 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
inlined_page_ = allPages->Add(CreateNumberedPage(2));
CPDF_Dictionary* pagesDict =
CreatePageTreeNode(std::move(allPages), this, 3);
- m_pOwnedRootDict = pdfium::MakeUnique<CPDF_Dictionary>();
- m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this,
- pagesDict->GetObjNum());
- m_pRootDict = m_pOwnedRootDict.get();
+ m_pRootDict = NewIndirect<CPDF_Dictionary>();
+ m_pRootDict->SetNewFor<CPDF_Reference>("Pages", this,
+ pagesDict->GetObjNum());
m_PageList.resize(3);
}
const CPDF_Object* inlined_page() const { return inlined_page_; }
private:
- std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
const CPDF_Object* inlined_page_;
};
@@ -143,15 +137,12 @@ class CPDF_TestDocPagesWithoutKids : public CPDF_Document {
pagesDict->SetNewFor<CPDF_Name>("Type", "Pages");
pagesDict->SetNewFor<CPDF_Number>("Count", 3);
m_PageList.resize(10);
- m_pOwnedRootDict = pdfium::MakeUnique<CPDF_Dictionary>();
- m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this,
- pagesDict->GetObjNum());
- m_pRootDict = m_pOwnedRootDict.get();
+ m_pRootDict = NewIndirect<CPDF_Dictionary>();
+ m_pRootDict->SetNewFor<CPDF_Reference>("Pages", this,
+ pagesDict->GetObjNum());
}
-
- private:
- std::unique_ptr<CPDF_Dictionary> m_pOwnedRootDict;
};
+
} // namespace
class cpdf_document_test : public testing::Test {
diff --git a/fpdfsdk/fpdf_doc_unittest.cpp b/fpdfsdk/fpdf_doc_unittest.cpp
index 0234d47833..58b8ffd42d 100644
--- a/fpdfsdk/fpdf_doc_unittest.cpp
+++ b/fpdfsdk/fpdf_doc_unittest.cpp
@@ -42,13 +42,13 @@ class PDFDocTest : public testing::Test {
CPDF_ModuleMgr::Get()->Init();
auto pTestDoc = pdfium::MakeUnique<CPDF_TestDocument>();
m_pIndirectObjs = pTestDoc->GetHolder();
- m_pRootObj = pdfium::MakeUnique<CPDF_Dictionary>();
- pTestDoc->SetRoot(m_pRootObj.get());
+ m_pRootObj = m_pIndirectObjs->NewIndirect<CPDF_Dictionary>();
+ pTestDoc->SetRoot(m_pRootObj.Get());
m_pDoc.reset(FPDFDocumentFromCPDFDocument(pTestDoc.release()));
}
void TearDown() override {
- m_pRootObj.reset();
+ m_pRootObj = nullptr;
m_pIndirectObjs = nullptr;
m_pDoc.reset();
CPDF_ModuleMgr::Destroy();
@@ -67,7 +67,7 @@ class PDFDocTest : public testing::Test {
protected:
ScopedFPDFDocument m_pDoc;
UnownedPtr<CPDF_IndirectObjectHolder> m_pIndirectObjs;
- std::unique_ptr<CPDF_Dictionary> m_pRootObj;
+ UnownedPtr<CPDF_Dictionary> m_pRootObj;
};
TEST_F(PDFDocTest, FindBookmark) {