OLD | NEW |
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/src/fpdfview_c_api_test.h" | 8 #include "fpdfsdk/src/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 Loading... |
49 TEST_F(FPDFViewEmbeddertest, NamedDests) { | 49 TEST_F(FPDFViewEmbeddertest, NamedDests) { |
50 EXPECT_TRUE(OpenDocument("named_dests.pdf")); | 50 EXPECT_TRUE(OpenDocument("named_dests.pdf")); |
51 long buffer_size; | 51 long buffer_size; |
52 char fixed_buffer[512]; | 52 char fixed_buffer[512]; |
53 FPDF_DEST dest; | 53 FPDF_DEST dest; |
54 | 54 |
55 // Query the size of the first item. | 55 // Query the size of the first item. |
56 buffer_size = 2000000; // Absurdly large, check not used for this case. | 56 buffer_size = 2000000; // Absurdly large, check not used for this case. |
57 dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size); | 57 dest = FPDF_GetNamedDest(document(), 0, nullptr, &buffer_size); |
58 EXPECT_NE(nullptr, dest); | 58 EXPECT_NE(nullptr, dest); |
59 EXPECT_EQ(12u, buffer_size); | 59 EXPECT_EQ(10u, buffer_size); |
60 | 60 |
61 // Try to retrieve the first item with too small a buffer. | 61 // Try to retrieve the first item with too small a buffer. |
62 buffer_size = 10; | 62 buffer_size = 8; |
63 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); | 63 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); |
64 EXPECT_NE(nullptr, dest); | 64 EXPECT_NE(nullptr, dest); |
65 EXPECT_EQ(-1, buffer_size); | 65 EXPECT_EQ(-1, buffer_size); |
66 | 66 |
67 // Try to retrieve the first item with correctly sized buffer. Item is | 67 // Try to retrieve the first item with correctly sized buffer. Item is |
68 // taken from Dests NameTree in named_dests.pdf. | 68 // taken from Dests NameTree in named_dests.pdf. |
69 buffer_size = 12; | 69 buffer_size = 12; |
70 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); | 70 dest = FPDF_GetNamedDest(document(), 0, fixed_buffer, &buffer_size); |
71 EXPECT_NE(nullptr, dest); | 71 EXPECT_NE(nullptr, dest); |
72 EXPECT_EQ(12u, buffer_size); | 72 EXPECT_EQ(10u, buffer_size); |
73 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0\0\0", 12), | 73 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0", 10), |
74 std::string(fixed_buffer, buffer_size)); | 74 std::string(fixed_buffer, buffer_size)); |
75 | 75 |
76 // Try to retrieve the second item with ample buffer. Item is taken | 76 // Try to retrieve the second item with ample buffer. Item is taken |
77 // from Dests NameTree but has a sub-dictionary in named_dests.pdf. | 77 // from Dests NameTree but has a sub-dictionary in named_dests.pdf. |
78 buffer_size = sizeof(fixed_buffer); | 78 buffer_size = sizeof(fixed_buffer); |
79 dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size); | 79 dest = FPDF_GetNamedDest(document(), 1, fixed_buffer, &buffer_size); |
80 EXPECT_NE(nullptr, dest); | 80 EXPECT_NE(nullptr, dest); |
81 EXPECT_EQ(10u, buffer_size); | 81 EXPECT_EQ(8u, buffer_size); |
82 EXPECT_EQ(std::string("N\0e\0x\0t\0\0\0", 10), | 82 EXPECT_EQ(std::string("N\0e\0x\0t\0", 8), |
83 std::string(fixed_buffer, buffer_size)); | 83 std::string(fixed_buffer, buffer_size)); |
84 | 84 |
85 // Try to retrieve third item with ample buffer. Item is taken | 85 // Try to retrieve third item with ample buffer. Item is taken |
86 // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf. | 86 // from Dests NameTree but has a bad sub-dictionary in named_dests.pdf. |
87 // in named_dests.pdf). | 87 // in named_dests.pdf). |
88 buffer_size = sizeof(fixed_buffer); | 88 buffer_size = sizeof(fixed_buffer); |
89 dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size); | 89 dest = FPDF_GetNamedDest(document(), 2, fixed_buffer, &buffer_size); |
90 EXPECT_EQ(nullptr, dest); | 90 EXPECT_EQ(nullptr, dest); |
91 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. | 91 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. |
92 | 92 |
93 // Try to retrieve the forth item with ample buffer. Item is taken | 93 // Try to retrieve the forth item with ample buffer. Item is taken |
94 // from Dests NameTree but has a vale of the wrong type in named_dests.pdf. | 94 // from Dests NameTree but has a vale of the wrong type in named_dests.pdf. |
95 buffer_size = sizeof(fixed_buffer); | 95 buffer_size = sizeof(fixed_buffer); |
96 dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size); | 96 dest = FPDF_GetNamedDest(document(), 3, fixed_buffer, &buffer_size); |
97 EXPECT_EQ(nullptr, dest); | 97 EXPECT_EQ(nullptr, dest); |
98 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. | 98 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. |
99 | 99 |
100 // Try to retrieve fifth item with ample buffer. Item taken from the | 100 // Try to retrieve fifth item with ample buffer. Item taken from the |
101 // old-style Dests dictionary object in named_dests.pdf. | 101 // old-style Dests dictionary object in named_dests.pdf. |
102 buffer_size = sizeof(fixed_buffer); | 102 buffer_size = sizeof(fixed_buffer); |
103 dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size); | 103 dest = FPDF_GetNamedDest(document(), 4, fixed_buffer, &buffer_size); |
104 EXPECT_NE(nullptr, dest); | 104 EXPECT_NE(nullptr, dest); |
105 EXPECT_EQ(30u, buffer_size); | 105 EXPECT_EQ(28u, buffer_size); |
106 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 30), | 106 EXPECT_EQ(std::string("F\0i\0r\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0", 28), |
107 std::string(fixed_buffer, buffer_size)); | 107 std::string(fixed_buffer, buffer_size)); |
108 | 108 |
109 // Try to retrieve sixth item with ample buffer. Item istaken from the | 109 // Try to retrieve sixth item with ample buffer. Item istaken from the |
110 // old-style Dests dictionary object but has a sub-dictionary in | 110 // old-style Dests dictionary object but has a sub-dictionary in |
111 // named_dests.pdf. | 111 // named_dests.pdf. |
112 buffer_size = sizeof(fixed_buffer); | 112 buffer_size = sizeof(fixed_buffer); |
113 dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size); | 113 dest = FPDF_GetNamedDest(document(), 5, fixed_buffer, &buffer_size); |
114 EXPECT_NE(nullptr, dest); | 114 EXPECT_NE(nullptr, dest); |
115 EXPECT_EQ(28u, buffer_size); | 115 EXPECT_EQ(26u, buffer_size); |
116 EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0\0\0", 28), | 116 EXPECT_EQ(std::string("L\0a\0s\0t\0A\0l\0t\0e\0r\0n\0a\0t\0e\0", 26), |
117 std::string(fixed_buffer, buffer_size)); | 117 std::string(fixed_buffer, buffer_size)); |
118 | 118 |
119 // Try to retrieve non-existent item with ample buffer. | 119 // Try to retrieve non-existent item with ample buffer. |
120 buffer_size = sizeof(fixed_buffer); | 120 buffer_size = sizeof(fixed_buffer); |
121 dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size); | 121 dest = FPDF_GetNamedDest(document(), 6, fixed_buffer, &buffer_size); |
122 EXPECT_EQ(nullptr, dest); | 122 EXPECT_EQ(nullptr, dest); |
123 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. | 123 EXPECT_EQ(sizeof(fixed_buffer), buffer_size); // unmodified. |
124 | 124 |
125 // Try to underflow/overflow the integer index. | 125 // Try to underflow/overflow the integer index. |
126 buffer_size = sizeof(fixed_buffer); | 126 buffer_size = sizeof(fixed_buffer); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 EXPECT_TRUE(OpenDocument("bug_452455.pdf")); | 192 EXPECT_TRUE(OpenDocument("bug_452455.pdf")); |
193 FPDF_PAGE page = LoadPage(0); | 193 FPDF_PAGE page = LoadPage(0); |
194 EXPECT_NE(nullptr, page); | 194 EXPECT_NE(nullptr, page); |
195 UnloadPage(page); | 195 UnloadPage(page); |
196 } | 196 } |
197 | 197 |
198 TEST_F(FPDFViewEmbeddertest, Crasher_454695) { | 198 TEST_F(FPDFViewEmbeddertest, Crasher_454695) { |
199 // Document is damanged and can't be opened. | 199 // Document is damanged and can't be opened. |
200 EXPECT_FALSE(OpenDocument("bug_454695.pdf")); | 200 EXPECT_FALSE(OpenDocument("bug_454695.pdf")); |
201 } | 201 } |
OLD | NEW |