summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfview_embeddertest.cpp
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-11-04 16:07:25 -0700
committerCommit bot <commit-bot@chromium.org>2016-11-04 16:07:25 -0700
commit04bebfe590d6d27a825b881fd234e31501843edc (patch)
tree127477b084005457579c599b2ec9eef0668a1479 /fpdfsdk/fpdfview_embeddertest.cpp
parent931d087b991a986cc8bfa72131fe8eda0d987fc4 (diff)
downloadpdfium-04bebfe590d6d27a825b881fd234e31501843edc.tar.xz
Implement FPDF_VIEWERREF_GetName() API.chromium/2910
This is a generic API function to retrieve any viewer preference of type name. BUG=pdfium:414 Review-Url: https://codereview.chromium.org/2475923003
Diffstat (limited to 'fpdfsdk/fpdfview_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfview_embeddertest.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/fpdfsdk/fpdfview_embeddertest.cpp b/fpdfsdk/fpdfview_embeddertest.cpp
index 820d496bdc..e712edb89a 100644
--- a/fpdfsdk/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/fpdfview_embeddertest.cpp
@@ -56,6 +56,10 @@ TEST_F(FPDFViewEmbeddertest, EmptyDocument) {
EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
+ char buf[100];
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
+
EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
}
@@ -69,11 +73,53 @@ TEST_F(FPDFViewEmbeddertest, Page) {
EXPECT_EQ(nullptr, LoadPage(1));
}
-TEST_F(FPDFViewEmbeddertest, ViewerRef) {
+TEST_F(FPDFViewEmbeddertest, ViewerRefDummy) {
EXPECT_TRUE(OpenDocument("about_blank.pdf"));
EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
+
+ char buf[100];
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
+}
+
+TEST_F(FPDFViewEmbeddertest, ViewerRef) {
+ EXPECT_TRUE(OpenDocument("viewer_ref.pdf"));
+ EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
+ EXPECT_EQ(5, FPDF_VIEWERREF_GetNumCopies(document()));
+ EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
+
+ // Test some corner cases.
+ char buf[100];
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "", buf, sizeof(buf)));
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
+ EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
+
+ // Make sure |buf| does not get written into when it appears to be too small.
+ strcpy(buf, "ABCD");
+ EXPECT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, 1));
+ EXPECT_STREQ("ABCD", buf);
+
+ // Note "Foo" is a different key from "foo".
+ EXPECT_EQ(4U,
+ FPDF_VIEWERREF_GetName(document(), "Foo", nullptr, sizeof(buf)));
+ ASSERT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, sizeof(buf)));
+ EXPECT_STREQ("foo", buf);
+
+ // Try to retrieve a boolean and an integer.
+ EXPECT_EQ(
+ 0U, FPDF_VIEWERREF_GetName(document(), "HideToolbar", buf, sizeof(buf)));
+ EXPECT_EQ(0U,
+ FPDF_VIEWERREF_GetName(document(), "NumCopies", buf, sizeof(buf)));
+
+ // Try more valid cases.
+ ASSERT_EQ(4U,
+ FPDF_VIEWERREF_GetName(document(), "Direction", buf, sizeof(buf)));
+ EXPECT_STREQ("R2L", buf);
+ ASSERT_EQ(8U,
+ FPDF_VIEWERREF_GetName(document(), "ViewArea", buf, sizeof(buf)));
+ EXPECT_STREQ("CropBox", buf);
}
TEST_F(FPDFViewEmbeddertest, NamedDests) {