summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfattachment_embeddertest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-08-31 02:33:27 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-08-31 16:41:19 +0000
commitdf064df7a08e008b3c8e4d56bb0b75da9f014147 (patch)
tree17f7244a29424c5e61460ed672b2f25df1278b14 /fpdfsdk/fpdfattachment_embeddertest.cpp
parent63b012652da22f75172895a975ea7932e63dcc81 (diff)
downloadpdfium-df064df7a08e008b3c8e4d56bb0b75da9f014147.tar.xz
Change APIs to use FPDF_BYTESTRING for keys.
Change-Id: I865a9eeb197ea2c1f5480cae32d975909495676d Reviewed-on: https://pdfium-review.googlesource.com/12551 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfattachment_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfattachment_embeddertest.cpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/fpdfsdk/fpdfattachment_embeddertest.cpp b/fpdfsdk/fpdfattachment_embeddertest.cpp
index 74b3d7b469..dd9b5aebf3 100644
--- a/fpdfsdk/fpdfattachment_embeddertest.cpp
+++ b/fpdfsdk/fpdfattachment_embeddertest.cpp
@@ -10,6 +10,9 @@
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
+static constexpr char kDateKey[] = "CreationDate";
+static constexpr char kChecksumKey[] = "CheckSum";
+
class FPDFAttachmentEmbeddertest : public EmbedderTest {};
TEST_F(FPDFAttachmentEmbeddertest, ExtractAttachments) {
@@ -37,25 +40,21 @@ TEST_F(FPDFAttachmentEmbeddertest, ExtractAttachments) {
EXPECT_EQ(std::string("test"), std::string(buf.data(), 4));
// Check that a non-existent key does not exist.
- EXPECT_FALSE(
- FPDFAttachment_HasKey(attachment, GetFPDFWideString(L"none").get()));
+ EXPECT_FALSE(FPDFAttachment_HasKey(attachment, "none"));
// Check that the string value of a non-string dictionary entry is empty.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> size_key =
- GetFPDFWideString(L"Size");
+ static constexpr char kSizeKey[] = "Size";
EXPECT_EQ(FPDF_OBJECT_NUMBER,
- FPDFAttachment_GetValueType(attachment, size_key.get()));
- EXPECT_EQ(2u, FPDFAttachment_GetStringValue(attachment, size_key.get(),
- nullptr, 0));
+ FPDFAttachment_GetValueType(attachment, kSizeKey));
+ EXPECT_EQ(2u,
+ FPDFAttachment_GetStringValue(attachment, kSizeKey, nullptr, 0));
// Check that the creation date of the first attachment is correct.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> date_key =
- GetFPDFWideString(L"CreationDate");
- len = FPDFAttachment_GetStringValue(attachment, date_key.get(), nullptr, 0);
+ len = FPDFAttachment_GetStringValue(attachment, kDateKey, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment, date_key.get(),
- buf.data(), len));
+ EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment, kDateKey, buf.data(),
+ len));
EXPECT_STREQ(L"D:20170712214438-07'00'",
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
.c_str());
@@ -78,13 +77,10 @@ TEST_F(FPDFAttachmentEmbeddertest, ExtractAttachments) {
EXPECT_EQ(kCheckSum, generated_checksum);
// Check that the stored checksum matches expectation.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> checksum_key =
- GetFPDFWideString(L"CheckSum");
- len =
- FPDFAttachment_GetStringValue(attachment, checksum_key.get(), nullptr, 0);
+ len = FPDFAttachment_GetStringValue(attachment, kChecksumKey, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, checksum_key.get(),
+ EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, kChecksumKey,
buf.data(), len));
EXPECT_EQ(kCheckSumW,
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())));
@@ -171,21 +167,17 @@ TEST_F(FPDFAttachmentEmbeddertest, AddAttachmentsWithParams) {
strlen(kContents)));
// Set the date to be an arbitrary value.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> date_key =
- GetFPDFWideString(L"CreationDate");
constexpr wchar_t kDateW[] = L"D:20170720161527-04'00'";
std::unique_ptr<unsigned short, pdfium::FreeDeleter> ws_date =
GetFPDFWideString(kDateW);
EXPECT_TRUE(
- FPDFAttachment_SetStringValue(attachment, date_key.get(), ws_date.get()));
+ FPDFAttachment_SetStringValue(attachment, kDateKey, ws_date.get()));
// Set the checksum to be an arbitrary value.
- std::unique_ptr<unsigned short, pdfium::FreeDeleter> checksum_key =
- GetFPDFWideString(L"CheckSum");
constexpr wchar_t kCheckSumW[] = L"<ABCDEF01234567899876543210FEDCBA>";
std::unique_ptr<unsigned short, pdfium::FreeDeleter> ws_checksum =
GetFPDFWideString(kCheckSumW);
- EXPECT_TRUE(FPDFAttachment_SetStringValue(attachment, checksum_key.get(),
+ EXPECT_TRUE(FPDFAttachment_SetStringValue(attachment, kChecksumKey,
ws_checksum.get()));
// Verify the name of the new attachment (i.e. the second attachment).
@@ -206,21 +198,20 @@ TEST_F(FPDFAttachmentEmbeddertest, AddAttachmentsWithParams) {
EXPECT_EQ(std::string(kContents), std::string(buf.data(), 12));
// Verify the creation date of the new attachment.
- len = FPDFAttachment_GetStringValue(attachment, date_key.get(), nullptr, 0);
+ len = FPDFAttachment_GetStringValue(attachment, kDateKey, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment, date_key.get(),
- buf.data(), len));
+ EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment, kDateKey, buf.data(),
+ len));
EXPECT_STREQ(kDateW,
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
.c_str());
// Verify the checksum of the new attachment.
- len =
- FPDFAttachment_GetStringValue(attachment, checksum_key.get(), nullptr, 0);
+ len = FPDFAttachment_GetStringValue(attachment, kChecksumKey, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, checksum_key.get(),
+ EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, kChecksumKey,
buf.data(), len));
EXPECT_STREQ(kCheckSumW,
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data()))
@@ -230,11 +221,10 @@ TEST_F(FPDFAttachmentEmbeddertest, AddAttachmentsWithParams) {
// gets updated to the correct value.
EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), nullptr, 0));
EXPECT_EQ(0u, FPDFAttachment_GetFile(attachment, nullptr, 0));
- len =
- FPDFAttachment_GetStringValue(attachment, checksum_key.get(), nullptr, 0);
+ len = FPDFAttachment_GetStringValue(attachment, kChecksumKey, nullptr, 0);
buf.clear();
buf.resize(len);
- EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, checksum_key.get(),
+ EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment, kChecksumKey,
buf.data(), len));
EXPECT_EQ(L"<D41D8CD98F00B204E9800998ECF8427E>",
GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())));