diff options
author | Jane Liu <janeliulwq@google.com> | 2017-06-26 11:28:36 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-27 18:13:48 +0000 |
commit | d60e9ad5194e13475ccb21575a7c57de1e2e22c4 (patch) | |
tree | 040f7bcade94671b71e5148f716e18416cd06558 /fpdfsdk/fpdfannot_embeddertest.cpp | |
parent | 22eb7ae54e4351f70a5a01b0130c8b0dc713586c (diff) | |
download | pdfium-d60e9ad5194e13475ccb21575a7c57de1e2e22c4.tar.xz |
Changed the return type for annotation APIs
Before:
When returning FPDF_ANNOTATION, the APIs would take in a
FPDF_ANNTOATION* and write the handle of the annotation to it, while
returning a boolean as status.
This CL:
This CL changes the APIs to directly return FPDF_ANNOTATION, which
would be null on failure.
Also adds more null checks within the annotation APIs.
Bug=pdfium:737
Change-Id: I4f77dd1b16d43eab3f16c303598b76591da0dcab
Reviewed-on: https://pdfium-review.googlesource.com/6952
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfannot_embeddertest.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp index b7dee88b78..4d6ae1c6d8 100644 --- a/fpdfsdk/fpdfannot_embeddertest.cpp +++ b/fpdfsdk/fpdfannot_embeddertest.cpp @@ -40,8 +40,8 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); // Check that the annotation is of type "highlight". - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_HIGHLIGHT, FPDFAnnot_GetSubtype(annot)); // Check that the annotation color is yellow. @@ -98,8 +98,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractHighlightLongContent) { .c_str()); // Check that the quadpoints are correct. - FS_QUADPOINTSF quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); EXPECT_EQ(115.802643f, quadpoints.x1); EXPECT_EQ(718.913940f, quadpoints.y1); EXPECT_EQ(157.211182f, quadpoints.x4); @@ -119,8 +118,8 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { EXPECT_EQ(3, FPDFPage_GetAnnotCount(page)); // Check that the third annotation is of type "ink". - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 2, &annot)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 2); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_INK, FPDFAnnot_GetSubtype(annot)); // Check that the annotation color is blue with opacity. @@ -141,8 +140,7 @@ TEST_F(FPDFAnnotEmbeddertest, ExtractInkMultiple) { // Check that the rectange coordinates are correct. // Note that upon rendering, the rectangle coordinates will be adjusted. - FS_RECTF rect; - ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); + FS_RECTF rect = FPDFAnnot_GetRect(annot); EXPECT_EQ(351.820404f, rect.left); EXPECT_EQ(583.830688f, rect.bottom); EXPECT_EQ(475.336090f, rect.right); @@ -159,8 +157,7 @@ TEST_F(FPDFAnnotEmbeddertest, AddIllegalSubtypeAnnotation) { ASSERT_TRUE(page); // Add an annotation with an illegal subtype. - FPDF_ANNOTATION annot; - ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1, &annot)); + ASSERT_FALSE(FPDFPage_CreateAnnot(page, -1)); UnloadPage(page); } @@ -173,8 +170,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(0, FPDFPage_GetAnnotCount(page)); // Add a text annotation to the page. - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT, &annot)); + FPDF_ANNOTATION annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_TEXT); + ASSERT_TRUE(annot); // Check that there is now 1 annotations on this page. EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); @@ -183,7 +180,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); FPDFPage_CloseAnnot(annot); - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); + annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); EXPECT_EQ(FPDF_ANNOT_TEXT, FPDFAnnot_GetSubtype(annot)); // Set the color of the annotation. @@ -213,15 +211,16 @@ TEST_F(FPDFAnnotEmbeddertest, AddFirstTextAnnotation) { EXPECT_EQ(51u, A); // Set the annotation rectangle. - FS_RECTF rect; - EXPECT_FALSE(FPDFAnnot_GetRect(annot, &rect)); + FS_RECTF rect = FPDFAnnot_GetRect(annot); + EXPECT_EQ(0.f, rect.left); + EXPECT_EQ(0.f, rect.right); rect.left = 35; rect.bottom = 150; rect.right = 53; rect.top = 165; ASSERT_TRUE(FPDFAnnot_SetRect(annot, rect)); // Check that the annotation rectangle has been set correctly. - ASSERT_TRUE(FPDFAnnot_GetRect(annot, &rect)); + rect = FPDFAnnot_GetRect(annot); EXPECT_EQ(35.f, rect.left); EXPECT_EQ(150.f, rect.bottom); EXPECT_EQ(53.f, rect.right); @@ -256,10 +255,9 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { // Check that there is a total of one annotation on its first page, and verify // its quadpoints. EXPECT_EQ(1, FPDFPage_GetAnnotCount(page)); - FPDF_ANNOTATION annot; - ASSERT_TRUE(FPDFPage_GetAnnot(page, 0, &annot)); - FS_QUADPOINTSF quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(annot, &quadpoints)); + FPDF_ANNOTATION annot = FPDFPage_GetAnnot(page, 0); + ASSERT_TRUE(annot); + FS_QUADPOINTSF quadpoints = FPDFAnnot_GetAttachmentPoints(annot); EXPECT_EQ(115.802643f, quadpoints.x1); EXPECT_EQ(718.913940f, quadpoints.y1); EXPECT_EQ(157.211182f, quadpoints.x4); @@ -267,7 +265,8 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { FPDFPage_CloseAnnot(annot); // Add an underline annotation to the page and set its quadpoints. - ASSERT_TRUE(FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE, &annot)); + annot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_UNDERLINE); + ASSERT_TRUE(annot); quadpoints.x1 = 140.802643f; quadpoints.x3 = 140.802643f; ASSERT_TRUE(FPDFAnnot_SetAttachmentPoints(annot, quadpoints)); @@ -294,11 +293,10 @@ TEST_F(FPDFAnnotEmbeddertest, AddAndSaveUnderlineAnnotation) { // Check that the second annotation is an underline annotation and verify // its quadpoints. - FPDF_ANNOTATION new_annot; - ASSERT_TRUE(FPDFPage_GetAnnot(new_page, 1, &new_annot)); + FPDF_ANNOTATION new_annot = FPDFPage_GetAnnot(new_page, 1); + ASSERT_TRUE(new_annot); EXPECT_EQ(FPDF_ANNOT_UNDERLINE, FPDFAnnot_GetSubtype(new_annot)); - FS_QUADPOINTSF new_quadpoints; - ASSERT_TRUE(FPDFAnnot_GetAttachmentPoints(new_annot, &new_quadpoints)); + FS_QUADPOINTSF new_quadpoints = FPDFAnnot_GetAttachmentPoints(new_annot); EXPECT_NEAR(quadpoints.x1, new_quadpoints.x1, 0.001f); EXPECT_NEAR(quadpoints.y1, new_quadpoints.y1, 0.001f); EXPECT_NEAR(quadpoints.x4, new_quadpoints.x4, 0.001f); |