From 2617056df6d6e1d0f17031f0c9db09f9192cb0fa Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 17 Apr 2018 17:01:52 +0000 Subject: Add constants for PDF 1.7 spec, table 3.4. Add constants/stream_dict_common.h. The header lists all the constants in the table in the same order. Constants that are not used at all are commented out. BUG=pdfium:1049 Change-Id: I6539090e0ad56319ea628883e388aeacef044e52 Reviewed-on: https://pdfium-review.googlesource.com/29090 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- core/fpdfapi/parser/cpdf_object_unittest.cpp | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_object_unittest.cpp') diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index 4b16021069..4780e87bc0 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -7,6 +7,7 @@ #include #include +#include "constants/stream_dict_common.h" #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_boolean.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" @@ -790,21 +791,25 @@ TEST(PDFStreamTest, SetData) { stream->InitStream(data.data(), data.size(), pdfium::MakeUnique()); EXPECT_EQ(static_cast(data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); - stream->GetDict()->SetNewFor("Filter", L"SomeFilter"); - stream->GetDict()->SetNewFor("DecodeParms", L"SomeParams"); + stream->GetDict()->SetNewFor(pdfium::stream::kFilter, + L"SomeFilter"); + stream->GetDict()->SetNewFor(pdfium::stream::kDecodeParms, + L"SomeParams"); std::vector new_data(data.size() * 2); stream->SetData(new_data.data(), new_data.size()); // The "Length" field should be updated for new data size. EXPECT_EQ(static_cast(new_data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); // The "Filter" and "DecodeParms" fields should not be changed. - EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("Filter"), L"SomeFilter"); - EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("DecodeParms"), L"SomeParams"); + EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor(pdfium::stream::kFilter), + L"SomeFilter"); + EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor(pdfium::stream::kDecodeParms), + L"SomeParams"); } TEST(PDFStreamTest, SetDataAndRemoveFilter) { @@ -813,20 +818,22 @@ TEST(PDFStreamTest, SetDataAndRemoveFilter) { stream->InitStream(data.data(), data.size(), pdfium::MakeUnique()); EXPECT_EQ(static_cast(data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); - stream->GetDict()->SetNewFor("Filter", L"SomeFilter"); - stream->GetDict()->SetNewFor("DecodeParms", L"SomeParams"); + stream->GetDict()->SetNewFor(pdfium::stream::kFilter, + L"SomeFilter"); + stream->GetDict()->SetNewFor(pdfium::stream::kDecodeParms, + L"SomeParams"); std::vector new_data(data.size() * 2); stream->SetDataAndRemoveFilter(new_data.data(), new_data.size()); // The "Length" field should be updated for new data size. EXPECT_EQ(static_cast(new_data.size()), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); // The "Filter" and "DecodeParms" should be removed. - EXPECT_FALSE(stream->GetDict()->KeyExist("Filter")); - EXPECT_FALSE(stream->GetDict()->KeyExist("DecodeParms")); + EXPECT_FALSE(stream->GetDict()->KeyExist(pdfium::stream::kFilter)); + EXPECT_FALSE(stream->GetDict()->KeyExist(pdfium::stream::kDecodeParms)); } TEST(PDFStreamTest, LengthInDictionaryOnCreate) { @@ -838,18 +845,18 @@ TEST(PDFStreamTest, LengthInDictionaryOnCreate) { auto stream = pdfium::MakeUnique( std::move(data), kBufSize, pdfium::MakeUnique()); EXPECT_EQ(static_cast(kBufSize), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); } // The length field should be corrected on stream create. { std::unique_ptr data; data.reset(FX_Alloc(uint8_t, kBufSize)); auto dict = pdfium::MakeUnique(); - dict->SetNewFor("Length", 30000); + dict->SetNewFor(pdfium::stream::kLength, 30000); auto stream = pdfium::MakeUnique(std::move(data), kBufSize, std::move(dict)); EXPECT_EQ(static_cast(kBufSize), - stream->GetDict()->GetIntegerFor("Length")); + stream->GetDict()->GetIntegerFor(pdfium::stream::kLength)); } } -- cgit v1.2.3