summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfeditimg_unittest.cpp
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-08-09 15:46:20 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-09 15:46:20 -0700
commitdc359b03ab6a70ee52a91119ff6704cae92f4809 (patch)
tree131cb9b1846f4be24c9cb7c54b30975c6a858071 /fpdfsdk/fpdfeditimg_unittest.cpp
parent39ba18a64283ef3fc3c4aedf537a09835f90862e (diff)
downloadpdfium-dc359b03ab6a70ee52a91119ff6704cae92f4809.tar.xz
Fix a leak with FPDFPageObj_NewImgeObj().
BUG=pdfium:545 Review-Url: https://codereview.chromium.org/2194393002
Diffstat (limited to 'fpdfsdk/fpdfeditimg_unittest.cpp')
-rw-r--r--fpdfsdk/fpdfeditimg_unittest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfeditimg_unittest.cpp b/fpdfsdk/fpdfeditimg_unittest.cpp
new file mode 100644
index 0000000000..abe0ffe25c
--- /dev/null
+++ b/fpdfsdk/fpdfeditimg_unittest.cpp
@@ -0,0 +1,52 @@
+// Copyright 2016 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 "public/fpdf_edit.h"
+
+#include "core/fpdfapi/include/cpdf_modulemgr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class PDFEditTest : public testing::Test {
+ void SetUp() override {
+ CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
+ module_mgr->InitPageModule();
+ }
+
+ void TearDown() override { CPDF_ModuleMgr::Destroy(); }
+};
+
+TEST_F(PDFEditTest, InsertObjectWithInvalidPage) {
+ FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
+ FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100);
+ EXPECT_EQ(0, FPDFPage_CountObject(page));
+
+ FPDFPage_InsertObject(nullptr, nullptr);
+ EXPECT_EQ(0, FPDFPage_CountObject(page));
+
+ FPDFPage_InsertObject(page, nullptr);
+ EXPECT_EQ(0, FPDFPage_CountObject(page));
+
+ FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImgeObj(doc);
+ FPDFPage_InsertObject(nullptr, page_image);
+ EXPECT_EQ(0, FPDFPage_CountObject(page));
+
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}
+
+// https://bugs.chromium.org/p/pdfium/issues/detail?id=545
+// TODO(thestig): Add another test case that also calls
+// FPDFPage_GenerateContent().
+TEST_F(PDFEditTest, NewImgeObj) {
+ FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
+ FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100);
+ EXPECT_EQ(0, FPDFPage_CountObject(page));
+
+ FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImgeObj(doc);
+ FPDFPage_InsertObject(page, page_image);
+ EXPECT_EQ(1, FPDFPage_CountObject(page));
+
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}