14d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// Copyright 2016 PDFium Authors. All rights reserved. 24d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// Use of this source code is governed by a BSD-style license that can be 34d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann// found in the LICENSE file. 44d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 54d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "fpdfsdk/cba_annotiterator.h" 64d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "fpdfsdk/cpdfsdk_annot.h" 74d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "fpdfsdk/cpdfsdk_formfillenvironment.h" 84d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "fpdfsdk/fsdk_define.h" 94d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "testing/embedder_test.h" 104d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "testing/embedder_test_mock_delegate.h" 114d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "testing/embedder_test_timer_handling_delegate.h" 124d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "testing/gmock/include/gmock/gmock.h" 134d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "testing/gtest/include/gtest/gtest.h" 144d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 154d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannnamespace { 164d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 174d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannvoid CheckRect(const CFX_FloatRect& actual, const CFX_FloatRect& expected) { 184d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(expected.left, actual.left); 194d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(expected.bottom, actual.bottom); 204d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(expected.right, actual.right); 214d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(expected.top, actual.top); 224d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann} 234d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 244d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann} // namespace 254d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 264d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannclass FSDKBaseFormEmbeddertest : public EmbedderTest {}; 274d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 284d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. MoltmannTEST_F(FSDKBaseFormEmbeddertest, CBA_AnnotIterator) { 294d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_TRUE(OpenDocument("annotiter.pdf")); 304d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann FPDF_PAGE page0 = LoadPage(0); 314d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann FPDF_PAGE page1 = LoadPage(1); 324d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann FPDF_PAGE page2 = LoadPage(2); 334d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_TRUE(page0); 344d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_TRUE(page1); 354d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_TRUE(page2); 364d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 374d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CFX_FloatRect LeftBottom(200, 200, 220, 220); 384d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CFX_FloatRect RightBottom(400, 201, 420, 221); 394d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CFX_FloatRect LeftTop(201, 400, 221, 420); 404d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CFX_FloatRect RightTop(401, 401, 421, 421); 414d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 424d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDFSDK_FormFillEnvironment* pFormFillEnv = 434d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann static_cast<CPDFSDK_FormFillEnvironment*>(form_handle()); 444d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 454d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann { 464d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann // Page 0 specifies "row order". 474d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CBA_AnnotIterator iter(pFormFillEnv->GetPageView(0), 484d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDF_Annot::Subtype::WIDGET); 494d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); 504d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 514d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 524d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 534d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 544d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 554d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 564d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 574d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 584d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); 594d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 604d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetLastAnnot(); 614d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 624d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 634d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 644d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 654d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 664d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 674d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 684d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 694d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetLastAnnot(), pAnnot); 704d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann } 714d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann { 724d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann // Page 1 specifies "column order" 734d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CBA_AnnotIterator iter(pFormFillEnv->GetPageView(1), 744d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDF_Annot::Subtype::WIDGET); 754d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); 764d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 774d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 784d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 794d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 804d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 814d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 824d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 834d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 844d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); 854d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 864d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetLastAnnot(); 874d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 884d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 894d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 904d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 914d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 924d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 934d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 944d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 954d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetLastAnnot(), pAnnot); 964d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann } 974d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann { 984d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann // Page 2 specifies "struct order" 994d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CBA_AnnotIterator iter(pFormFillEnv->GetPageView(2), 1004d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDF_Annot::Subtype::WIDGET); 1014d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CPDFSDK_Annot* pAnnot = iter.GetFirstAnnot(); 1024d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 1034d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 1044d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 1054d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 1064d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 1074d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 1084d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 1094d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetNextAnnot(pAnnot); 1104d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetFirstAnnot(), pAnnot); 1114d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann 1124d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetLastAnnot(); 1134d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightBottom); 1144d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 1154d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftTop); 1164d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 1174d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), RightTop); 1184d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 1194d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann CheckRect(pAnnot->GetRect(), LeftBottom); 1204d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann pAnnot = iter.GetPrevAnnot(pAnnot); 1214d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann EXPECT_EQ(iter.GetLastAnnot(), pAnnot); 1224d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann } 1234d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann UnloadPage(page2); 1244d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann UnloadPage(page1); 1254d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann UnloadPage(page0); 1264d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann} 127