summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfannot_embeddertest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfannot_embeddertest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp
index 9d9e2d365f..85fe1326bc 100644
--- a/fpdfsdk/fpdfannot_embeddertest.cpp
+++ b/fpdfsdk/fpdfannot_embeddertest.cpp
@@ -392,3 +392,72 @@ TEST_F(FPDFAnnotEmbeddertest, ModifyRectQuadpointsWithAP) {
FPDFPage_CloseAnnot(annot);
UnloadPage(page);
}
+
+TEST_F(FPDFAnnotEmbeddertest, RemoveAnnotation) {
+ // Open a file with 3 annotations on its first page.
+ ASSERT_TRUE(OpenDocument("annotation_ink_multiple.pdf"));
+ FPDF_PAGE page = FPDF_LoadPage(document(), 0);
+ ASSERT_TRUE(page);
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
+
+ // Check that the annotations have the expected rectangle coordinates.
+ FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0);
+ FS_RECTF rect = FPDFAnnot_GetRect(annot);
+ EXPECT_NEAR(86.1971f, rect.left, 0.001f);
+ FPDFPage_CloseAnnot(annot);
+
+ annot = FPDFPage_GetAnnot(page, 1);
+ rect = FPDFAnnot_GetRect(annot);
+ EXPECT_NEAR(149.8127f, rect.left, 0.001f);
+ FPDFPage_CloseAnnot(annot);
+
+ annot = FPDFPage_GetAnnot(page, 2);
+ rect = FPDFAnnot_GetRect(annot);
+ EXPECT_NEAR(351.8204f, rect.left, 0.001f);
+ FPDFPage_CloseAnnot(annot);
+
+ // Check that nothing happens when attempting to remove an annotation with an
+ // out-of-bound index.
+ EXPECT_FALSE(FPDFPage_RemoveAnnot(page, 4));
+ EXPECT_FALSE(FPDFPage_RemoveAnnot(page, -1));
+ EXPECT_EQ(3, FPDFPage_GetAnnotCount(page));
+
+ // Remove the second annotation.
+ EXPECT_TRUE(FPDFPage_RemoveAnnot(page, 1));
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(page));
+ EXPECT_FALSE(FPDFPage_GetAnnot(page, 2));
+
+ // Save the document, closing the page and document.
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ FPDF_ClosePage(page);
+
+ // Open the saved document.
+ std::string new_file = GetString();
+ FPDF_FILEACCESS file_access;
+ memset(&file_access, 0, sizeof(file_access));
+ file_access.m_FileLen = new_file.size();
+ file_access.m_GetBlock = GetBlockFromString;
+ file_access.m_Param = &new_file;
+ FPDF_DOCUMENT new_doc = FPDF_LoadCustomDocument(&file_access, nullptr);
+ ASSERT_TRUE(new_doc);
+ FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0);
+ ASSERT_TRUE(new_page);
+
+ // Check that the saved document has 2 annotations on the first page.
+ EXPECT_EQ(2, FPDFPage_GetAnnotCount(new_page));
+
+ // Check that the remaining 2 annotations are the original 1st and 3rd ones by
+ // verifying their rectangle coordinates.
+ annot = FPDFPage_GetAnnot(new_page, 0);
+ rect = FPDFAnnot_GetRect(annot);
+ EXPECT_NEAR(86.1971f, rect.left, 0.001f);
+ FPDFPage_CloseAnnot(annot);
+
+ annot = FPDFPage_GetAnnot(new_page, 1);
+ rect = FPDFAnnot_GetRect(annot);
+ EXPECT_NEAR(351.8204f, rect.left, 0.001f);
+ FPDFPage_CloseAnnot(annot);
+
+ FPDF_ClosePage(new_page);
+ FPDF_CloseDocument(new_doc);
+}