summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-28 21:00:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-28 21:00:35 +0000
commitcbf76e656042e3d9778ccc114983ab6a3c19ff92 (patch)
tree793bacffd8e8f052ad17a25461c22dfa8479217e /fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp
parent53a8093c6ef694ec520fe0b087fbac86af97f5e8 (diff)
downloadpdfium-cbf76e656042e3d9778ccc114983ab6a3c19ff92.tar.xz
Rename CBA_AnnotIterator to CPDFSDK_AnnotIteratorchromium/3383
This CL renames CBA_AnnotIterator to CPDFSDK_AnnotIterator. This iterator does not seem to be restricted to just BAAnnot entries, so rename to the more general name. Change-Id: I735dc37cd5417a2b544882db515dbef4d4dbae67 Reviewed-on: https://pdfium-review.googlesource.com/29430 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp b/fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp
new file mode 100644
index 0000000000..879a365ae8
--- /dev/null
+++ b/fpdfsdk/cpdfsdk_annotiterator_embeddertest.cpp
@@ -0,0 +1,126 @@
+// 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/cpdfsdk_annot.h"
+#include "fpdfsdk/cpdfsdk_annotiterator.h"
+#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
+#include "fpdfsdk/cpdfsdk_helpers.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 CFX_FloatRect& actual, const CFX_FloatRect& 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 CPDFSDK_AnnotIteratorTest : public EmbedderTest {};
+
+TEST_F(CPDFSDK_AnnotIteratorTest, CPDFSDK_AnnotIterator) {
+ EXPECT_TRUE(OpenDocument("annotiter.pdf"));
+ FPDF_PAGE page0 = LoadPage(0);
+ FPDF_PAGE page1 = LoadPage(1);
+ FPDF_PAGE page2 = LoadPage(2);
+ ASSERT_TRUE(page0);
+ ASSERT_TRUE(page1);
+ ASSERT_TRUE(page2);
+
+ CFX_FloatRect LeftBottom(200, 200, 220, 220);
+ CFX_FloatRect RightBottom(400, 201, 420, 221);
+ CFX_FloatRect LeftTop(201, 400, 221, 420);
+ CFX_FloatRect RightTop(401, 401, 421, 421);
+
+ CPDFSDK_FormFillEnvironment* pFormFillEnv =
+ static_cast<CPDFSDK_FormFillEnvironment*>(form_handle());
+
+ {
+ // Page 0 specifies "row order".
+ CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(0),
+ CPDF_Annot::Subtype::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"
+ CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(1),
+ CPDF_Annot::Subtype::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"
+ CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(2),
+ CPDF_Annot::Subtype::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);
+ }
+ UnloadPage(page2);
+ UnloadPage(page1);
+ UnloadPage(page0);
+}