Delete unused fpdfsdkdll.rc and resource.h.
[pdfium.git] / fpdfsdk / src / fpdfview_embeddertest.cpp
index ee32727..896a196 100644 (file)
@@ -5,12 +5,16 @@
 #include <limits>
 #include <string>
 
+#include "../../public/fpdfview.h"
 #include "../../testing/embedder_test.h"
-#include "../../fpdfsdk/include/fpdfview.h"
+#include "fpdfview_c_api_test.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
-class FPDFViewEmbeddertest : public EmbedderTest {
-};
+TEST(fpdf, CApiTest) {
+  EXPECT_TRUE(CheckPDFiumCApi());
+}
+
+class FPDFViewEmbeddertest : public EmbedderTest {};
 
 TEST_F(FPDFViewEmbeddertest, Document) {
   EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
@@ -27,14 +31,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) {
@@ -51,21 +53,21 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
   FPDF_DEST dest;
 
   // Query the size of the first item.
-  buffer_size = 2000000; // Absurdly large, check not used for this case.
-  dest = FPDF_GetNamedDest(document(), 0, nullptr, buffer_size);
+  buffer_size = 2000000;  // Absurdly large, check not used for this case.
+  dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(12u, buffer_size);
 
   // Try to retrieve the first item with too small a buffer.
   buffer_size = 10;
-  dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(-1, buffer_size);
 
   // Try to retrieve the first item with correctly sized buffer. Item is
   // taken from Dests NameTree in named_dests.pdf.
   buffer_size = 12;
-  dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(12u, buffer_size);
   EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12),
@@ -74,7 +76,7 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
   // Try to retrieve the second item with ample buffer. Item is taken
   // from Dests NameTree but has a sub-dictionary in named_dests.pdf.
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(10u, buffer_size);
   EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10),
@@ -84,59 +86,57 @@ TEST_F(FPDFViewEmbeddertest, NamedDests) {
   // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf.
   // in named_dests.pdf).
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 
   // Try to retrieve the forth item with ample buffer. Item is taken
   // from Dests NameTree but has a vale of the wrong type in named_dests.pdf.
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 
   // Try to retrieve fifth item with ample buffer. Item taken from the
   // old-style Dests dictionary object in named_dests.pdf.
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(30u, buffer_size);
-  EXPECT_EQ(
-      std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30),
-      std::string(fixed_buffer, buffer_size));
+  EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30),
+            std::string(fixed_buffer, buffer_size));
 
   // Try to retrieve sixth item with ample buffer. Item istaken from the
   // old-style Dests dictionary object but has a sub-dictionary in
   // named_dests.pdf.
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size);
   EXPECT_NE(nullptr, dest);
   EXPECT_EQ(28u, buffer_size);
-  EXPECT_EQ(
-      std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28),
-      std::string(fixed_buffer, buffer_size));
+  EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28),
+            std::string(fixed_buffer, buffer_size));
 
   // Try to retrieve non-existent item with ample buffer.
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 
   // Try to underflow/overflow the integer index.
   buffer_size = sizeof(fixed_buffer);
   dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::max(),
-                           fixed_buffer, buffer_size);
+                           fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 
   buffer_size = sizeof(fixed_buffer);
   dest = FPDF_GetNamedDest(document(), std::numeric_limits<int>::min(),
-                           fixed_buffer, buffer_size);
+                           fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 
   buffer_size = sizeof(fixed_buffer);
-  dest = FPDF_GetNamedDest(document(), -1, fixed_buffer, buffer_size);
+  dest = FPDF_GetNamedDest(document(), -1, fixed_buffer, &buffer_size);
   EXPECT_EQ(nullptr, dest);
   EXPECT_EQ(sizeof(fixed_buffer), buffer_size);  // unmodified.
 }
@@ -158,7 +158,7 @@ TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
 
   long ignore_len = 0;
   FPDF_DEST dest_by_index =
-      FPDF_GetNamedDest(document(), 0, nullptr, ignore_len);
+      FPDF_GetNamedDest(document(), 0, nullptr, &ignore_len);
   EXPECT_EQ(dest_by_index, dest);
 
   // Item from Dests dictionary.
@@ -166,7 +166,7 @@ TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
   EXPECT_NE(nullptr, dest);
 
   ignore_len = 0;
-  dest_by_index = FPDF_GetNamedDest(document(), 4, nullptr, ignore_len);
+  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.
@@ -177,3 +177,23 @@ TEST_F(FPDFViewEmbeddertest, NamedDestsByName) {
   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);
+  UnloadPage(page);
+}
+
+TEST_F(FPDFViewEmbeddertest, Crasher3) {
+  EXPECT_TRUE(OpenDocument("testing/resources/bug_454695.pdf"));
+}