Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp

Issue 2384883003: Remove CPDF_Object::Release() in favor of direct delete (Closed)
Patch Set: Remove ScopedDict typedefs Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
index f62e73df810b75856bd29ea8f3f7fe3d90f91a5e..e7de4e4648ebc95df1914927dbcd433e6b9e2cf7 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
@@ -22,11 +22,6 @@
namespace {
-using ScopedArray = std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>>;
-using ScopedDict =
- std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>;
-using ScopedStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Stream>>;
-
void TestArrayAccessors(const CPDF_Array* arr,
size_t index,
const char* str_val,
@@ -173,7 +168,7 @@ class PDFObjectsTest : public testing::Test {
}
protected:
- using ScopedObj = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>;
+ using ScopedObj = std::unique_ptr<CPDF_Object>;
// m_ObjHolder needs to be declared first and destructed last since it also
// refers to some objects in m_DirectObjs.
@@ -393,7 +388,7 @@ TEST(PDFArrayTest, GetMatrix) {
{2.3f, 4.05f, 3, -2, -3, 0.0f},
{0.05f, 0.1f, 0.56f, 0.67f, 1.34f, 99.9f}};
for (size_t i = 0; i < FX_ArraySize(elems); ++i) {
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
CFX_Matrix matrix(elems[i][0], elems[i][1], elems[i][2], elems[i][3],
elems[i][4], elems[i][5]);
for (size_t j = 0; j < 6; ++j)
@@ -414,7 +409,7 @@ TEST(PDFArrayTest, GetRect) {
{2.3f, 4.05f, -3, 0.0f},
{0.05f, 0.1f, 1.34f, 99.9f}};
for (size_t i = 0; i < FX_ArraySize(elems); ++i) {
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
CFX_FloatRect rect(elems[i]);
for (size_t j = 0; j < 4; ++j)
arr->AddNumber(elems[i][j]);
@@ -430,7 +425,7 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Boolean array.
const bool vals[] = {true, false, false, true, true};
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
arr->InsertAt(i, new CPDF_Boolean(vals[i]));
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
@@ -447,7 +442,7 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Integer array.
const int vals[] = {10, 0, -345, 2089345456, -1000000000, 567, 93658767};
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
arr->InsertAt(i, new CPDF_Number(vals[i]));
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
@@ -468,7 +463,7 @@ TEST(PDFArrayTest, GetTypeAt) {
897.34f, -2.5f, -1.0f, -345.0f, -0.0f};
const char* const expected_str[] = {
"0", "0", "10", "10", "0.0345", "897.34", "-2.5", "-1", "-345", "0"};
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
arr->InsertAt(i, new CPDF_Number(vals[i]));
}
@@ -487,8 +482,8 @@ TEST(PDFArrayTest, GetTypeAt) {
// String and name array
const char* const vals[] = {"this", "adsde$%^", "\r\t", "\"012",
".", "EYREW", "It is a joke :)"};
- ScopedArray string_array(new CPDF_Array);
- ScopedArray name_array(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
string_array->InsertAt(i, new CPDF_String(vals[i], false));
name_array->InsertAt(i, new CPDF_Name(vals[i]));
@@ -514,7 +509,7 @@ TEST(PDFArrayTest, GetTypeAt) {
}
{
// Null element array.
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < 3; ++i)
arr->InsertAt(i, new CPDF_Null);
for (size_t i = 0; i < 3; ++i) {
@@ -531,7 +526,7 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Array of array.
CPDF_Array* vals[3];
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < 3; ++i) {
vals[i] = new CPDF_Array;
for (size_t j = 0; j < 3; ++j) {
@@ -554,7 +549,7 @@ TEST(PDFArrayTest, GetTypeAt) {
{
// Dictionary array.
CPDF_Dictionary* vals[3];
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < 3; ++i) {
vals[i] = new CPDF_Dictionary();
for (size_t j = 0; j < 3; ++j) {
@@ -581,7 +576,7 @@ TEST(PDFArrayTest, GetTypeAt) {
// Stream array.
CPDF_Dictionary* vals[3];
CPDF_Stream* stream_vals[3];
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < 3; ++i) {
vals[i] = new CPDF_Dictionary();
for (size_t j = 0; j < 3; ++j) {
@@ -611,7 +606,7 @@ TEST(PDFArrayTest, GetTypeAt) {
}
{
// Mixed array.
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
// Array arr will take ownership of all the objects inserted.
arr->InsertAt(0, new CPDF_Boolean(true));
arr->InsertAt(1, new CPDF_Boolean(false));
@@ -676,7 +671,7 @@ TEST(PDFArrayTest, GetTypeAt) {
TEST(PDFArrayTest, AddNumber) {
float vals[] = {1.0f, -1.0f, 0, 0.456734f,
12345.54321f, 0.5f, 1000, 0.000045f};
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
arr->AddNumber(vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
@@ -687,7 +682,7 @@ TEST(PDFArrayTest, AddNumber) {
TEST(PDFArrayTest, AddInteger) {
int vals[] = {0, 1, 934435456, 876, 10000, -1, -24354656, -100};
- ScopedArray arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i)
arr->AddInteger(vals[i]);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
@@ -699,8 +694,8 @@ TEST(PDFArrayTest, AddInteger) {
TEST(PDFArrayTest, AddStringAndName) {
const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323",
"$#%^&**", " ", "This is a test.\r\n"};
- ScopedArray string_array(new CPDF_Array);
- ScopedArray name_array(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
string_array->AddString(vals[i]);
name_array->AddName(vals[i]);
@@ -725,8 +720,8 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
CPDF_Object* indirect_objs[] = {boolean_obj, int_obj, float_obj,
str_obj, name_obj, null_obj};
unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
- ScopedArray arr(new CPDF_Array);
- ScopedArray arr1(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr1(new CPDF_Array);
// Create two arrays of references by different AddReference() APIs.
for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
// All the indirect objects inserted will be owned by holder.
@@ -752,7 +747,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
TEST(PDFArrayTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
- ScopedArray array(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> array(new CPDF_Array);
array->AddReference(&objects_holder, 1234);
ASSERT_EQ(1U, array->GetCount());
CPDF_Object* obj = array->GetObjectAt(0);
@@ -763,7 +758,7 @@ TEST(PDFArrayTest, CloneDirectObject) {
ASSERT_TRUE(cloned_array_object);
ASSERT_TRUE(cloned_array_object->IsArray());
- ScopedArray cloned_array(cloned_array_object->AsArray());
+ std::unique_ptr<CPDF_Array> cloned_array(cloned_array_object->AsArray());
ASSERT_EQ(1U, cloned_array->GetCount());
CPDF_Object* cloned_obj = cloned_array->GetObjectAt(0);
EXPECT_FALSE(cloned_obj);
@@ -771,7 +766,7 @@ TEST(PDFArrayTest, CloneDirectObject) {
TEST(PDFDictionaryTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
- ScopedDict dict(new CPDF_Dictionary());
+ std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary());
dict->SetReferenceFor("foo", &objects_holder, 1234);
ASSERT_EQ(1U, dict->GetCount());
CPDF_Object* obj = dict->GetObjectFor("foo");
@@ -782,7 +777,8 @@ TEST(PDFDictionaryTest, CloneDirectObject) {
ASSERT_TRUE(cloned_dict_object);
ASSERT_TRUE(cloned_dict_object->IsDictionary());
- ScopedDict cloned_dict(cloned_dict_object->AsDictionary());
+ std::unique_ptr<CPDF_Dictionary> cloned_dict(
+ cloned_dict_object->AsDictionary());
ASSERT_EQ(1U, cloned_dict->GetCount());
CPDF_Object* cloned_obj = cloned_dict->GetObjectFor("foo");
EXPECT_FALSE(cloned_obj);
@@ -792,12 +788,12 @@ TEST(PDFObjectTest, CloneCheckLoop) {
{
// Create an dictionary/array pair with a reference loop.
CPDF_Dictionary* dict_obj = new CPDF_Dictionary();
- ScopedArray arr_obj(new CPDF_Array);
+ std::unique_ptr<CPDF_Array> arr_obj(new CPDF_Array);
dict_obj->SetFor("arr", arr_obj.get());
arr_obj->InsertAt(0, dict_obj);
// Clone this object to see whether stack overflow will be triggered.
- ScopedArray cloned_array(arr_obj->Clone()->AsArray());
+ std::unique_ptr<CPDF_Array> cloned_array(arr_obj->Clone()->AsArray());
// Cloned object should be the same as the original.
ASSERT_TRUE(cloned_array);
EXPECT_EQ(1u, cloned_array->GetCount());
@@ -810,11 +806,12 @@ TEST(PDFObjectTest, CloneCheckLoop) {
{
// Create a dictionary/stream pair with a reference loop.
CPDF_Dictionary* dict_obj = new CPDF_Dictionary();
- ScopedStream stream_obj(new CPDF_Stream(nullptr, 0, dict_obj));
+ std::unique_ptr<CPDF_Stream> stream_obj(
+ new CPDF_Stream(nullptr, 0, dict_obj));
dict_obj->SetFor("stream", stream_obj.get());
// Clone this object to see whether stack overflow will be triggered.
- ScopedStream cloned_stream(stream_obj->Clone()->AsStream());
+ std::unique_ptr<CPDF_Stream> cloned_stream(stream_obj->Clone()->AsStream());
// Cloned object should be the same as the original.
ASSERT_TRUE(cloned_stream);
CPDF_Object* cloned_dict = cloned_stream->GetDict();
@@ -840,7 +837,8 @@ TEST(PDFObjectTest, CloneCheckLoop) {
EXPECT_EQ(dict_obj, elem0->AsReference()->GetDirect());
// Clone this object to see whether stack overflow will be triggered.
- ScopedDict cloned_dict(ToDictionary(dict_obj->CloneDirectObject()));
+ std::unique_ptr<CPDF_Dictionary> cloned_dict(
+ ToDictionary(dict_obj->CloneDirectObject()));
// Cloned object should be the same as the original.
ASSERT_TRUE(cloned_dict);
CPDF_Object* cloned_arr = cloned_dict->GetObjectFor("arr");

Powered by Google App Engine
This is Rietveld 408576698