diff options
author | Lei Zhang <thestig@chromium.org> | 2018-09-14 17:02:40 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-14 17:02:40 +0000 |
commit | 7557e7b0efc01cd2367a37d919f3bbfe50616a28 (patch) | |
tree | 2bb64de11f110ed26c43af31102ebe63662f07d0 /fpdfsdk/fpdf_annot_embeddertest.cpp | |
parent | 7a956edb6b5356ebab6bae0a6c3d8bd279c01019 (diff) | |
download | pdfium-7557e7b0efc01cd2367a37d919f3bbfe50616a28.tar.xz |
Add basic tests for some annotation APIs.
Make sure they can handle obviously bad input. These cases lack test
coverage.
Change-Id: I32d3345faebe566e5346750f622f6be9409f30e4
Reviewed-on: https://pdfium-review.googlesource.com/42450
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_annot_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdf_annot_embeddertest.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp index 767a5c78c0..7be5d75177 100644 --- a/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/fpdfsdk/fpdf_annot_embeddertest.cpp @@ -28,6 +28,43 @@ std::string BufferToString(const std::vector<char>& buf) { return GetPlatformString(reinterpret_cast<FPDF_WIDESTRING>(buf.data())); } +TEST_F(FPDFAnnotEmbeddertest, BadParams) { + ASSERT_TRUE(OpenDocument("hello_world.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + EXPECT_EQ(0, FPDFPage_GetAnnotCount(nullptr)); + + EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 0)); + EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, -1)); + EXPECT_FALSE(FPDFPage_GetAnnot(nullptr, 1)); + EXPECT_FALSE(FPDFPage_GetAnnot(page, -1)); + EXPECT_FALSE(FPDFPage_GetAnnot(page, 1)); + + EXPECT_EQ(FPDF_ANNOT_UNKNOWN, FPDFAnnot_GetSubtype(nullptr)); + + EXPECT_EQ(0, FPDFAnnot_GetObjectCount(nullptr)); + + EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, 0)); + EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, -1)); + EXPECT_FALSE(FPDFAnnot_GetObject(nullptr, 1)); + + EXPECT_FALSE(FPDFAnnot_HasKey(nullptr, "foo")); + + static constexpr wchar_t kContents[] = L"Bar"; + std::unique_ptr<unsigned short, pdfium::FreeDeleter> text = + GetFPDFWideString(kContents); + EXPECT_FALSE(FPDFAnnot_SetStringValue(nullptr, "foo", text.get())); + + char buffer[128]; + EXPECT_EQ(0u, FPDFAnnot_GetStringValue(nullptr, "foo", nullptr, 0)); + EXPECT_EQ(0u, FPDFAnnot_GetStringValue(nullptr, "foo", buffer, 0)); + EXPECT_EQ(0u, + FPDFAnnot_GetStringValue(nullptr, "foo", buffer, sizeof(buffer))); + + UnloadPage(page); +} + TEST_F(FPDFAnnotEmbeddertest, RenderAnnotWithOnlyRolloverAP) { // Open a file with one annotation and load its first page. ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); @@ -1418,9 +1455,19 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) { ASSERT_TRUE(page); // Attempt to get an annotation where no annotation exists on page. - FPDF_ANNOTATION annot = - FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0); - EXPECT_FALSE(annot); + EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0)); + + { + // Verify there is an annotation. + ScopedFPDFAnnotation annot( + FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 120, 120)); + EXPECT_TRUE(annot); + } + + // Try other bad inputs at a valid location. + EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, nullptr, 120, 120)); + EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(nullptr, page, 120, 120)); + EXPECT_FALSE(FPDFAnnot_GetFormFieldAtPoint(form_handle(), nullptr, 120, 120)); UnloadPage(page); } |