From 0729be26d745e2ea713908eb9040e2be7c40c96b Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 5 Feb 2018 21:13:51 +0000 Subject: Make EmbedderTest class member style consistent. The class started with |foo_bar_| but now has a mixture of |foo_bar_| and |m_FooBar|. Change them all to |foo_bar_|. While making this change, also initialize the members in the header when possible. Change-Id: I202ff5dc5e945175ad4da2f3245724f3493aa8aa Reviewed-on: https://pdfium-review.googlesource.com/25390 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- .../parser/cpdf_security_handler_embeddertest.cpp | 2 +- fpdfsdk/fpdfedit_embeddertest.cpp | 4 +- testing/embedder_test.cpp | 57 ++++++++++------------ testing/embedder_test.h | 39 ++++++++------- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp index a1d5fda510..cc29b8954e 100644 --- a/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp +++ b/core/fpdfapi/parser/cpdf_security_handler_embeddertest.cpp @@ -83,7 +83,7 @@ TEST_F(CPDFSecurityHandlerEmbeddertest, PasswordAfterGenerateSave) { OpenSavedDocument(test.password); FPDF_PAGE page = LoadSavedPage(0); VerifySavedRendering(page, 612, 792, md5); - EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(m_SavedDocument)); + EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(saved_document_)); CloseSavedPage(page); CloseSavedDocument(); diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index c0ddd77cda..1a422bd941 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -472,14 +472,14 @@ TEST_F(FPDFEditEmbeddertest, EditOverExistingContent) { EXPECT_TRUE(FPDFPath_SetFillColor(green_rect2, 0, 255, 0, 100)); EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect2, FPDF_FILLMODE_ALTERNATE, 0)); FPDFPage_InsertObject(page, green_rect2); - FPDF_BITMAP new_bitmap = RenderPageWithFlags(page, m_SavedForm, 0); + FPDF_BITMAP new_bitmap = RenderPageWithFlags(page, saved_form_handle_, 0); const char last_md5[] = "4b5b00f824620f8c9b8801ebb98e1cdd"; CompareBitmap(new_bitmap, 612, 792, last_md5); FPDFBitmap_Destroy(new_bitmap); EXPECT_TRUE(FPDFPage_GenerateContent(page)); // Now save the result, closing the page and document - EXPECT_TRUE(FPDF_SaveAsCopy(m_SavedDocument, this, 0)); + EXPECT_TRUE(FPDF_SaveAsCopy(saved_document_, this, 0)); CloseSavedPage(page); CloseSavedDocument(); diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index b434353bd9..d7f4376b24 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -49,17 +49,8 @@ int GetBitmapBytesPerPixel(FPDF_BITMAP bitmap) { } // namespace EmbedderTest::EmbedderTest() - : default_delegate_(new EmbedderTest::Delegate()), - document_(nullptr), - form_handle_(nullptr), - avail_(nullptr), - external_isolate_(nullptr), - loader_(nullptr), - file_length_(0), - file_contents_(nullptr) { - memset(&file_access_, 0, sizeof(file_access_)); - delegate_ = default_delegate_.get(); - + : default_delegate_(pdfium::MakeUnique()), + delegate_(default_delegate_.get()) { FPDF_FILEWRITE::version = 1; FPDF_FILEWRITE::WriteBlock = WriteBlockCallback; } @@ -80,7 +71,7 @@ void EmbedderTest::SetUp() { info->FSDK_UnSupport_Handler = UnsupportedHandlerTrampoline; FSDK_SetUnSpObjProcessHandler(info); - m_SavedDocument = nullptr; + saved_document_ = nullptr; } void EmbedderTest::TearDown() { @@ -129,9 +120,12 @@ bool EmbedderTest::OpenDocumentWithOptions(const std::string& filename, EXPECT_TRUE(!loader_); loader_ = new TestLoader(file_contents_.get(), file_length_); + + memset(&file_access_, 0, sizeof(file_access_)); file_access_.m_FileLen = static_cast(file_length_); file_access_.m_GetBlock = TestLoader::GetBlock; file_access_.m_Param = loader_; + fake_file_access_ = pdfium::MakeUnique(&file_access_); return OpenDocumentHelper(password, must_linearize, fake_file_access_.get(), &document_, &avail_, &form_handle_); @@ -301,43 +295,43 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) { FPDF_DOCUMENT EmbedderTest::OpenSavedDocument(const char* password) { memset(&saved_file_access_, 0, sizeof(saved_file_access_)); - saved_file_access_.m_FileLen = m_String.size(); + saved_file_access_.m_FileLen = data_string_.size(); saved_file_access_.m_GetBlock = GetBlockFromString; - saved_file_access_.m_Param = &m_String; + saved_file_access_.m_Param = &data_string_; saved_fake_file_access_ = pdfium::MakeUnique(&saved_file_access_); EXPECT_TRUE(OpenDocumentHelper(password, false, saved_fake_file_access_.get(), - &m_SavedDocument, &m_SavedAvail, - &m_SavedForm)); - return m_SavedDocument; + &saved_document_, &saved_avail_, + &saved_form_handle_)); + return saved_document_; } void EmbedderTest::CloseSavedDocument() { - ASSERT(m_SavedDocument); + ASSERT(saved_document_); - FPDFDOC_ExitFormFillEnvironment(m_SavedForm); - FPDF_CloseDocument(m_SavedDocument); - FPDFAvail_Destroy(m_SavedAvail); + FPDFDOC_ExitFormFillEnvironment(saved_form_handle_); + FPDF_CloseDocument(saved_document_); + FPDFAvail_Destroy(saved_avail_); - m_SavedForm = nullptr; - m_SavedDocument = nullptr; - m_SavedAvail = nullptr; + saved_form_handle_ = nullptr; + saved_document_ = nullptr; + saved_avail_ = nullptr; } FPDF_PAGE EmbedderTest::LoadSavedPage(int page_number) { - ASSERT(m_SavedDocument); + ASSERT(saved_document_); - EXPECT_LT(page_number, FPDF_GetPageCount(m_SavedDocument)); - FPDF_PAGE page = FPDF_LoadPage(m_SavedDocument, page_number); + EXPECT_LT(page_number, FPDF_GetPageCount(saved_document_)); + FPDF_PAGE page = FPDF_LoadPage(saved_document_, page_number); ASSERT(page); return page; } FPDF_BITMAP EmbedderTest::RenderSavedPage(FPDF_PAGE page) { - return RenderPageWithFlags(page, m_SavedForm, 0); + return RenderPageWithFlags(page, saved_form_handle_, 0); } void EmbedderTest::CloseSavedPage(FPDF_PAGE page) { @@ -349,10 +343,11 @@ void EmbedderTest::VerifySavedRendering(FPDF_PAGE page, int width, int height, const char* md5) { - ASSERT(m_SavedDocument); + ASSERT(saved_document_); ASSERT(page); - FPDF_BITMAP new_bitmap = RenderPageWithFlags(page, m_SavedForm, FPDF_ANNOT); + FPDF_BITMAP new_bitmap = + RenderPageWithFlags(page, saved_form_handle_, FPDF_ANNOT); CompareBitmap(new_bitmap, width, height, md5); FPDFBitmap_Destroy(new_bitmap); } @@ -479,7 +474,7 @@ int EmbedderTest::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* data, unsigned long size) { EmbedderTest* pThis = static_cast(pFileWrite); - pThis->m_String.append(static_cast(data), size); + pThis->data_string_.append(static_cast(data), size); return 1; } diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 98432e3e54..b36ac06a89 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -146,8 +146,8 @@ class EmbedderTest : public ::testing::Test, int expected_height, const char* expected_md5sum); - void ClearString() { m_String.clear(); } - const std::string& GetString() const { return m_String; } + void ClearString() { data_string_.clear(); } + const std::string& GetString() const { return data_string_; } static int GetBlockFromString(void* param, unsigned long pos, @@ -167,25 +167,28 @@ class EmbedderTest : public ::testing::Test, void SetWholeFileAvailable(); - Delegate* delegate_; std::unique_ptr default_delegate_; - FPDF_DOCUMENT document_; - FPDF_FORMHANDLE form_handle_; - FPDF_AVAIL avail_; - FPDF_FILEACCESS file_access_; // must outlive avail_. - void* external_isolate_; - TestLoader* loader_; - size_t file_length_; + Delegate* delegate_; + + FPDF_DOCUMENT document_ = nullptr; + FPDF_FORMHANDLE form_handle_ = nullptr; + FPDF_AVAIL avail_ = nullptr; + FPDF_FILEACCESS file_access_; // must outlive |avail_|. + std::unique_ptr fake_file_access_; // must outlive |avail_|. + + void* external_isolate_ = nullptr; + TestLoader* loader_ = nullptr; + size_t file_length_ = 0; std::unique_ptr file_contents_; std::map page_map_; std::map page_reverse_map_; - FPDF_DOCUMENT m_SavedDocument; - FPDF_FORMHANDLE m_SavedForm; - FPDF_AVAIL m_SavedAvail; - FPDF_FILEACCESS saved_file_access_; // must outlive m_SavedAvail. - std::unique_ptr fake_file_access_; // must outlive avail_. - std::unique_ptr - saved_fake_file_access_; // must outlive m_SavedAvail. + + FPDF_DOCUMENT saved_document_ = nullptr; + FPDF_FORMHANDLE saved_form_handle_ = nullptr; + FPDF_AVAIL saved_avail_ = nullptr; + FPDF_FILEACCESS saved_file_access_; // must outlive |saved_avail_|. + // must outlive |saved_avail_|. + std::unique_ptr saved_fake_file_access_; private: static void UnsupportedHandlerTrampoline(UNSUPPORT_INFO*, int type); @@ -205,7 +208,7 @@ class EmbedderTest : public ::testing::Test, const void* data, unsigned long size); - std::string m_String; + std::string data_string_; }; #endif // TESTING_EMBEDDER_TEST_H_ -- cgit v1.2.3