From 971a674ef17526ad37ce55ba90110830b94889d0 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 28 Mar 2018 19:23:25 +0000 Subject: 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 Reviewed-by: Henrique Nakashima --- fpdfsdk/fpdfdoc_unittest.cpp | 271 ------------------------------------------- 1 file changed, 271 deletions(-) delete mode 100644 fpdfsdk/fpdfdoc_unittest.cpp (limited to 'fpdfsdk/fpdfdoc_unittest.cpp') diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp deleted file mode 100644 index b52cccf098..0000000000 --- a/fpdfsdk/fpdfdoc_unittest.cpp +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2016 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_doc.h" - -#include -#include - -#include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/cpdf_name.h" -#include "core/fpdfapi/parser/cpdf_null.h" -#include "core/fpdfapi/parser/cpdf_number.h" -#include "core/fpdfapi/parser/cpdf_parser.h" -#include "core/fpdfapi/parser/cpdf_reference.h" -#include "core/fpdfapi/parser/cpdf_string.h" -#include "core/fpdfdoc/cpdf_dest.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/test_support.h" -#include "third_party/base/ptr_util.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; } - CPDF_IndirectObjectHolder* GetHolder() { return this; } -}; - -#ifdef PDF_ENABLE_XFA -class CPDF_TestXFAContext : public CPDFXFA_Context { - public: - CPDF_TestXFAContext() - : CPDFXFA_Context(pdfium::MakeUnique()) {} - - void SetRoot(CPDF_Dictionary* root) { - reinterpret_cast(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 PDFDocTest : public testing::Test { - public: - struct DictObjInfo { - uint32_t num; - CPDF_Dictionary* obj; - }; - - void SetUp() override { - CPDF_ModuleMgr::Get()->Init(); - - m_pDoc = pdfium::MakeUnique(); - m_pIndirectObjs = m_pDoc->GetHolder(); - - // Setup the root directory. - m_pRootObj = pdfium::MakeUnique(); - m_pDoc->SetRoot(m_pRootObj.get()); - } - - void TearDown() override { - m_pRootObj.reset(); - m_pIndirectObjs = nullptr; - m_pDoc.reset(); - CPDF_ModuleMgr::Destroy(); - } - - std::vector CreateDictObjs(int num) { - std::vector info; - for (int i = 0; i < num; ++i) { - // Objects created will be released by the document. - CPDF_Dictionary* obj = m_pIndirectObjs->NewIndirect(); - info.push_back({obj->GetObjNum(), obj}); - } - return info; - } - - protected: - std::unique_ptr m_pDoc; - UnownedPtr m_pIndirectObjs; - std::unique_ptr m_pRootObj; -}; - -TEST_F(PDFDocTest, FindBookmark) { - { - // No bookmark information. - std::unique_ptr title = - GetFPDFWideString(L""); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - title = GetFPDFWideString(L"Preface"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - } - { - // Empty bookmark tree. - m_pRootObj->SetNewFor("Outlines"); - std::unique_ptr title = - GetFPDFWideString(L""); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - title = GetFPDFWideString(L"Preface"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - } - { - // Check on a regular bookmark tree. - auto bookmarks = CreateDictObjs(3); - - bookmarks[1].obj->SetNewFor("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[1].obj->SetNewFor("Next", m_pIndirectObjs.Get(), - bookmarks[2].num); - - bookmarks[2].obj->SetNewFor("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[2].obj->SetNewFor("Prev", m_pIndirectObjs.Get(), - bookmarks[1].num); - - bookmarks[0].obj->SetNewFor("Type", "Outlines"); - bookmarks[0].obj->SetNewFor("Count", 2); - bookmarks[0].obj->SetNewFor("First", m_pIndirectObjs.Get(), - bookmarks[1].num); - bookmarks[0].obj->SetNewFor("Last", m_pIndirectObjs.Get(), - bookmarks[2].num); - - m_pRootObj->SetNewFor("Outlines", m_pIndirectObjs.Get(), - bookmarks[0].num); - - // Title with no match. - std::unique_ptr title = - GetFPDFWideString(L"Chapter 3"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - // Title with partial match only. - title = GetFPDFWideString(L"Chapter"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - // Title with a match. - title = GetFPDFWideString(L"Chapter 2"); - EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - // Title match is case insensitive. - title = GetFPDFWideString(L"cHaPter 2"); - EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); - } - { - // Circular bookmarks in depth. - auto bookmarks = CreateDictObjs(3); - - bookmarks[1].obj->SetNewFor("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[1].obj->SetNewFor("First", m_pIndirectObjs.Get(), - bookmarks[2].num); - - bookmarks[2].obj->SetNewFor("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[1].num); - bookmarks[2].obj->SetNewFor("First", m_pIndirectObjs.Get(), - bookmarks[1].num); - - bookmarks[0].obj->SetNewFor("Type", "Outlines"); - bookmarks[0].obj->SetNewFor("Count", 2); - bookmarks[0].obj->SetNewFor("First", m_pIndirectObjs.Get(), - bookmarks[1].num); - bookmarks[0].obj->SetNewFor("Last", m_pIndirectObjs.Get(), - bookmarks[2].num); - - m_pRootObj->SetNewFor("Outlines", m_pIndirectObjs.Get(), - bookmarks[0].num); - - // Title with no match. - std::unique_ptr title = - GetFPDFWideString(L"Chapter 3"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - // Title with a match. - title = GetFPDFWideString(L"Chapter 2"); - EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); - } - { - // Circular bookmarks in breadth. - auto bookmarks = CreateDictObjs(4); - - bookmarks[1].obj->SetNewFor("Title", L"Chapter 1"); - bookmarks[1].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[1].obj->SetNewFor("Next", m_pIndirectObjs.Get(), - bookmarks[2].num); - - bookmarks[2].obj->SetNewFor("Title", L"Chapter 2"); - bookmarks[2].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[2].obj->SetNewFor("Next", m_pIndirectObjs.Get(), - bookmarks[3].num); - - bookmarks[3].obj->SetNewFor("Title", L"Chapter 3"); - bookmarks[3].obj->SetNewFor("Parent", m_pIndirectObjs.Get(), - bookmarks[0].num); - bookmarks[3].obj->SetNewFor("Next", m_pIndirectObjs.Get(), - bookmarks[1].num); - - bookmarks[0].obj->SetNewFor("Type", "Outlines"); - bookmarks[0].obj->SetNewFor("Count", 2); - bookmarks[0].obj->SetNewFor("First", m_pIndirectObjs.Get(), - bookmarks[1].num); - bookmarks[0].obj->SetNewFor("Last", m_pIndirectObjs.Get(), - bookmarks[2].num); - - m_pRootObj->SetNewFor("Outlines", m_pIndirectObjs.Get(), - bookmarks[0].num); - - // Title with no match. - std::unique_ptr title = - GetFPDFWideString(L"Chapter 8"); - EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get())); - - // Title with a match. - title = GetFPDFWideString(L"Chapter 3"); - EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get())); - } -} - -TEST_F(PDFDocTest, GetLocationInPage) { - auto array = pdfium::MakeUnique(); - array->AddNew(0); // Page Index. - array->AddNew("XYZ"); - array->AddNew(4); // X - array->AddNew(5); // Y - array->AddNew(6); // Zoom. - - FPDF_BOOL hasX; - FPDF_BOOL hasY; - FPDF_BOOL hasZoom; - FS_FLOAT x; - FS_FLOAT y; - FS_FLOAT zoom; - - EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom, - &x, &y, &zoom)); - EXPECT_TRUE(hasX); - EXPECT_TRUE(hasY); - EXPECT_TRUE(hasZoom); - EXPECT_EQ(4, x); - EXPECT_EQ(5, y); - EXPECT_EQ(6, zoom); - - array->SetNewAt(2); - array->SetNewAt(3); - array->SetNewAt(4); - EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom, - &x, &y, &zoom)); - EXPECT_FALSE(hasX); - EXPECT_FALSE(hasY); - EXPECT_FALSE(hasZoom); - - array = pdfium::MakeUnique(); - EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom, - &x, &y, &zoom)); -} -- cgit v1.2.3