Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: fpdfsdk/fpdfeditimg_unittest.cpp

Issue 2194393002: Fix a leak with FPDFPageObj_NewImgeObj(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/fpdfeditimg.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfeditimg_unittest.cpp
diff --git a/fpdfsdk/fpdfeditimg_unittest.cpp b/fpdfsdk/fpdfeditimg_unittest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..abe0ffe25c0a9c054d9fb489b8b190042b2c6cef
--- /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);
+}
« no previous file with comments | « fpdfsdk/fpdfeditimg.cpp ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698