summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedit_embeddertest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp91
1 files changed, 87 insertions, 4 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index ec403c74b3..65e790cc32 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -387,7 +387,8 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
-// Show how the original file looks like.
+ // Show what the original file looks like.
+ {
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
const char kOriginalMD5[] = "b90475ca64d1348c3bf5e2b77ad9187a";
#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
@@ -395,7 +396,6 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
#else
const char kOriginalMD5[] = "2baa4c0e1758deba1b9c908e1fbd04ed";
#endif
- {
std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
RenderPageWithFlags(page, nullptr, 0);
CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5);
@@ -407,7 +407,8 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
ASSERT_TRUE(page_object);
EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
-// Verify the "Hello, world!" text is gone.
+ // Verify the "Hello, world!" text is gone.
+ {
#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
const char kRemovedMD5[] = "af760c4702467cb1492a57fb8215efaa";
#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
@@ -415,7 +416,6 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
#else
const char kRemovedMD5[] = "b76df015fe88009c3c342395df96abf1";
#endif
- {
std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
RenderPageWithFlags(page, nullptr, 0);
CompareBitmap(page_bitmap.get(), 200, 200, kRemovedMD5);
@@ -426,6 +426,89 @@ TEST_F(FPDFEditEmbeddertest, RemovePageObject) {
FPDFPageObj_Destroy(page_object);
}
+TEST_F(FPDFEditEmbeddertest, RemoveMarkedObjectsPrime) {
+ // Load document with some text.
+ EXPECT_TRUE(OpenDocument("text_in_page_marked.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Show what the original file looks like.
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char kOriginalMD5[] = "5a5eb63cb21cc15084fea1f14284b8df";
+#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+ const char kOriginalMD5[] = "587c507a40f613f9c530b2ce2d58d655";
+#else
+ const char kOriginalMD5[] = "2edc6e70d54889aa0c0b7bdf3e168f86";
+#endif
+ std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
+ RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 200, kOriginalMD5);
+ }
+
+ // Iterate over all objects, counting the number of times each content mark
+ // name appears.
+ int object_count = FPDFPage_CountObjects(page);
+ ASSERT_EQ(19, object_count);
+
+ unsigned long prime_count = 0;
+ unsigned long square_count = 0;
+ unsigned long greater_than_ten_count = 0;
+ std::vector<FPDF_PAGEOBJECT> primes;
+ for (int i = 0; i < object_count; ++i) {
+ FPDF_PAGEOBJECT page_object = FPDFPage_GetObject(page, i);
+
+ int mark_count = FPDFPageObj_CountMarks(page_object);
+ for (int j = 0; j < mark_count; ++j) {
+ FPDF_PAGEOBJECTMARK mark = FPDFPageObj_GetMark(page_object, j);
+
+ char buffer[256];
+ ASSERT_GT(FPDFPageObjMark_GetName(mark, buffer, 256), 0u);
+ std::wstring name =
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buffer));
+ if (name == L"Prime") {
+ prime_count++;
+ primes.push_back(page_object);
+ } else if (name == L"Square") {
+ square_count++;
+ } else if (name == L"GreaterThanTen") {
+ greater_than_ten_count++;
+ } else {
+ FAIL();
+ }
+ }
+ }
+
+ // Expect certain number of tagged objects. The test file contains strings
+ // from 1 to 19.
+ EXPECT_EQ(8u, prime_count);
+ EXPECT_EQ(4u, square_count);
+ EXPECT_EQ(9u, greater_than_ten_count);
+
+ // Remove all objects marked with "Prime".
+ for (FPDF_PAGEOBJECT page_object : primes) {
+ EXPECT_TRUE(FPDFPage_RemoveObject(page, page_object));
+ FPDFPageObj_Destroy(page_object);
+ }
+
+ EXPECT_EQ(11, FPDFPage_CountObjects(page));
+
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char kNonPrimesMD5[] = "57e76dc7375d896704f0fd6d6d1b9e65";
+#elif _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+ const char kNonPrimesMD5[] = "4d906b57fba36c70c600cf50d60f508c";
+#else
+ const char kNonPrimesMD5[] = "33d9c45bec41ead92a295e252f6b7922";
+#endif
+ std::unique_ptr<void, FPDFBitmapDeleter> page_bitmap =
+ RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 200, 200, kNonPrimesMD5);
+ }
+
+ UnloadPage(page);
+}
+
TEST_F(FPDFEditEmbeddertest, AddAndRemovePaths) {
// Start with a blank page.
FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);