Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 1 | // Copyright 2016 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 5 | #include "fpdfsdk/cpdfsdk_annot.h" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 6 | #include "fpdfsdk/cpdfsdk_annotiterator.h" |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Dan Sinclair | 00d47a6 | 2018-03-28 18:39:04 +0000 | [diff] [blame] | 8 | #include "fpdfsdk/cpdfsdk_helpers.h" |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 9 | #include "testing/embedder_test.h" |
| 10 | #include "testing/embedder_test_mock_delegate.h" |
| 11 | #include "testing/embedder_test_timer_handling_delegate.h" |
| 12 | #include "testing/gmock/include/gmock/gmock.h" |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
| 15 | namespace { |
| 16 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 17 | void CheckRect(const CFX_FloatRect& actual, const CFX_FloatRect& expected) { |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 18 | EXPECT_EQ(expected.left, actual.left); |
| 19 | EXPECT_EQ(expected.bottom, actual.bottom); |
| 20 | EXPECT_EQ(expected.right, actual.right); |
| 21 | EXPECT_EQ(expected.top, actual.top); |
| 22 | } |
| 23 | |
| 24 | } // namespace |
| 25 | |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 26 | class CPDFSDK_AnnotIteratorTest : public EmbedderTest {}; |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 27 | |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 28 | TEST_F(CPDFSDK_AnnotIteratorTest, CPDFSDK_AnnotIterator) { |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 29 | EXPECT_TRUE(OpenDocument("annotiter.pdf")); |
weili | 0dadcc6 | 2016-08-23 21:10:57 -0700 | [diff] [blame] | 30 | FPDF_PAGE page0 = LoadPage(0); |
| 31 | FPDF_PAGE page1 = LoadPage(1); |
| 32 | FPDF_PAGE page2 = LoadPage(2); |
Dan Sinclair | 7d12532 | 2018-03-28 18:49:34 +0000 | [diff] [blame] | 33 | ASSERT_TRUE(page0); |
| 34 | ASSERT_TRUE(page1); |
| 35 | ASSERT_TRUE(page2); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 36 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 37 | CFX_FloatRect LeftBottom(200, 200, 220, 220); |
| 38 | CFX_FloatRect RightBottom(400, 201, 420, 221); |
| 39 | CFX_FloatRect LeftTop(201, 400, 221, 420); |
| 40 | CFX_FloatRect RightTop(401, 401, 421, 421); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 41 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 42 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
Tom Sepez | 2563fc3 | 2018-08-01 19:13:06 +0000 | [diff] [blame] | 43 | CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 44 | |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 45 | { |
| 46 | // Page 0 specifies "row order". |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 47 | CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(0), |
| 48 | CPDF_Annot::Subtype::WIDGET); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 49 | CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); |
| 50 | CheckRect(pAnnot->GetRect(), RightTop); |
| 51 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 52 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 53 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 54 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 55 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 56 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 57 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 58 | EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); |
| 59 | |
| 60 | pAnnot = iter.GetLastAnnot(); |
| 61 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 62 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 63 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 64 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 65 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 66 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 67 | CheckRect(pAnnot->GetRect(), RightTop); |
| 68 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 69 | EXPECT_EQ(iter.GetLastAnnot(), pAnnot); |
| 70 | } |
| 71 | { |
| 72 | // Page 1 specifies "column order" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 73 | CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(1), |
| 74 | CPDF_Annot::Subtype::WIDGET); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 75 | CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); |
| 76 | CheckRect(pAnnot->GetRect(), RightTop); |
| 77 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 78 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 79 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 80 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 81 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 82 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 83 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 84 | EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); |
| 85 | |
| 86 | pAnnot = iter.GetLastAnnot(); |
| 87 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 88 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 89 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 90 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 91 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 92 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 93 | CheckRect(pAnnot->GetRect(), RightTop); |
| 94 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 95 | EXPECT_EQ(iter.GetLastAnnot(), pAnnot); |
| 96 | } |
| 97 | { |
| 98 | // Page 2 specifies "struct order" |
Dan Sinclair | cbf76e6 | 2018-03-28 21:00:35 +0000 | [diff] [blame] | 99 | CPDFSDK_AnnotIterator iter(pFormFillEnv->GetPageView(2), |
| 100 | CPDF_Annot::Subtype::WIDGET); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 101 | CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); |
| 102 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 103 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 104 | CheckRect(pAnnot->GetRect(), RightTop); |
| 105 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 106 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 107 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 108 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 109 | pAnnot = iter.GetNextAnnot(pAnnot); |
| 110 | EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); |
| 111 | |
| 112 | pAnnot = iter.GetLastAnnot(); |
| 113 | CheckRect(pAnnot->GetRect(), RightBottom); |
| 114 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 115 | CheckRect(pAnnot->GetRect(), LeftTop); |
| 116 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 117 | CheckRect(pAnnot->GetRect(), RightTop); |
| 118 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 119 | CheckRect(pAnnot->GetRect(), LeftBottom); |
| 120 | pAnnot = iter.GetPrevAnnot(pAnnot); |
| 121 | EXPECT_EQ(iter.GetLastAnnot(), pAnnot); |
| 122 | } |
weili | 0dadcc6 | 2016-08-23 21:10:57 -0700 | [diff] [blame] | 123 | UnloadPage(page2); |
| 124 | UnloadPage(page1); |
| 125 | UnloadPage(page0); |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 126 | } |