Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Unified Diff: testing/embedder_test.cpp

Issue 1546063002: Add tests to exercise FPDF_SaveAsCopy(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« fpdfsdk/src/fpdfsave_embeddertest.cpp ('K') | « testing/embedder_test.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/embedder_test.cpp
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index d4ce7eba5a511f2c1c0b499c1ebe1f97aef98343..6a80bf4df1464c4f9ecffa270cb85e2372c7894f 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -59,6 +59,91 @@ EmbedderTest::EmbedderTest()
EmbedderTest::~EmbedderTest() {}
+// static
+bool EmbedderTest::LoadDocument(const char* data,
+ size_t data_size,
+ bool must_linearize,
+ TestLoader* loader,
+ EmbedderTest* embedder_test,
+ LoadDocumentData* out_data) {
+ out_data->file_access->m_FileLen = static_cast<unsigned long>(data_size);
+ out_data->file_access->m_GetBlock = TestLoader::GetBlock;
+ out_data->file_access->m_Param = loader;
+
+ out_data->file_avail->version = 1;
+ out_data->file_avail->IsDataAvail = Is_Data_Avail;
+
+ out_data->hints->version = 1;
+ out_data->hints->AddSegment = Add_Segment;
+
+ *out_data->avail =
+ FPDFAvail_Create(out_data->file_avail, out_data->file_access);
+
+ if (FPDFAvail_IsLinearized(*out_data->avail) == PDF_LINEARIZED) {
+ *out_data->document = FPDFAvail_GetDocument(*out_data->avail, nullptr);
+ if (!*out_data->document) {
+ return false;
+ }
+ int32_t nRet = PDF_DATA_NOTAVAIL;
+ while (nRet == PDF_DATA_NOTAVAIL) {
+ nRet = FPDFAvail_IsDocAvail(*out_data->avail, out_data->hints);
+ }
+ if (nRet == PDF_DATA_ERROR) {
+ return false;
+ }
+ nRet = FPDFAvail_IsFormAvail(*out_data->avail, out_data->hints);
+ if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
+ return false;
+ }
+ int page_count = FPDF_GetPageCount(*out_data->document);
+ for (int i = 0; i < page_count; ++i) {
+ nRet = PDF_DATA_NOTAVAIL;
+ while (nRet == PDF_DATA_NOTAVAIL) {
+ nRet = FPDFAvail_IsPageAvail(*out_data->avail, i, out_data->hints);
Wei Li 2016/01/04 19:01:13 I know this is from the original code, but worth c
Lei Zhang 2016/01/07 02:50:58 Maybe. If you can create a test case that does tha
+ }
+ if (nRet == PDF_DATA_ERROR) {
+ return false;
+ }
+ }
+ } else {
+ if (must_linearize) {
+ return false;
+ }
+ *out_data->document =
+ FPDF_LoadCustomDocument(out_data->file_access, nullptr);
+ if (!*out_data->document) {
+ return false;
+ }
+ }
+
+ (void)FPDF_GetDocPermissions(*out_data->document);
+
+ if (embedder_test) {
+ IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(embedder_test);
+ memset(platform, 0, sizeof(IPDF_JSPLATFORM));
+ platform->version = 2;
+ platform->app_alert = AlertTrampoline;
+
+ FPDF_FORMFILLINFO* formfillinfo =
+ static_cast<FPDF_FORMFILLINFO*>(embedder_test);
+ memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
+ formfillinfo->version = 1;
+ formfillinfo->FFI_SetTimer = SetTimerTrampoline;
+ formfillinfo->FFI_KillTimer = KillTimerTrampoline;
+ formfillinfo->FFI_GetPage = GetPageTrampoline;
+ formfillinfo->m_pJsPlatform = platform;
+
+ *out_data->form_handle =
+ FPDFDOC_InitFormFillEnvironment(*out_data->document, formfillinfo);
+ FPDF_SetFormFieldHighlightColor(*out_data->form_handle, 0, 0xFFE4DD);
+ FPDF_SetFormFieldHighlightAlpha(*out_data->form_handle, 100);
+ } else {
+ *out_data->form_handle = nullptr;
+ }
+
+ return true;
+}
+
void EmbedderTest::SetUp() {
FPDF_LIBRARY_CONFIG config;
config.version = 2;
@@ -102,74 +187,15 @@ bool EmbedderTest::OpenDocument(const std::string& filename,
return false;
loader_ = new TestLoader(file_contents_, file_length_);
- file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
- file_access_.m_GetBlock = TestLoader::GetBlock;
- file_access_.m_Param = loader_;
-
- file_avail_.version = 1;
- file_avail_.IsDataAvail = Is_Data_Avail;
-
- hints_.version = 1;
- hints_.AddSegment = Add_Segment;
-
- avail_ = FPDFAvail_Create(&file_avail_, &file_access_);
-
- if (FPDFAvail_IsLinearized(avail_) == PDF_LINEARIZED) {
- document_ = FPDFAvail_GetDocument(avail_, nullptr);
- if (!document_) {
- return false;
- }
- int32_t nRet = PDF_DATA_NOTAVAIL;
- while (nRet == PDF_DATA_NOTAVAIL) {
- nRet = FPDFAvail_IsDocAvail(avail_, &hints_);
- }
- if (nRet == PDF_DATA_ERROR) {
- return false;
- }
- nRet = FPDFAvail_IsFormAvail(avail_, &hints_);
- if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
- return false;
- }
- int page_count = FPDF_GetPageCount(document_);
- for (int i = 0; i < page_count; ++i) {
- nRet = PDF_DATA_NOTAVAIL;
- while (nRet == PDF_DATA_NOTAVAIL) {
- nRet = FPDFAvail_IsPageAvail(avail_, i, &hints_);
- }
- if (nRet == PDF_DATA_ERROR) {
- return false;
- }
- }
- } else {
- if (must_linearize) {
- return false;
- }
- document_ = FPDF_LoadCustomDocument(&file_access_, nullptr);
- if (!document_) {
- return false;
- }
- }
-
- (void)FPDF_GetDocPermissions(document_);
-
- IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
- memset(platform, 0, sizeof(IPDF_JSPLATFORM));
- platform->version = 2;
- platform->app_alert = AlertTrampoline;
-
- FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);
- memset(formfillinfo, 0, sizeof(FPDF_FORMFILLINFO));
- formfillinfo->version = 1;
- formfillinfo->FFI_SetTimer = SetTimerTrampoline;
- formfillinfo->FFI_KillTimer = KillTimerTrampoline;
- formfillinfo->FFI_GetPage = GetPageTrampoline;
- formfillinfo->m_pJsPlatform = platform;
-
- form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
- FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
- FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
-
- return true;
+ LoadDocumentData load_data;
+ load_data.document = &document_;
+ load_data.file_access = &file_access_;
+ load_data.file_avail = &file_avail_;
+ load_data.avail = &avail_;
+ load_data.hints = &hints_;
+ load_data.form_handle = &form_handle_;
+ return LoadDocument(file_contents_, file_length_, must_linearize, loader_,
+ this, &load_data);
}
void EmbedderTest::DoOpenActions() {
« fpdfsdk/src/fpdfsave_embeddertest.cpp ('K') | « testing/embedder_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698