summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfattachment_embeddertest.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-07-25 18:11:27 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-27 13:52:39 +0000
commitf63e8133d7a767c6f162e700056ae8ba8512820d (patch)
treef0a8aab3dfb06b5c121d4f3350bf97aeceab4d7e /fpdfsdk/fpdfattachment_embeddertest.cpp
parentf9d60598992f3d9ce2f4b5860a7835fa44d55c88 (diff)
downloadpdfium-f63e8133d7a767c6f162e700056ae8ba8512820d.tar.xz
Added FPDFDoc_DeleteAttachment()
Added an API for deleting an attachment and an embedder test for it. Bug=pdfium:174 Change-Id: I97a1367a197bceb96ecef55c36b1599beccd95a6 Reviewed-on: https://pdfium-review.googlesource.com/8932 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfattachment_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfattachment_embeddertest.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/fpdfsdk/fpdfattachment_embeddertest.cpp b/fpdfsdk/fpdfattachment_embeddertest.cpp
index f4d0bfcfae..74b3d7b469 100644
--- a/fpdfsdk/fpdfattachment_embeddertest.cpp
+++ b/fpdfsdk/fpdfattachment_embeddertest.cpp
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+#include <string>
+#include <vector>
+
#include "public/fpdf_attachment.h"
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
@@ -234,4 +238,33 @@ TEST_F(FPDFAttachmentEmbeddertest, AddAttachmentsWithParams) {
buf.data(), len));
EXPECT_EQ(L"<D41D8CD98F00B204E9800998ECF8427E>",
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())));
-} \ No newline at end of file
+}
+
+TEST_F(FPDFAttachmentEmbeddertest, DeleteAttachment) {
+ // Open a file with two attachments.
+ ASSERT_TRUE(OpenDocument("embedded_attachments.pdf"));
+ EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
+
+ // Verify the name of the first attachment.
+ FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0);
+ unsigned long len = FPDFAttachment_GetName(attachment, nullptr, 0);
+ std::vector<char> buf(len);
+ EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), len));
+ EXPECT_STREQ(L"1.txt",
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
+ .c_str());
+
+ // Delete the first attachment.
+ EXPECT_TRUE(FPDFDoc_DeleteAttachment(document(), 0));
+ EXPECT_EQ(1, FPDFDoc_GetAttachmentCount(document()));
+
+ // Verify the name of the new first attachment.
+ attachment = FPDFDoc_GetAttachment(document(), 0);
+ len = FPDFAttachment_GetName(attachment, nullptr, 0);
+ buf.clear();
+ buf.resize(len);
+ EXPECT_EQ(26u, FPDFAttachment_GetName(attachment, buf.data(), len));
+ EXPECT_STREQ(L"attached.pdf",
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
+ .c_str());
+}