Fix segv in CPDF_DataAvail::CheckRoot() when /Root object is a string.
[pdfium.git] / fpdfsdk / src / fpdfview_embeddertest.cpp
index 55c159a..47119b5 100644 (file)
@@ -27,14 +27,12 @@ TEST_F(FPDFViewEmbeddertest, Document) {
 
 TEST_F(FPDFViewEmbeddertest, Page) {
   EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
-  FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
-  FPDF_PAGE page = LoadPage(0, form_handle);
+  FPDF_PAGE page = LoadPage(0);
   EXPECT_NE(nullptr, page);
   EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
   EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
-  UnloadPage(page, form_handle);
-  EXPECT_EQ(nullptr, LoadPage(1, form_handle));
-  ClearFormFillEnvironment(form_handle);
+  UnloadPage(page);
+  EXPECT_EQ(nullptr, LoadPage(1));
 }
 
 TEST_F(FPDFViewEmbeddertest, ViewerRef) {
@@ -140,3 +138,59 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 }
+
+TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
+  EXPECT_TRUE(OpenDocument("testing/resources/named_dests.pdf"));
+
+  // Null pointer returns NULL.
+  FPDF_DEST dest = FPDF_GetNamedDestByName(document(), nullptr);
+  EXPECT_EQ(nullptr, dest);
+
+  // Empty string returns NULL.
+  dest = FPDF_GetNamedDestByName(document(), "");
+  EXPECT_EQ(nullptr, dest);
+
+  // Item from Dests NameTree.
+  dest = FPDF_GetNamedDestByName(document(), "First");
+  EXPECT_NE(nullptr, dest);
+
+  long ignore_len = 0;
+  FPDF_DEST dest_by_index =
+      FPDF_GetNamedDest(document(), 0, nullptr, ignore_len);
+  EXPECT_EQ(dest_by_index, dest);
+
+  // Item from Dests dictionary.
+  dest = FPDF_GetNamedDestByName(document(), "FirstAlternate");
+  EXPECT_NE(nullptr, dest);
+
+  ignore_len = 0;
+  dest_by_index = FPDF_GetNamedDest(document(), 4, nullptr, ignore_len);
+  EXPECT_EQ(dest_by_index, dest);
+
+  // Bad value type for item from Dests NameTree array.
+  dest = FPDF_GetNamedDestByName(document(), "WrongType");
+  EXPECT_EQ(nullptr, dest);
+
+  // No such destination in either Dest NameTree or dictionary.
+  dest = FPDF_GetNamedDestByName(document(), "Bogus");
+  EXPECT_EQ(nullptr, dest);
+}
+
+// The following tests pass if the document opens without crashing.
+TEST_F(FPDFViewEmbeddertest, Crasher_113) {
+  EXPECT_TRUE(OpenDocument("testing/resources/bug_113.pdf"));
+}
+
+TEST_F(FPDFViewEmbeddertest, Crasher_451830) {
+  EXPECT_TRUE(OpenDocument("testing/resources/bug_451830.pdf"));
+}
+
+TEST_F(FPDFViewEmbeddertest, Crasher_452455) {
+  EXPECT_TRUE(OpenDocument("testing/resources/bug_452455.pdf"));
+  FPDF_PAGE page = LoadPage(0);
+  EXPECT_NE(nullptr, page);
+}
+
+TEST_F(FPDFViewEmbeddertest, Crasher3) {
+  EXPECT_TRUE(OpenDocument("testing/resources/bug_454695.pdf"));
+}