Follow-on to pdfium_embeddertests.
authorTom Sepez <tsepez@chromium.org>
Fri, 16 Jan 2015 16:55:17 +0000 (08:55 -0800)
committerTom Sepez <tsepez@chromium.org>
Fri, 16 Jan 2015 16:55:17 +0000 (08:55 -0800)
This includes:
- Fix TestLoader lifetime.
- Rename test file to match the equivalent .cpp under test
- Re-organize a few tests to avoid duplicate loading
- add tests for a few additional functions.

R=jam@chromium.org

Review URL: https://codereview.chromium.org/857483005

fpdfsdk/src/fpdfview_embeddertest.cpp [new file with mode: 0644]
pdfium.gyp
testing/basic_embeddertest.cpp [deleted file]
testing/embedder_test.cpp
testing/embedder_test.h

diff --git a/fpdfsdk/src/fpdfview_embeddertest.cpp b/fpdfsdk/src/fpdfview_embeddertest.cpp
new file mode 100644 (file)
index 0000000..94a5109
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright 2015 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "../../testing/embedder_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FPDFViewEmbeddertest : public EmbedderTest {
+};
+
+TEST_F(FPDFViewEmbeddertest, Document) {
+  EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
+  EXPECT_EQ(1, GetPageCount());
+  EXPECT_EQ(0, GetFirstPageNum());
+
+  int version;
+  EXPECT_TRUE(FPDF_GetFileVersion(document(), &version));
+  EXPECT_EQ(14, version);
+
+  EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
+  EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(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);
+  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);
+}
+
+TEST_F(FPDFViewEmbeddertest, ViewerRef) {
+  EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
+  EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
+  EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
+  EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
+}
+
index fb6771f..9039190 100644 (file)
         '<(DEPTH)'
       ],
       'sources': [
-        'testing/basic_embeddertest.cpp',
+        'fpdfsdk/src/fpdfview_embeddertest.cpp',
         'testing/embedder_test.cpp',
         'testing/embedder_test.h',
         'testing/fx_string_testhelpers.cpp',
diff --git a/testing/basic_embeddertest.cpp b/testing/basic_embeddertest.cpp
deleted file mode 100644 (file)
index 210fabd..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2015 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "embedder_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class BasicEmbeddertest : public EmbedderTest {
-};
-
-TEST_F(BasicEmbeddertest, GetPageCount) {
-  EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
-  EXPECT_EQ(1, GetPageCount());
-}
-
-TEST_F(BasicEmbeddertest, GetFirstPageNum) {
-  EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
-  EXPECT_EQ(0, GetFirstPageNum());
-}
index 7b84983..e823347 100644 (file)
@@ -195,6 +195,9 @@ void EmbedderTest::SetUp() {
 void EmbedderTest::TearDown() {
   FPDF_CloseDocument(document_);
   FPDFAvail_Destroy(avail_);
+  if (loader_) {
+    delete loader_;
+  }
   if (file_contents_) {
     free(file_contents_);
   }
@@ -206,11 +209,10 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
     return false;
   }
 
-  TestLoader loader(file_contents_, file_length_);
-
+  loader_ = new TestLoader(file_contents_, file_length_);
   file_access_.m_FileLen = static_cast<unsigned long>(file_length_);
   file_access_.m_GetBlock = Get_Block;
-  file_access_.m_Param = &loader;
+  file_access_.m_Param = loader_;
 
   file_avail_.version = 1;
   file_avail_.IsDataAvail = Is_Data_Avail;
index b127ead..48ea415 100644 (file)
@@ -14,6 +14,8 @@
 #include "testing/gtest/include/gtest/gtest.h"
 #include "v8/include/v8.h"
 
+class TestLoader;
+
 // This class is used to load a PDF document, and then run programatic
 // API tests against it.
 class EmbedderTest : public ::testing::Test {
@@ -21,6 +23,7 @@ class EmbedderTest : public ::testing::Test {
   EmbedderTest() :
       document_(nullptr),
       avail_(nullptr),
+      loader_(nullptr),
       file_length_(0),
       file_contents_(nullptr) {
     memset(&hints_, 0, sizeof(hints_));
@@ -70,6 +73,7 @@ class EmbedderTest : public ::testing::Test {
   FX_FILEAVAIL file_avail_;
   v8::StartupData natives_;
   v8::StartupData snapshot_;
+  TestLoader* loader_;
   size_t file_length_;
   char* file_contents_;
 };