summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfdoc_embeddertest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-09-14 12:58:41 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-09-14 20:40:32 +0000
commit188cf0cfc6b9dabc4454eba17685410e714b3f9d (patch)
treebc001096842327098711e4e45acc1976fdc83be4 /fpdfsdk/fpdfdoc_embeddertest.cpp
parentbdd98abbce31e6b8b73c55865ab5ede14e9931ab (diff)
downloadpdfium-188cf0cfc6b9dabc4454eba17685410e714b3f9d.tar.xz
Add tests for FPDF_GetMetaText().
Change-Id: I8d2eaea9696b6ac4ea7ba5cb323bf74546c31d46 Reviewed-on: https://pdfium-review.googlesource.com/13890 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfdoc_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfdoc_embeddertest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfdoc_embeddertest.cpp b/fpdfsdk/fpdfdoc_embeddertest.cpp
index f069ec2631..781af1e67e 100644
--- a/fpdfsdk/fpdfdoc_embeddertest.cpp
+++ b/fpdfsdk/fpdfdoc_embeddertest.cpp
@@ -182,6 +182,40 @@ TEST_F(FPDFDocEmbeddertest, DeletePage) {
EXPECT_EQ(0, FPDF_GetPageCount(document()));
}
+TEST_F(FPDFDocEmbeddertest, GetMetaText) {
+ ASSERT_TRUE(OpenDocument("bug_601362.pdf"));
+
+ // Invalid document / tag results in 0.
+ unsigned short buf[128];
+ EXPECT_EQ(0u, FPDF_GetMetaText(document(), nullptr, buf, sizeof(buf)));
+ EXPECT_EQ(0u, FPDF_GetMetaText(nullptr, "", buf, sizeof(buf)));
+
+ // Tags that do not eixst results in an empty wide string.
+ EXPECT_EQ(2u, FPDF_GetMetaText(document(), "", buf, sizeof(buf)));
+ EXPECT_EQ(2u, FPDF_GetMetaText(document(), "foo", buf, sizeof(buf)));
+ ASSERT_EQ(2u, FPDF_GetMetaText(document(), "Title", buf, sizeof(buf)));
+ ASSERT_EQ(2u, FPDF_GetMetaText(document(), "Author", buf, sizeof(buf)));
+ ASSERT_EQ(2u, FPDF_GetMetaText(document(), "Subject", buf, sizeof(buf)));
+ ASSERT_EQ(2u, FPDF_GetMetaText(document(), "Keywords", buf, sizeof(buf)));
+ ASSERT_EQ(2u, FPDF_GetMetaText(document(), "Producer", buf, sizeof(buf)));
+
+ constexpr wchar_t kExpectedCreator[] = L"Microsoft Word";
+ ASSERT_EQ(30u, FPDF_GetMetaText(document(), "Creator", buf, sizeof(buf)));
+ EXPECT_EQ(CFX_WideString(kExpectedCreator),
+ CFX_WideString::FromUTF16LE(buf, FXSYS_len(kExpectedCreator)));
+
+ constexpr wchar_t kExpectedCreationDate[] = L"D:20160411190039+00'00'";
+ ASSERT_EQ(48u,
+ FPDF_GetMetaText(document(), "CreationDate", buf, sizeof(buf)));
+ EXPECT_EQ(CFX_WideString(kExpectedCreationDate),
+ CFX_WideString::FromUTF16LE(buf, FXSYS_len(kExpectedCreationDate)));
+
+ constexpr wchar_t kExpectedModDate[] = L"D:20160411190039+00'00'";
+ ASSERT_EQ(48u, FPDF_GetMetaText(document(), "ModDate", buf, sizeof(buf)));
+ EXPECT_EQ(CFX_WideString(kExpectedModDate),
+ CFX_WideString::FromUTF16LE(buf, FXSYS_len(kExpectedModDate)));
+}
+
TEST_F(FPDFDocEmbeddertest, NoPageLabels) {
EXPECT_TRUE(OpenDocument("about_blank.pdf"));
EXPECT_EQ(1, FPDF_GetPageCount(document()));