summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_editimg_unittest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-28 19:23:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-28 19:23:25 +0000
commit971a674ef17526ad37ce55ba90110830b94889d0 (patch)
treed99fabf665cc63825b48dd087daadf664bb80ee8 /fpdfsdk/fpdf_editimg_unittest.cpp
parent7d12532362545273e0ceac93fae2154661323fd1 (diff)
downloadpdfium-971a674ef17526ad37ce55ba90110830b94889d0.tar.xz
Rename fpdfsdk/fpdf* files to be consistent
This CL makes the fpdfsdk/fpdf* files to be consistently prefixed with fpdf_ instead of randomly dropping the _. Change-Id: I23e3c8a0831b56bcd17c788d9fe874b2ab8b24fc Reviewed-on: https://pdfium-review.googlesource.com/29390 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_editimg_unittest.cpp')
-rw-r--r--fpdfsdk/fpdf_editimg_unittest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_editimg_unittest.cpp b/fpdfsdk/fpdf_editimg_unittest.cpp
new file mode 100644
index 0000000000..fcc081ab76
--- /dev/null
+++ b/fpdfsdk/fpdf_editimg_unittest.cpp
@@ -0,0 +1,71 @@
+// 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/cpdf_modulemgr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class PDFEditTest : public testing::Test {
+ void SetUp() override { CPDF_ModuleMgr::Get()->Init(); }
+
+ 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_CountObjects(page));
+
+ FPDFPage_InsertObject(nullptr, nullptr);
+ EXPECT_EQ(0, FPDFPage_CountObjects(page));
+
+ FPDFPage_InsertObject(page, nullptr);
+ EXPECT_EQ(0, FPDFPage_CountObjects(page));
+
+ FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc);
+ FPDFPage_InsertObject(nullptr, page_image);
+ EXPECT_EQ(0, FPDFPage_CountObjects(page));
+
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}
+
+TEST_F(PDFEditTest, NewImageObj) {
+ FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
+ FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100);
+ EXPECT_EQ(0, FPDFPage_CountObjects(page));
+
+ FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc);
+ FPDFPage_InsertObject(page, page_image);
+ EXPECT_EQ(1, FPDFPage_CountObjects(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}
+
+TEST_F(PDFEditTest, NewImageObjGenerateContent) {
+ FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
+ FPDF_PAGE page = FPDFPage_New(doc, 0, 100, 100);
+ EXPECT_EQ(0, FPDFPage_CountObjects(page));
+
+ constexpr int kBitmapSize = 50;
+ FPDF_BITMAP bitmap = FPDFBitmap_Create(kBitmapSize, kBitmapSize, 0);
+ FPDFBitmap_FillRect(bitmap, 0, 0, kBitmapSize, kBitmapSize, 0x00000000);
+ EXPECT_EQ(kBitmapSize, FPDFBitmap_GetWidth(bitmap));
+ EXPECT_EQ(kBitmapSize, FPDFBitmap_GetHeight(bitmap));
+
+ FPDF_PAGEOBJECT page_image = FPDFPageObj_NewImageObj(doc);
+ ASSERT_TRUE(FPDFImageObj_SetBitmap(&page, 0, page_image, bitmap));
+ ASSERT_TRUE(
+ FPDFImageObj_SetMatrix(page_image, kBitmapSize, 0, 0, kBitmapSize, 0, 0));
+ FPDFPage_InsertObject(page, page_image);
+ EXPECT_EQ(1, FPDFPage_CountObjects(page));
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+
+ FPDFBitmap_Destroy(bitmap);
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}