summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-29 16:26:27 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-29 16:26:27 -0800
commitfe351dbc18e419b0ed9fbe34f2d1fb155b4f7bf1 (patch)
treeac7136643eb602f6fec582b4c3ef71694682730e /fpdfsdk/src
parent9b76113ae4567eb998618d049afde26d3f0175d5 (diff)
downloadpdfium-fe351dbc18e419b0ed9fbe34f2d1fb155b4f7bf1.tar.xz
Merge to XFA: Add tests for CBA_AnnotIterator.
Original Review URL: https://codereview.chromium.org/1652533002 . (cherry picked from commit 1bce5f62f3292a6baf35491bf4c9b4fde2fb73e3) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1652543003 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp17
-rw-r--r--fpdfsdk/src/fsdk_baseform_embeddertest.cpp115
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp7
3 files changed, 128 insertions, 11 deletions
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index 49dfd6c113..5825456b19 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -20,13 +20,8 @@
namespace {
-CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) {
- CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
- return pEnv ? pEnv->GetSDKDocument() : nullptr;
-}
-
CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr;
}
@@ -36,7 +31,7 @@ CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
if (!pPage)
return nullptr;
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr;
}
@@ -285,7 +280,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
}
DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
if (!pSDKDoc)
return FALSE;
@@ -681,20 +676,20 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
}
DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
pSDKDoc->ProcJavascriptFun();
}
DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
pSDKDoc->ProcOpenAction();
}
DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
int aaType) {
- CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
+ CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle);
if (!pSDKDoc)
return;
diff --git a/fpdfsdk/src/fsdk_baseform_embeddertest.cpp b/fpdfsdk/src/fsdk_baseform_embeddertest.cpp
new file mode 100644
index 0000000000..109b22f3b5
--- /dev/null
+++ b/fpdfsdk/src/fsdk_baseform_embeddertest.cpp
@@ -0,0 +1,115 @@
+// 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 "fpdfsdk/include/fsdk_baseform.h"
+#include "fpdfsdk/include/fsdk_define.h"
+#include "fpdfsdk/include/fsdk_mgr.h"
+#include "testing/embedder_test.h"
+#include "testing/embedder_test_mock_delegate.h"
+#include "testing/embedder_test_timer_handling_delegate.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+void CheckRect(const CPDF_Rect& actual, const CPDF_Rect& expected) {
+ EXPECT_EQ(expected.left, actual.left);
+ EXPECT_EQ(expected.bottom, actual.bottom);
+ EXPECT_EQ(expected.right, actual.right);
+ EXPECT_EQ(expected.top, actual.top);
+}
+
+} // namespace
+
+class FSDKBaseFormEmbeddertest : public EmbedderTest {};
+
+TEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) {
+ EXPECT_TRUE(OpenDocument("annotiter.pdf"));
+ EXPECT_TRUE(LoadPage(0));
+ EXPECT_TRUE(LoadPage(1));
+ EXPECT_TRUE(LoadPage(2));
+
+ CPDF_Rect LeftBottom(200, 200, 220, 220);
+ CPDF_Rect RightBottom(400, 201, 420, 221);
+ CPDF_Rect LeftTop(201, 400, 221, 420);
+ CPDF_Rect RightTop(401, 401, 421, 421);
+
+ CPDFSDK_Document* pSDKDoc =
+ CPDFSDK_Document::FromFPDFFormHandle(form_handle());
+ {
+ // Page 0 specifies "row order".
+ CBA_AnnotIterator iter(pSDKDoc->GetPageView(0), "Widget", "");
+ CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot();
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ EXPECT_EQ(iter.GetFirstAnnot(), pAnnot);
+
+ pAnnot = iter.GetLastAnnot();
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ EXPECT_EQ(iter.GetLastAnnot(), pAnnot);
+ }
+ {
+ // Page 1 specifies "column order"
+ CBA_AnnotIterator iter(pSDKDoc->GetPageView(1), "Widget", "");
+ CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot();
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ EXPECT_EQ(iter.GetFirstAnnot(), pAnnot);
+
+ pAnnot = iter.GetLastAnnot();
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ EXPECT_EQ(iter.GetLastAnnot(), pAnnot);
+ }
+ {
+ // Page 2 specifies "struct order"
+ CBA_AnnotIterator iter(pSDKDoc->GetPageView(2), "Widget", "");
+ CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot();
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetNextAnnot(pAnnot);
+ EXPECT_EQ(iter.GetFirstAnnot(), pAnnot);
+
+ pAnnot = iter.GetLastAnnot();
+ CheckRect(pAnnot->GetRect(), RightBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), RightTop);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ CheckRect(pAnnot->GetRect(), LeftBottom);
+ pAnnot = iter.GetPrevAnnot(pAnnot);
+ EXPECT_EQ(iter.GetLastAnnot(), pAnnot);
+ }
+}
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index e9de9e4000..76e0d2de20 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -390,6 +390,13 @@ CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() {
return m_pIFormFiller.get();
}
+// static
+CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle(
+ FPDF_FORMHANDLE hHandle) {
+ CPDFDoc_Environment* pEnv = static_cast<CPDFDoc_Environment*>(hHandle);
+ return pEnv ? pEnv->GetSDKDocument() : nullptr;
+}
+
CPDFSDK_Document::CPDFSDK_Document(UnderlyingDocumentType* pDoc,
CPDFDoc_Environment* pEnv)
: m_pDoc(pDoc),