Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: fpdfsdk/fpdfview_embeddertest.cpp

Issue 2475923003: Implement FPDF_VIEWERREF_GetName() API. (Closed)
Patch Set: Comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fpdfview_c_api_test.c ('k') | public/fpdf_doc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 PDFium Authors. All rights reserved. 1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 #include <string> 6 #include <string>
7 7
8 #include "fpdfsdk/fpdfview_c_api_test.h" 8 #include "fpdfsdk/fpdfview_c_api_test.h"
9 #include "public/fpdfview.h" 9 #include "public/fpdfview.h"
10 #include "testing/embedder_test.h" 10 #include "testing/embedder_test.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document())); 51 EXPECT_EQ(-1, FPDF_GetSecurityHandlerRevision(document()));
52 52
53 EXPECT_EQ(0, FPDF_GetPageCount(document())); 53 EXPECT_EQ(0, FPDF_GetPageCount(document()));
54 54
55 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document())); 55 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
56 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document())); 56 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
57 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document())); 57 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
58 58
59 char buf[100];
60 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
61 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
62
59 EXPECT_EQ(0u, FPDF_CountNamedDests(document())); 63 EXPECT_EQ(0u, FPDF_CountNamedDests(document()));
60 } 64 }
61 65
62 TEST_F(FPDFViewEmbeddertest, Page) { 66 TEST_F(FPDFViewEmbeddertest, Page) {
63 EXPECT_TRUE(OpenDocument("about_blank.pdf")); 67 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
64 FPDF_PAGE page = LoadPage(0); 68 FPDF_PAGE page = LoadPage(0);
65 EXPECT_NE(nullptr, page); 69 EXPECT_NE(nullptr, page);
66 EXPECT_EQ(612.0, FPDF_GetPageWidth(page)); 70 EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
67 EXPECT_EQ(792.0, FPDF_GetPageHeight(page)); 71 EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
68 UnloadPage(page); 72 UnloadPage(page);
69 EXPECT_EQ(nullptr, LoadPage(1)); 73 EXPECT_EQ(nullptr, LoadPage(1));
70 } 74 }
71 75
72 TEST_F(FPDFViewEmbeddertest, ViewerRef) { 76 TEST_F(FPDFViewEmbeddertest, ViewerRefDummy) {
73 EXPECT_TRUE(OpenDocument("about_blank.pdf")); 77 EXPECT_TRUE(OpenDocument("about_blank.pdf"));
74 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document())); 78 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
75 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document())); 79 EXPECT_EQ(1, FPDF_VIEWERREF_GetNumCopies(document()));
76 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document())); 80 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
81
82 char buf[100];
83 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
84 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
85 }
86
87 TEST_F(FPDFViewEmbeddertest, ViewerRef) {
88 EXPECT_TRUE(OpenDocument("viewer_ref.pdf"));
89 EXPECT_TRUE(FPDF_VIEWERREF_GetPrintScaling(document()));
90 EXPECT_EQ(5, FPDF_VIEWERREF_GetNumCopies(document()));
91 EXPECT_EQ(DuplexUndefined, FPDF_VIEWERREF_GetDuplex(document()));
92
93 // Test some corner cases.
94 char buf[100];
95 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "", buf, sizeof(buf)));
96 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", nullptr, 0));
97 EXPECT_EQ(0U, FPDF_VIEWERREF_GetName(document(), "foo", buf, sizeof(buf)));
98
99 // Make sure |buf| does not get written into when it appears to be too small.
100 strcpy(buf, "ABCD");
101 EXPECT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, 1));
102 EXPECT_STREQ("ABCD", buf);
103
104 // Note "Foo" is a different key from "foo".
105 EXPECT_EQ(4U,
106 FPDF_VIEWERREF_GetName(document(), "Foo", nullptr, sizeof(buf)));
107 ASSERT_EQ(4U, FPDF_VIEWERREF_GetName(document(), "Foo", buf, sizeof(buf)));
108 EXPECT_STREQ("foo", buf);
109
110 // Try to retrieve a boolean and an integer.
111 EXPECT_EQ(
112 0U, FPDF_VIEWERREF_GetName(document(), "HideToolbar", buf, sizeof(buf)));
113 EXPECT_EQ(0U,
114 FPDF_VIEWERREF_GetName(document(), "NumCopies", buf, sizeof(buf)));
115
116 // Try more valid cases.
117 ASSERT_EQ(4U,
118 FPDF_VIEWERREF_GetName(document(), "Direction", buf, sizeof(buf)));
119 EXPECT_STREQ("R2L", buf);
120 ASSERT_EQ(8U,
121 FPDF_VIEWERREF_GetName(document(), "ViewArea", buf, sizeof(buf)));
122 EXPECT_STREQ("CropBox", buf);
77 } 123 }
78 124
79 TEST_F(FPDFViewEmbeddertest, NamedDests) { 125 TEST_F(FPDFViewEmbeddertest, NamedDests) {
80 EXPECT_TRUE(OpenDocument("named_dests.pdf")); 126 EXPECT_TRUE(OpenDocument("named_dests.pdf"));
81 long buffer_size; 127 long buffer_size;
82 char fixed_buffer[512]; 128 char fixed_buffer[512];
83 FPDF_DEST dest; 129 FPDF_DEST dest;
84 130
85 // Query the size of the first item. 131 // Query the size of the first item.
86 buffer_size = 2000000; // Absurdly large, check not used for this case. 132 buffer_size = 2000000; // Absurdly large, check not used for this case.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 319
274 // The test should pass when there is no infinite recursion in 320 // The test should pass when there is no infinite recursion in
275 // CPDF_SyntaxParser::GetString(). 321 // CPDF_SyntaxParser::GetString().
276 TEST_F(FPDFViewEmbeddertest, Hang_355) { 322 TEST_F(FPDFViewEmbeddertest, Hang_355) {
277 EXPECT_FALSE(OpenDocument("bug_355.pdf")); 323 EXPECT_FALSE(OpenDocument("bug_355.pdf"));
278 } 324 }
279 // The test should pass even when the file has circular references to pages. 325 // The test should pass even when the file has circular references to pages.
280 TEST_F(FPDFViewEmbeddertest, Hang_360) { 326 TEST_F(FPDFViewEmbeddertest, Hang_360) {
281 EXPECT_FALSE(OpenDocument("bug_360.pdf")); 327 EXPECT_FALSE(OpenDocument("bug_360.pdf"));
282 } 328 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfview_c_api_test.c ('k') | public/fpdf_doc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698