Add more tests for FPDF_CountNamedDests().
Including a new PDF with "old style" destinations.
Change-Id: I6a9e9746dbdb89e351d155b5748cc0367dbd6ab0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68254
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index cbeeaf6..e5701a3 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -529,6 +529,8 @@
TEST_F(FPDFViewEmbedderTest, NamedDests) {
EXPECT_TRUE(OpenDocument("named_dests.pdf"));
+ EXPECT_EQ(6u, FPDF_CountNamedDests(document()));
+
long buffer_size;
char fixed_buffer[512];
FPDF_DEST dest;
@@ -665,6 +667,11 @@
EXPECT_EQ(nullptr, dest);
}
+TEST_F(FPDFViewEmbedderTest, NamedDestsOldStyle) {
+ EXPECT_TRUE(OpenDocument("named_dests_old_style.pdf"));
+ EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
+}
+
// The following tests pass if the document opens without crashing.
TEST_F(FPDFViewEmbedderTest, Crasher_113) {
EXPECT_TRUE(OpenDocument("bug_113.pdf"));
diff --git a/testing/resources/named_dests_old_style.in b/testing/resources/named_dests_old_style.in
new file mode 100644
index 0000000..70e45ed
--- /dev/null
+++ b/testing/resources/named_dests_old_style.in
@@ -0,0 +1,55 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /Dests 6 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 2
+ /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources <<
+ /Font <<
+ /F1 5 0 R
+ >>
+ >>
+ /Contents [4 0 R]
+ /MediaBox [0 0 612 792]
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+BT
+/F1 20 Tf
+100 600 TD (Page1)Tj
+ET
+endstream
+endobj
+{{object 5 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Arial
+>>
+endobj
+% Old-style top-level Dests dictionary. Note that FirstAlternate
+% intentionally references non-existent page 11 and LastAlternate
+% intentionally references non-existent object 999.
+{{object 6 0}} <<
+ /FirstAlternate [11 /XYZ 200 400 800]
+ /LastAlternate <<
+ /D [999 0 R /XYZ 0 0 -200]
+ >>
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/named_dests_old_style.pdf b/testing/resources/named_dests_old_style.pdf
new file mode 100644
index 0000000..df7f04a
--- /dev/null
+++ b/testing/resources/named_dests_old_style.pdf
@@ -0,0 +1,68 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /Dests 6 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 2
+ /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources <<
+ /Font <<
+ /F1 5 0 R
+ >>
+ >>
+ /Contents [4 0 R]
+ /MediaBox [0 0 612 792]
+>>
+endobj
+4 0 obj <<
+ /Length 37
+>>
+stream
+BT
+/F1 20 Tf
+100 600 TD (Page1)Tj
+ET
+endstream
+endobj
+5 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Arial
+>>
+endobj
+% Old-style top-level Dests dictionary. Note that FirstAlternate
+% intentionally references non-existent page 11 and LastAlternate
+% intentionally references non-existent object 999.
+6 0 obj <<
+ /FirstAlternate [11 /XYZ 200 400 800]
+ /LastAlternate <<
+ /D [999 0 R /XYZ 0 0 -200]
+ >>
+>>
+endobj
+xref
+0 7
+0000000000 65535 f
+0000000015 00000 n
+0000000083 00000 n
+0000000146 00000 n
+0000000300 00000 n
+0000000388 00000 n
+0000000643 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 7
+>>
+startxref
+761
+%%EOF