diff options
Diffstat (limited to 'core/fxcrt/tree_node_unittest.cpp')
-rw-r--r-- | core/fxcrt/tree_node_unittest.cpp | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/core/fxcrt/tree_node_unittest.cpp b/core/fxcrt/tree_node_unittest.cpp index 26dd610ce..ecd5b09f2 100644 --- a/core/fxcrt/tree_node_unittest.cpp +++ b/core/fxcrt/tree_node_unittest.cpp @@ -1,4 +1,4 @@ -// Copyright 2019 PDFium Authors. All rights reserved. +// Copyright 2019 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,7 +7,6 @@ #include <memory> #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/base/ptr_util.h" namespace fxcrt { @@ -17,114 +16,114 @@ class TestTreeNode : public TreeNode<TestTreeNode> {}; // These tests check that we trip CHECKS given bad calls. TEST(TreeNode, SelfAppendFirstChild) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); EXPECT_DEATH(pNode->AppendFirstChild(pNode.get()), ""); } TEST(TreeNode, SelfAppendLastChild) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); EXPECT_DEATH(pNode->AppendLastChild(pNode.get()), ""); } TEST(TreeNode, SelfInsertBeforeOther) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); - auto pOther = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); + auto pOther = std::make_unique<TestTreeNode>(); pNode->AppendFirstChild(pOther.get()); EXPECT_DEATH(pNode->InsertBefore(pNode.get(), pOther.get()), ""); } TEST(TreeNode, InsertOtherBeforeSelf) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); - auto pOther = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); + auto pOther = std::make_unique<TestTreeNode>(); pNode->AppendFirstChild(pOther.get()); EXPECT_DEATH(pNode->InsertBefore(pOther.get(), pNode.get()), ""); } TEST(TreeNode, SelfInsertAfterOther) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); - auto pOther = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); + auto pOther = std::make_unique<TestTreeNode>(); pNode->AppendFirstChild(pOther.get()); EXPECT_DEATH(pNode->InsertBefore(pNode.get(), pOther.get()), ""); } TEST(TreeNode, InsertOtherAfterSelf) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); - auto pOther = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); + auto pOther = std::make_unique<TestTreeNode>(); pNode->AppendFirstChild(pOther.get()); EXPECT_DEATH(pNode->InsertBefore(pOther.get(), pNode.get()), ""); } TEST(TreeNode, RemoveParentless) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); EXPECT_DEATH(pNode->GetParent()->RemoveChild(pNode.get()), ""); } TEST(TreeNode, RemoveFromWrongParent) { - auto pGoodParent = pdfium::MakeUnique<TestTreeNode>(); - auto pBadParent = pdfium::MakeUnique<TestTreeNode>(); - auto pNode = pdfium::MakeUnique<TestTreeNode>(); + auto pGoodParent = std::make_unique<TestTreeNode>(); + auto pBadParent = std::make_unique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); pGoodParent->AppendFirstChild(pNode.get()); EXPECT_DEATH(pBadParent->RemoveChild(pNode.get()), ""); } TEST(TreeNode, SafeRemove) { - auto pParent = pdfium::MakeUnique<TestTreeNode>(); - auto pChild = pdfium::MakeUnique<TestTreeNode>(); + auto pParent = std::make_unique<TestTreeNode>(); + auto pChild = std::make_unique<TestTreeNode>(); pParent->AppendFirstChild(pChild.get()); pChild->RemoveSelfIfParented(); - EXPECT_EQ(nullptr, pParent->GetFirstChild()); - EXPECT_EQ(nullptr, pChild->GetParent()); + EXPECT_FALSE(pParent->GetFirstChild()); + EXPECT_FALSE(pChild->GetParent()); } TEST(TreeNode, SafeRemoveParentless) { - auto pNode = pdfium::MakeUnique<TestTreeNode>(); + auto pNode = std::make_unique<TestTreeNode>(); pNode->RemoveSelfIfParented(); - EXPECT_EQ(nullptr, pNode->GetParent()); + EXPECT_FALSE(pNode->GetParent()); } TEST(TreeNode, RemoveAllChildren) { - auto pParent = pdfium::MakeUnique<TestTreeNode>(); + auto pParent = std::make_unique<TestTreeNode>(); pParent->RemoveAllChildren(); - EXPECT_EQ(nullptr, pParent->GetFirstChild()); + EXPECT_FALSE(pParent->GetFirstChild()); - auto p0 = pdfium::MakeUnique<TestTreeNode>(); - auto p1 = pdfium::MakeUnique<TestTreeNode>(); - auto p2 = pdfium::MakeUnique<TestTreeNode>(); - auto p3 = pdfium::MakeUnique<TestTreeNode>(); + auto p0 = std::make_unique<TestTreeNode>(); + auto p1 = std::make_unique<TestTreeNode>(); + auto p2 = std::make_unique<TestTreeNode>(); + auto p3 = std::make_unique<TestTreeNode>(); pParent->AppendLastChild(p0.get()); pParent->AppendLastChild(p1.get()); pParent->AppendLastChild(p2.get()); pParent->AppendLastChild(p3.get()); pParent->RemoveAllChildren(); - EXPECT_EQ(nullptr, pParent->GetFirstChild()); + EXPECT_FALSE(pParent->GetFirstChild()); } TEST(TreeNode, NthChild) { - auto pParent = pdfium::MakeUnique<TestTreeNode>(); - EXPECT_EQ(nullptr, pParent->GetNthChild(-1)); - EXPECT_EQ(nullptr, pParent->GetNthChild(0)); - - auto p0 = pdfium::MakeUnique<TestTreeNode>(); - auto p1 = pdfium::MakeUnique<TestTreeNode>(); - auto p2 = pdfium::MakeUnique<TestTreeNode>(); - auto p3 = pdfium::MakeUnique<TestTreeNode>(); + auto pParent = std::make_unique<TestTreeNode>(); + EXPECT_FALSE(pParent->GetNthChild(-1)); + EXPECT_FALSE(pParent->GetNthChild(0)); + + auto p0 = std::make_unique<TestTreeNode>(); + auto p1 = std::make_unique<TestTreeNode>(); + auto p2 = std::make_unique<TestTreeNode>(); + auto p3 = std::make_unique<TestTreeNode>(); pParent->AppendLastChild(p0.get()); pParent->AppendLastChild(p1.get()); pParent->AppendLastChild(p2.get()); pParent->AppendLastChild(p3.get()); - EXPECT_EQ(nullptr, pParent->GetNthChild(-1)); + EXPECT_FALSE(pParent->GetNthChild(-1)); EXPECT_EQ(p0.get(), pParent->GetNthChild(0)); EXPECT_EQ(p1.get(), pParent->GetNthChild(1)); EXPECT_EQ(p2.get(), pParent->GetNthChild(2)); EXPECT_EQ(p3.get(), pParent->GetNthChild(3)); - EXPECT_EQ(nullptr, pParent->GetNthChild(4)); + EXPECT_FALSE(pParent->GetNthChild(4)); pParent->RemoveAllChildren(); } TEST(TreeNode, AppendFirstChild) { - auto parent = pdfium::MakeUnique<TestTreeNode>(); - auto child0 = pdfium::MakeUnique<TestTreeNode>(); - auto child1 = pdfium::MakeUnique<TestTreeNode>(); + auto parent = std::make_unique<TestTreeNode>(); + auto child0 = std::make_unique<TestTreeNode>(); + auto child1 = std::make_unique<TestTreeNode>(); parent->AppendFirstChild(child0.get()); EXPECT_EQ(child0.get(), parent->GetFirstChild()); parent->AppendFirstChild(child1.get()); @@ -134,9 +133,9 @@ TEST(TreeNode, AppendFirstChild) { } TEST(TreeNode, RemoveChild) { - auto parent = pdfium::MakeUnique<TestTreeNode>(); - auto child0 = pdfium::MakeUnique<TestTreeNode>(); - auto child1 = pdfium::MakeUnique<TestTreeNode>(); + auto parent = std::make_unique<TestTreeNode>(); + auto child0 = std::make_unique<TestTreeNode>(); + auto child1 = std::make_unique<TestTreeNode>(); parent->AppendFirstChild(child0.get()); parent->AppendLastChild(child1.get()); @@ -146,8 +145,8 @@ TEST(TreeNode, RemoveChild) { EXPECT_EQ(child1.get(), parent->GetFirstChild()); EXPECT_EQ(child1.get(), parent->GetLastChild()); parent->RemoveChild(child1.get()); - EXPECT_EQ(nullptr, parent->GetFirstChild()); - EXPECT_EQ(nullptr, parent->GetLastChild()); + EXPECT_FALSE(parent->GetFirstChild()); + EXPECT_FALSE(parent->GetLastChild()); parent->AppendFirstChild(child0.get()); parent->AppendLastChild(child1.get()); @@ -157,8 +156,8 @@ TEST(TreeNode, RemoveChild) { EXPECT_EQ(child0.get(), parent->GetFirstChild()); EXPECT_EQ(child0.get(), parent->GetLastChild()); parent->RemoveChild(child0.get()); - EXPECT_EQ(nullptr, parent->GetFirstChild()); - EXPECT_EQ(nullptr, parent->GetLastChild()); + EXPECT_FALSE(parent->GetFirstChild()); + EXPECT_FALSE(parent->GetLastChild()); } } // namespace fxcrt |