Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 1 | // Copyright (c) 2015 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef TESTING_EMBEDDER_TEST_H_ |
| 6 | #define TESTING_EMBEDDER_TEST_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "../core/include/fxcrt/fx_system.h" |
| 11 | #include "../fpdfsdk/include/fpdf_dataavail.h" |
| 12 | #include "../fpdfsdk/include/fpdfformfill.h" |
| 13 | #include "../fpdfsdk/include/fpdfview.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | #include "v8/include/v8.h" |
| 16 | |
| 17 | class TestLoader; |
| 18 | |
| 19 | // This class is used to load a PDF document, and then run programatic |
| 20 | // API tests against it. |
| 21 | class EmbedderTest : public ::testing::Test { |
| 22 | public: |
| 23 | EmbedderTest() : |
| 24 | document_(nullptr), |
| 25 | avail_(nullptr), |
| 26 | loader_(nullptr), |
| 27 | file_length_(0), |
| 28 | file_contents_(nullptr) { |
| 29 | memset(&hints_, 0, sizeof(hints_)); |
| 30 | memset(&file_access_, 0, sizeof(file_access_)); |
| 31 | memset(&file_avail_, 0, sizeof(file_avail_)); |
| 32 | } |
| 33 | |
| 34 | virtual ~EmbedderTest() { } |
| 35 | |
| 36 | void SetUp() override; |
| 37 | void TearDown() override; |
| 38 | |
| 39 | FPDF_DOCUMENT document() { return document_; } |
| 40 | |
| 41 | // Open the document specified by |filename|, or return false on failure. |
| 42 | virtual bool OpenDocument(const std::string& filename); |
| 43 | |
| 44 | // Create and return a handle to the form fill module for use with the |
| 45 | // FORM_ family of functions from fpdfformfill.h, or return NULL on failure. |
| 46 | virtual FPDF_FORMHANDLE SetFormFillEnvironment(); |
| 47 | |
| 48 | // Release the resources obtained from SetFormFillEnvironment(). |
| 49 | virtual void ClearFormFillEnvironment(FPDF_FORMHANDLE form); |
| 50 | |
| 51 | // Perform JavaScript actions that are to run at document open time. |
| 52 | virtual void DoOpenActions(FPDF_FORMHANDLE form); |
| 53 | |
| 54 | // Determine the page numbers present in the document. |
| 55 | virtual int GetFirstPageNum(); |
| 56 | virtual int GetPageCount(); |
| 57 | |
| 58 | // Load a specific page of the open document. |
| 59 | virtual FPDF_PAGE LoadPage(int page_number, FPDF_FORMHANDLE form); |
| 60 | |
| 61 | // Convert a loaded page into a bitmap. |
| 62 | virtual FPDF_BITMAP RenderPage(FPDF_PAGE page, FPDF_FORMHANDLE form); |
| 63 | |
| 64 | // Relese the resources obtained from LoadPage(). Further use of |page| |
| 65 | // is prohibited after this call is made. |
| 66 | virtual void UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form); |
| 67 | |
Tom Sepez | 2255a1b | 2015-01-23 15:33:44 -0800 | [diff] [blame^] | 68 | protected: |
Tom Sepez | 96d1334 | 2015-01-16 14:59:26 -0800 | [diff] [blame] | 69 | FPDF_DOCUMENT document_; |
| 70 | FPDF_AVAIL avail_; |
| 71 | FX_DOWNLOADHINTS hints_; |
| 72 | FPDF_FILEACCESS file_access_; |
| 73 | FX_FILEAVAIL file_avail_; |
| 74 | v8::StartupData natives_; |
| 75 | v8::StartupData snapshot_; |
| 76 | TestLoader* loader_; |
| 77 | size_t file_length_; |
| 78 | char* file_contents_; |
| 79 | }; |
| 80 | |
| 81 | #endif // TESTING_EMBEDDER_TEST_H_ |
| 82 | |