From 822484b5f88d92dbcd567b1c2da38af1e720b56f Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 11 Apr 2016 18:14:56 -0700 Subject: Remove CPDF_Object::GetConstString and overrides GetConstString() has sharp edges in that when applied to a CPDF_Number, it must return null whereas GetString() returns a the stringified number, because of the inability to control the lifetime of the underlying allocated string. Deleting this method showed several places where we actually wanted a *String, not a *StringC, so we were re-allocating a string we already had. Review URL: https://codereview.chromium.org/1879683002 --- core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp | 32 ----------------------- 1 file changed, 32 deletions(-) (limited to '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 362991f723..3d0947d643 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp @@ -34,7 +34,6 @@ void TestArrayAccessors(const CPDF_Array* arr, CPDF_Dictionary* dict_val, CPDF_Stream* stream_val) { EXPECT_STREQ(str_val, arr->GetStringAt(index).c_str()); - EXPECT_STREQ(const_str_val, arr->GetConstStringAt(index).c_str()); EXPECT_EQ(int_val, arr->GetIntegerAt(index)); EXPECT_EQ(float_val, arr->GetNumberAt(index)); EXPECT_EQ(float_val, arr->GetFloatAt(index)); @@ -199,33 +198,6 @@ TEST_F(PDFObjectsTest, GetString) { } } -TEST_F(PDFObjectsTest, GetConstString) { - const char* direct_obj_results[] = { - nullptr, nullptr, nullptr, nullptr, "A simple test", "\t\n", - "space", nullptr, nullptr, nullptr, nullptr}; - // Check for direct objects. - for (size_t i = 0; i < m_DirectObjs.size(); ++i) { - if (!direct_obj_results[i]) { - EXPECT_EQ(direct_obj_results[i], - m_DirectObjs[i]->GetConstString().c_str()); - } else { - EXPECT_STREQ(direct_obj_results[i], - m_DirectObjs[i]->GetConstString().c_str()); - } - } - // Check indirect references. - const char* indirect_obj_results[] = {nullptr, nullptr, "\t\n", "space", - nullptr, nullptr, nullptr}; - for (size_t i = 0; i < m_RefObjs.size(); ++i) { - if (!indirect_obj_results[i]) { - EXPECT_EQ(nullptr, m_RefObjs[i]->GetConstString().c_str()); - } else { - EXPECT_STREQ(indirect_obj_results[i], - m_RefObjs[i]->GetConstString().c_str()); - } - } -} - TEST_F(PDFObjectsTest, GetUnicodeText) { const wchar_t* direct_obj_results[] = { L"", L"", L"", L"", L"A simple test", @@ -668,16 +640,12 @@ TEST(PDFArrayTest, GetTypeAt) { const char* const expected_str[] = { "true", "false", "0", "-1234", "2345", "0.05", "", "It is a test!", "NAME", "test", "", "", "", ""}; - const char* const expected_cstr[] = { - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - "It is a test!", "NAME", "test", nullptr, nullptr, nullptr, nullptr}; const int expected_int[] = {1, 0, 0, -1234, 2345, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const float expected_float[] = {0, 0, 0, -1234, 2345, 0.05f, 0, 0, 0, 0, 0, 0, 0, 0}; for (size_t i = 0; i < arr->GetCount(); ++i) { EXPECT_STREQ(expected_str[i], arr->GetStringAt(i).c_str()); - EXPECT_STREQ(expected_cstr[i], arr->GetConstStringAt(i).c_str()); EXPECT_EQ(expected_int[i], arr->GetIntegerAt(i)); EXPECT_EQ(expected_float[i], arr->GetNumberAt(i)); EXPECT_EQ(expected_float[i], arr->GetFloatAt(i)); -- cgit v1.2.3