From e08d2b1fee0db40bac9538ca8b7be0a951675bd6 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 25 Apr 2018 18:49:32 +0000 Subject: Introduce ScopedFPDF types in public/cpp/fpdf_scopers.h Applies std::remove_ptr to the public API types so that we can deduce a correct unique ptr type no matter how that API might change away from void* usage. Creates shorter names for std::unique_ptr, ...> Change-Id: I04a0ff43cb7d5a4d3867939a53a54c9cef00db86 Reviewed-on: https://pdfium-review.googlesource.com/31292 Reviewed-by: Lei Zhang Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- testing/embedder_test.cpp | 29 ++++++++++++----------------- testing/embedder_test.h | 19 ++++++++----------- testing/libfuzzer/pdf_font_fuzzer.cc | 10 ++++------ 3 files changed, 24 insertions(+), 34 deletions(-) (limited to 'testing') diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index fd53b52fdc..03eebe3abc 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -15,6 +15,7 @@ #include #include "core/fdrm/crypto/fx_crypt.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_edit.h" #include "public/fpdf_text.h" @@ -305,13 +306,12 @@ void EmbedderTest::UnloadPage(FPDF_PAGE page) { page_map_.erase(page_number); } -std::unique_ptr EmbedderTest::RenderLoadedPage( - FPDF_PAGE page) { +ScopedFPDFBitmap EmbedderTest::RenderLoadedPage(FPDF_PAGE page) { return RenderLoadedPageWithFlags(page, 0); } -std::unique_ptr -EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, int flags) { +ScopedFPDFBitmap EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, + int flags) { if (GetPageNumberForLoadedPage(page) < 0) { NOTREACHED(); return nullptr; @@ -319,14 +319,12 @@ EmbedderTest::RenderLoadedPageWithFlags(FPDF_PAGE page, int flags) { return RenderPageWithFlags(page, form_handle_, flags); } -std::unique_ptr EmbedderTest::RenderSavedPage( - FPDF_PAGE page) { +ScopedFPDFBitmap EmbedderTest::RenderSavedPage(FPDF_PAGE page) { return RenderSavedPageWithFlags(page, 0); } -std::unique_ptr EmbedderTest::RenderSavedPageWithFlags( - FPDF_PAGE page, - int flags) { +ScopedFPDFBitmap EmbedderTest::RenderSavedPageWithFlags(FPDF_PAGE page, + int flags) { if (GetPageNumberForSavedPage(page) < 0) { NOTREACHED(); return nullptr; @@ -335,15 +333,13 @@ std::unique_ptr EmbedderTest::RenderSavedPageWithFlags( } // static -std::unique_ptr EmbedderTest::RenderPageWithFlags( - FPDF_PAGE page, - FPDF_FORMHANDLE handle, - int flags) { +ScopedFPDFBitmap EmbedderTest::RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags) { int width = static_cast(FPDF_GetPageWidth(page)); int height = static_cast(FPDF_GetPageHeight(page)); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; - std::unique_ptr bitmap( - FPDFBitmap_Create(width, height, alpha)); + ScopedFPDFBitmap bitmap(FPDFBitmap_Create(width, height, alpha)); FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap.get(), 0, 0, width, height, fill_color); FPDF_RenderPageBitmap(bitmap.get(), page, 0, 0, width, height, 0, flags); @@ -417,8 +413,7 @@ void EmbedderTest::VerifySavedRendering(FPDF_PAGE page, ASSERT(saved_document_); ASSERT(page); - std::unique_ptr bitmap = - RenderSavedPageWithFlags(page, FPDF_ANNOT); + ScopedFPDFBitmap bitmap = RenderSavedPageWithFlags(page, FPDF_ANNOT); CompareBitmap(bitmap.get(), width, height, md5); } diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 4923180c4a..8156dd2353 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -9,7 +9,7 @@ #include #include -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_dataavail.h" #include "public/fpdf_ext.h" #include "public/fpdf_formfill.h" @@ -126,26 +126,22 @@ class EmbedderTest : public ::testing::Test, void UnloadPage(FPDF_PAGE page); // RenderLoadedPageWithFlags() with no flags. - std::unique_ptr RenderLoadedPage(FPDF_PAGE page); + ScopedFPDFBitmap RenderLoadedPage(FPDF_PAGE page); // Convert |page| loaded via LoadPage() into a bitmap with the specified page // rendering |flags|. // // See public/fpdfview.h for a list of page rendering flags. - std::unique_ptr RenderLoadedPageWithFlags( - FPDF_PAGE page, - int flags); + ScopedFPDFBitmap RenderLoadedPageWithFlags(FPDF_PAGE page, int flags); // RenderSavedPageWithFlags() with no flags. - std::unique_ptr RenderSavedPage(FPDF_PAGE page); + ScopedFPDFBitmap RenderSavedPage(FPDF_PAGE page); // Convert |page| loaded via LoadSavedPage() into a bitmap with the specified // page rendering |flags|. // // See public/fpdfview.h for a list of page rendering flags. - std::unique_ptr RenderSavedPageWithFlags( - FPDF_PAGE page, - int flags); + ScopedFPDFBitmap RenderSavedPageWithFlags(FPDF_PAGE page, int flags); // Convert |page| into a bitmap with the specified page rendering |flags|. // The form handle associated with |page| should be passed in via |handle|. @@ -153,8 +149,9 @@ class EmbedderTest : public ::testing::Test, // // See public/fpdfview.h for a list of page rendering flags. // If none of the above Render methods are appropriate, then use this one. - static std::unique_ptr - RenderPageWithFlags(FPDF_PAGE page, FPDF_FORMHANDLE handle, int flags); + static ScopedFPDFBitmap RenderPageWithFlags(FPDF_PAGE page, + FPDF_FORMHANDLE handle, + int flags); protected: using PageNumberToHandleMap = std::map; diff --git a/testing/libfuzzer/pdf_font_fuzzer.cc b/testing/libfuzzer/pdf_font_fuzzer.cc index aed66613fa..7c596307f0 100644 --- a/testing/libfuzzer/pdf_font_fuzzer.cc +++ b/testing/libfuzzer/pdf_font_fuzzer.cc @@ -5,7 +5,7 @@ #include #include -#include "public/cpp/fpdf_deleters.h" +#include "public/cpp/fpdf_scopers.h" #include "public/fpdf_edit.h" #include "public/fpdfview.h" @@ -13,15 +13,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (size < 2) return 0; - std::unique_ptr doc(FPDF_CreateNewDocument()); - std::unique_ptr page( - FPDFPage_New(doc.get(), 0, 612, 792)); + ScopedFPDFDocument doc(FPDF_CreateNewDocument()); + ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 612, 792)); int font_type = data[0]; FPDF_BOOL cid = data[1]; data += 2; size -= 2; - std::unique_ptr font( - FPDFText_LoadFont(doc.get(), data, size, font_type, cid)); + ScopedFPDFFont font(FPDFText_LoadFont(doc.get(), data, size, font_type, cid)); if (!font) return 0; -- cgit v1.2.3