From 75c81710b1d193b59d5b38142bb926959346f7ea Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 8 Feb 2018 17:22:39 +0000 Subject: Do more page load/unload checks in EmbedderTest. - Keep track of pages in a single map when calling LoadPage(). It is simpler and performance is not crucial as the number of loaded pages is usually very small. - Verify UnloadPage() is only called for loaded pages. - Verify there are no loaded pages in TearDown(). - Verify RenderLoadedPage methods are only rendering loaded pages. - Fix pages that are using FPDF_LoadPage() and FPDF_ClosePage() when they should be using LoadPage() and UnloadPage(). - Disallow calling LoadPage() for the same page number repeatedly. No caller does this and it makes verification in UnloadPage() harder. Change-Id: I58878ea8ade21dde28f1bbebd3a3304ce677561d Reviewed-on: https://pdfium-review.googlesource.com/25550 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- testing/embedder_test.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'testing/embedder_test.h') diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 18b16b7066..c8fce4825f 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -106,11 +106,17 @@ class EmbedderTest : public ::testing::Test, int GetFirstPageNum(); int GetPageCount(); - // Load a specific page of the open document. + // Load a specific page of the open document with a given non-negative + // |page_number|. On success, fire form events for the page and return a page + // handle. On failure, return nullptr. + // The caller does not own the returned page handle, but must call + // UnloadPage() on it when done. + // The caller cannot call this for a |page_number| if it already obtained and + // holds the page handle for that page. FPDF_PAGE LoadPage(int page_number); - // Release the resources obtained from LoadPage(). Further use of |page| - // is prohibited after this call is made. + // Fire form unload events and release the resources for a |page| obtained + // from LoadPage(). Further use of |page| is prohibited after calling this. void UnloadPage(FPDF_PAGE page); // Convert a loaded page into a bitmap. @@ -215,7 +221,6 @@ class EmbedderTest : public ::testing::Test, size_t file_length_ = 0; std::unique_ptr file_contents_; std::map page_map_; - std::map page_reverse_map_; FPDF_DOCUMENT saved_document_ = nullptr; FPDF_FORMHANDLE saved_form_handle_ = nullptr; @@ -242,6 +247,10 @@ class EmbedderTest : public ::testing::Test, const void* data, unsigned long size); + // Find |page| inside |page_map_| and return the associated page number, or -1 + // if |page| cannot be found. + int GetPageNumberForLoadedPage(FPDF_PAGE page) const; + std::string data_string_; }; -- cgit v1.2.3