Add fpdf_edit basic creation embedder test. (issue 1554133003 by tsepez@chromium.org)

0 views
Skip to first unread message

tse...@chromium.org

unread,
Jan 4, 2016, 3:05:29 PM1/4/16
to the...@chromium.org, pdfium-...@googlegroups.com
Reviewers: Lei Zhang
CL: https://codereview.chromium.org/1554133003/

Message:
Lei, for review. Would like to get to a point where each of the public
header
files has an embedder test file for it.

Description:
Add fpdf_edit basic creation embedder test.

Base URL: https://pdfium.googlesource.com/pdfium.git@master

Affected files (+41, -2 lines):
M BUILD.gn
A fpdfsdk/src/fpdfedit_embeddertest.cpp
M pdfium.gyp
M testing/embedder_test.h
M testing/embedder_test.cpp


Index: BUILD.gn
diff --git a/BUILD.gn b/BUILD.gn
index
1377b68af5cd8b47635e4cd1e3b59ad750673f33..c3ac3d1809010720ff4f51c4873be2c509f37119
100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -756,6 +756,7 @@ test("pdfium_embeddertests") {
"core/src/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp",
"fpdfsdk/src/fpdf_dataavail_embeddertest.cpp",
"fpdfsdk/src/fpdfdoc_embeddertest.cpp",
+ "fpdfsdk/src/fpdfedit_embeddertest.cpp",
"fpdfsdk/src/fpdfformfill_embeddertest.cpp",
"fpdfsdk/src/fpdftext_embeddertest.cpp",
"fpdfsdk/src/fpdfview_c_api_test.c",
Index: fpdfsdk/src/fpdfedit_embeddertest.cpp
diff --git a/fpdfsdk/src/fpdfedit_embeddertest.cpp
b/fpdfsdk/src/fpdfedit_embeddertest.cpp
new file mode 100644
index
0000000000000000000000000000000000000000..3131f772a33eaaae944f41fd9e754949cb0c0ad5
--- /dev/null
+++ b/fpdfsdk/src/fpdfedit_embeddertest.cpp
@@ -0,0 +1,20 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/include/fxcrt/fx_string.h"
+#include "public/fpdf_edit.h"
+#include "public/fpdfview.h"
+#include "testing/embedder_test.h"
+#include "testing/fx_string_testhelpers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FPDFEditEmbeddertest : public EmbedderTest {};
+
+TEST_F(FPDFEditEmbeddertest, EmptyCreation) {
+ EXPECT_TRUE(CreateDocument());
+ FPDF_PAGE page = FPDFPage_New(document(), 1, 640.0, 480.0);
+ EXPECT_NE(nullptr, page);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ FPDFPage_Delete(document(), 1);
+}
Index: pdfium.gyp
diff --git a/pdfium.gyp b/pdfium.gyp
index
8401dcc5b90b6b88d35af70d0cdbed6ff2b36552..2c7ebadad9371262e33b7ee32f4a724cdb195643
100644
--- a/pdfium.gyp
+++ b/pdfium.gyp
@@ -751,6 +751,7 @@
'core/src/fpdfapi/fpdf_render/fpdf_render_pattern_embeddertest.cpp',
'fpdfsdk/src/fpdf_dataavail_embeddertest.cpp',
'fpdfsdk/src/fpdfdoc_embeddertest.cpp',
+ 'fpdfsdk/src/fpdfedit_embeddertest.cpp',
'fpdfsdk/src/fpdfformfill_embeddertest.cpp',
'fpdfsdk/src/fpdftext_embeddertest.cpp',
'fpdfsdk/src/fpdfview_c_api_test.c',
Index: testing/embedder_test.cpp
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index
33c72201a1fb70938c6669bf691d95782e00c4fb..0e650ec9704409f1d86e981d2d053e48693ec842
100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -93,6 +93,15 @@ void EmbedderTest::TearDown() {
free(file_contents_);
}

+bool EmbedderTest::CreateDocument() {
+ document_ = FPDF_CreateNewDocument();
+ if (!document_)
+ return false;
+
+ SetupFormFillEnvironment();
+ return true;
+}
+
bool EmbedderTest::OpenDocument(const std::string& filename,
bool must_linearize) {
std::string file_path;
@@ -152,7 +161,11 @@ bool EmbedderTest::OpenDocument(const std::string&
filename,
}

(void)FPDF_GetDocPermissions(document_);
+ SetupFormFillEnvironment();
+ return true;
+}

+void EmbedderTest::SetupFormFillEnvironment() {
IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
memset(platform, 0, sizeof(IPDF_JSPLATFORM));
platform->version = 2;
@@ -169,8 +182,6 @@ bool EmbedderTest::OpenDocument(const std::string&
filename,
form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, formfillinfo);
FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
-
- return true;
}

void EmbedderTest::DoOpenActions() {
Index: testing/embedder_test.h
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index
a544f265432a699edfd80c1f1a7059ad861c69cf..0defb2f0796314e7124f6975793ae5e09a58cd58
100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -78,6 +78,10 @@ class EmbedderTest : public ::testing::Test,
FPDF_DOCUMENT document() { return document_; }
FPDF_FORMHANDLE form_handle() { return form_handle_; }

+ // Create an empty document, and its form fill environment. Returns true
+ // on success or false on failure.
+ virtual bool CreateDocument();
+
// Open the document specified by |filename|, and create its form fill
// environment, or return false on failure.
// The filename is relative to the test data directory where we store
all the
@@ -107,6 +111,8 @@ class EmbedderTest : public ::testing::Test,
virtual void UnloadPage(FPDF_PAGE page);

protected:
+ void SetupFormFillEnvironment();
+
Delegate* delegate_;
std::unique_ptr<Delegate> default_delegate_;
FPDF_DOCUMENT document_;


the...@chromium.org

unread,
Jan 5, 2016, 9:05:06 PM1/5/16
to tse...@chromium.org, pdfium-...@googlegroups.com
lgtm




https://codereview.chromium.org/1554133003/diff/1/fpdfsdk/src/fpdfedit_embeddertest.cpp
File fpdfsdk/src/fpdfedit_embeddertest.cpp (right):

https://codereview.chromium.org/1554133003/diff/1/fpdfsdk/src/fpdfedit_embeddertest.cpp#newcode5
fpdfsdk/src/fpdfedit_embeddertest.cpp:5: #include
"core/include/fxcrt/fx_string.h"
Again, not needed. Also fx_string_testhelpers.h.

https://codereview.chromium.org/1554133003/diff/1/testing/embedder_test.h
File testing/embedder_test.h (right):

https://codereview.chromium.org/1554133003/diff/1/testing/embedder_test.h#newcode83
testing/embedder_test.h:83: virtual bool CreateDocument();
CreateEmptyDocument() ?

https://codereview.chromium.org/1554133003/

tsepez@chromium.org via codereview.chromium.org

unread,
Jan 6, 2016, 12:55:49 PM1/6/16
to the...@chromium.org, tse...@chromium.org, pdfium-...@googlegroups.com
Committed patchset #2 (id:20001) manually as
d368261cc8d604286e29ca6358700e6bb051dcaa (presubmit successful).

https://codereview.chromium.org/1554133003/

tse...@chromium.org

unread,
Jan 6, 2016, 12:57:10 PM1/6/16
to the...@chromium.org, pdfium-...@googlegroups.com

https://codereview.chromium.org/1554133003/diff/1/fpdfsdk/src/fpdfedit_embeddertest.cpp
File fpdfsdk/src/fpdfedit_embeddertest.cpp (right):

https://codereview.chromium.org/1554133003/diff/1/fpdfsdk/src/fpdfedit_embeddertest.cpp#newcode5
fpdfsdk/src/fpdfedit_embeddertest.cpp:5: #include
"core/include/fxcrt/fx_string.h"
On 2016/01/06 02:05:06, Lei Zhang wrote:
> Again, not needed. Also fx_string_testhelpers.h.

Done.
On 2016/01/06 02:05:06, Lei Zhang wrote:
> CreateEmptyDocument() ?

Sure. Done.

https://codereview.chromium.org/1554133003/
Reply all
Reply to author
Forward
0 new messages