Test FPDFAnnot_GetFormFieldType API with more form field types
The CL adds a new file with multiple types of form fields. The file is
used to validate the FPDFAnnot_GetFormFieldType API for more form field
types.
Bug: pdfium:1459
Change-Id: Ibfc2a41aca69feb8845612b2856bd09ea440a9ca
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65990
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 1e0ebd8..e69ee16 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -10,6 +10,7 @@
#include "build/build_config.h"
#include "constants/annotation_common.h"
+#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_system.h"
#include "public/cpp/fpdf_scopers.h"
#include "public/fpdf_annot.h"
@@ -2238,34 +2239,30 @@
UnloadPage(page);
}
-TEST_F(FPDFAnnotEmbedderTest, GetFormFieldTypeTextField) {
- ASSERT_TRUE(OpenDocument("text_form.pdf"));
+TEST_F(FPDFAnnotEmbedderTest, GetFormFieldType) {
+ ASSERT_TRUE(OpenDocument("multiple_form_types.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
+ EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(), nullptr));
+
{
- EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(form_handle(), nullptr));
-
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 1));
ASSERT_TRUE(annot);
-
EXPECT_EQ(-1, FPDFAnnot_GetFormFieldType(nullptr, annot.get()));
-
- EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
- FPDFAnnot_GetFormFieldType(form_handle(), annot.get()));
}
- UnloadPage(page);
-}
-TEST_F(FPDFAnnotEmbedderTest, GetFormFieldTypeComboBox) {
- ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
- FPDF_PAGE page = LoadPage(0);
- ASSERT_TRUE(page);
+ constexpr int kExpectedAnnotTypes[] = {-1,
+ FPDF_FORMFIELD_COMBOBOX,
+ FPDF_FORMFIELD_LISTBOX,
+ FPDF_FORMFIELD_TEXTFIELD,
+ FPDF_FORMFIELD_CHECKBOX,
+ FPDF_FORMFIELD_RADIOBUTTON};
- {
- ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+ for (size_t i = 0; i < FX_ArraySize(kExpectedAnnotTypes); ++i) {
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, i));
ASSERT_TRUE(annot);
- EXPECT_EQ(FPDF_FORMFIELD_COMBOBOX,
+ EXPECT_EQ(kExpectedAnnotTypes[i],
FPDFAnnot_GetFormFieldType(form_handle(), annot.get()));
}
UnloadPage(page);
diff --git a/testing/resources/multiple_form_types.in b/testing/resources/multiple_form_types.in
new file mode 100644
index 0000000..ec6af63
--- /dev/null
+++ b/testing/resources/multiple_form_types.in
@@ -0,0 +1,131 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm <<
+ /Fields [8 0 R 9 0 R 10 0 R 11 0 R 12 0 R]
+ /DR 4 0 R
+ >>
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 4 0 R
+ /MediaBox [0 0 300 600]
+ /Contents 6 0 R
+ /Annots [7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 13 0 R]
+>>
+endobj
+{{object 4 0}} <<
+ /Font <<
+ /F1 5 0 R
+ >>
+>>
+endobj
+{{object 5 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+{{object 6 0}} <<
+ {{streamlen}}
+>>
+stream
+BT
+0 0 0 rg
+/F1 12 Tf
+100 450 Td
+(Test Form) Tj
+ET
+endstream
+endobj
+{{object 7 0}} <<
+ /Type /Annot
+ /Subtype /Link
+ /BS <<
+ /W 0
+ >>
+ /Rect [100 450 160 460]
+ /A <<
+ /Type /Action
+ /URI (https://www.cs.chromium.org/)
+ /S /URI
+ >>
+ /F 4
+>>
+endobj
+{{object 8 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Ch
+ /Ff 393216
+ /T (Combo_Editable)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 400 200 430]
+ /Opt [[(foo) (Foo)] [(bar) (Bar)] [(qux) (Qux)]]
+>>
+endobj
+{{object 9 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Ch
+ /Ff 2097152
+ /T (Listbox_MultiSelectMultipleSelected)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 350 200 380]
+ /Opt [(Alpha) (Beta) (Gamma) (Delta) (Epsilon)]
+ /V [(Epsilon) (Gamma)]
+>>
+endobj
+{{object 10 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 300 200 330]
+>>
+endobj
+{{object 11 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /F 4
+ /P 3 0 R
+ /Rect [135 250 155 270]
+ /T (Checkbox)
+>>
+endobj
+{{object 12 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /Ff 32768
+ /T (radioButton)
+ /TU (radioButton1)
+ /Kids [13 0 R]
+ /V /value3
+>>
+endobj
+{{object 13 0}} <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /F 4
+ /P 3 0 R
+ /Parent 12 0 R
+ /Rect [85 50 105 70]
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/multiple_form_types.pdf b/testing/resources/multiple_form_types.pdf
new file mode 100644
index 0000000..da83c9e
--- /dev/null
+++ b/testing/resources/multiple_form_types.pdf
@@ -0,0 +1,151 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm <<
+ /Fields [8 0 R 9 0 R 10 0 R 11 0 R 12 0 R]
+ /DR 4 0 R
+ >>
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 4 0 R
+ /MediaBox [0 0 300 600]
+ /Contents 6 0 R
+ /Annots [7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 13 0 R]
+>>
+endobj
+4 0 obj <<
+ /Font <<
+ /F1 5 0 R
+ >>
+>>
+endobj
+5 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+6 0 obj <<
+ /Length 51
+>>
+stream
+BT
+0 0 0 rg
+/F1 12 Tf
+100 450 Td
+(Test Form) Tj
+ET
+endstream
+endobj
+7 0 obj <<
+ /Type /Annot
+ /Subtype /Link
+ /BS <<
+ /W 0
+ >>
+ /Rect [100 450 160 460]
+ /A <<
+ /Type /Action
+ /URI (https://www.cs.chromium.org/)
+ /S /URI
+ >>
+ /F 4
+>>
+endobj
+8 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Ch
+ /Ff 393216
+ /T (Combo_Editable)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 400 200 430]
+ /Opt [[(foo) (Foo)] [(bar) (Bar)] [(qux) (Qux)]]
+>>
+endobj
+9 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Ch
+ /Ff 2097152
+ /T (Listbox_MultiSelectMultipleSelected)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 350 200 380]
+ /Opt [(Alpha) (Beta) (Gamma) (Delta) (Epsilon)]
+ /V [(Epsilon) (Gamma)]
+>>
+endobj
+10 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [100 300 200 330]
+>>
+endobj
+11 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /F 4
+ /P 3 0 R
+ /Rect [135 250 155 270]
+ /T (Checkbox)
+>>
+endobj
+12 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /Ff 32768
+ /T (radioButton)
+ /TU (radioButton1)
+ /Kids [13 0 R]
+ /V /value3
+>>
+endobj
+13 0 obj <<
+ /Type /Annot
+ /Subtype /Widget
+ /FT /Btn
+ /F 4
+ /P 3 0 R
+ /Parent 12 0 R
+ /Rect [85 50 105 70]
+>>
+endobj
+xref
+0 14
+0000000000 65535 f
+0000000015 00000 n
+0000000149 00000 n
+0000000212 00000 n
+0000000377 00000 n
+0000000428 00000 n
+0000000504 00000 n
+0000000606 00000 n
+0000000798 00000 n
+0000001002 00000 n
+0000001252 00000 n
+0000001387 00000 n
+0000001514 00000 n
+0000001663 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 14
+>>
+startxref
+1788
+%%EOF