22 ASSERT_TRUE(OpenDocument(
"embedded_attachments.pdf"));
23 EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
26 EXPECT_FALSE(FPDFDoc_GetAttachment(document(), -1));
27 EXPECT_FALSE(FPDFDoc_GetAttachment(document(), 2));
30 FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0);
31 ASSERT_TRUE(attachment);
35 ASSERT_EQ(12u, length_bytes);
36 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
37 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
38 EXPECT_EQ(L"1.txt", GetPlatformWString(buf.data()));
46 std::vector<uint8_t> content_buf(length_bytes);
47 unsigned long actual_length_bytes;
48 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
49 length_bytes, &actual_length_bytes));
50 ASSERT_THAT(content_buf, testing::ElementsAre(
't',
'e',
's',
't'));
56 static constexpr char kSizeKey[] =
"Size";
65 ASSERT_EQ(48u, length_bytes);
66 buf = GetFPDFWideStringBuffer(length_bytes);
67 EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment,
kDateKey, buf.data(),
69 EXPECT_EQ(L"D:20170712214438-07'00'", GetPlatformWString(buf.data()));
72 attachment = FPDFDoc_GetAttachment(document(), 1);
73 ASSERT_TRUE(attachment);
78 content_buf.resize(length_bytes);
79 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
80 length_bytes, &actual_length_bytes));
81 ASSERT_EQ(5869u, actual_length_bytes);
84 const char kCheckSum[] =
"72afcddedf554dda63c0c88e06f1ce18";
85 const wchar_t kCheckSumW[] = L"<72AFCDDEDF554DDA63C0C88E06F1CE18>";
86 const std::string generated_checksum = GenerateMD5Base16(content_buf);
87 EXPECT_EQ(kCheckSum, generated_checksum);
92 ASSERT_EQ(70u, length_bytes);
93 buf = GetFPDFWideStringBuffer(length_bytes);
94 EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment,
kChecksumKey,
95 buf.data(), length_bytes));
96 EXPECT_EQ(kCheckSumW, GetPlatformWString(buf.data()));
111 ASSERT_TRUE(OpenDocument(
"embedded_attachments_invalid_data.pdf"));
112 ASSERT_EQ(1, FPDFDoc_GetAttachmentCount(document()));
115 FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0);
116 ASSERT_TRUE(attachment);
120 ASSERT_EQ(12u, length_bytes);
121 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
122 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
123 EXPECT_EQ(
"1.txt", GetPlatformString(buf.data()));
129 EXPECT_TRUE(FPDFDoc_DeleteAttachment(document(), 0));
130 EXPECT_EQ(0, FPDFDoc_GetAttachmentCount(document()));
135 ASSERT_TRUE(OpenDocument(
"embedded_attachments.pdf"));
136 EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
139 EXPECT_FALSE(FPDFDoc_AddAttachment(document(),
nullptr));
142 ScopedFPDFWideString file_name = GetFPDFWideString(L"0.txt");
143 FPDF_ATTACHMENT attachment =
144 FPDFDoc_AddAttachment(document(), file_name.get());
145 ASSERT_TRUE(attachment);
148 EXPECT_FALSE(FPDFAttachment_SetFile(attachment, document(),
nullptr, 10));
151 constexpr char kContents1[] =
"Hello!";
152 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), kContents1,
153 strlen(kContents1)));
154 EXPECT_EQ(3, FPDFDoc_GetAttachmentCount(document()));
157 attachment = FPDFDoc_GetAttachment(document(), 0);
158 ASSERT_TRUE(attachment);
160 ASSERT_EQ(12u, length_bytes);
161 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
162 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
163 EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data()));
167 std::vector<
char> content_buf(length_bytes);
168 unsigned long actual_length_bytes;
169 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
170 length_bytes, &actual_length_bytes));
171 ASSERT_EQ(6u, actual_length_bytes);
172 EXPECT_EQ(std::string(kContents1),
std::string(content_buf.data(), 6));
175 file_name = GetFPDFWideString(L"z.txt");
176 attachment = FPDFDoc_AddAttachment(document(), file_name.get());
177 ASSERT_TRUE(attachment);
178 constexpr char kContents2[] =
"World!";
179 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), kContents2,
180 strlen(kContents2)));
181 EXPECT_EQ(4, FPDFDoc_GetAttachmentCount(document()));
184 attachment = FPDFDoc_GetAttachment(document(), 3);
185 ASSERT_TRUE(attachment);
187 ASSERT_EQ(12u, length_bytes);
188 buf = GetFPDFWideStringBuffer(length_bytes);
189 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
190 EXPECT_EQ(L"z.txt", GetPlatformWString(buf.data()));
195 content_buf.resize(length_bytes);
196 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
197 length_bytes, &actual_length_bytes));
198 ASSERT_EQ(6u, actual_length_bytes);
199 EXPECT_EQ(std::string(kContents2),
std::string(content_buf.data(), 6));
204 ASSERT_TRUE(OpenDocument(
"embedded_attachments.pdf"));
205 EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
208 ScopedFPDFWideString file_name = GetFPDFWideString(L"5.txt");
209 FPDF_ATTACHMENT attachment =
210 FPDFDoc_AddAttachment(document(), file_name.get());
211 ASSERT_TRUE(attachment);
212 constexpr char kContents[] =
"Hello World!";
213 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), kContents,
217 constexpr wchar_t kDateW[] = L"D:20170720161527-04'00'";
218 ScopedFPDFWideString ws_date = GetFPDFWideString(kDateW);
220 FPDFAttachment_SetStringValue(attachment,
kDateKey, ws_date.get()));
223 constexpr wchar_t kCheckSumW[] = L"<ABCDEF01234567899876543210FEDCBA>";
224 ScopedFPDFWideString ws_checksum = GetFPDFWideString(kCheckSumW);
225 EXPECT_TRUE(FPDFAttachment_SetStringValue(attachment,
kChecksumKey,
229 attachment = FPDFDoc_GetAttachment(document(), 1);
230 ASSERT_TRUE(attachment);
232 ASSERT_EQ(12u, length_bytes);
233 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
234 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
235 EXPECT_EQ(L"5.txt", GetPlatformWString(buf.data()));
239 std::vector<
char> content_buf(length_bytes);
240 unsigned long actual_length_bytes;
241 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
242 length_bytes, &actual_length_bytes));
243 ASSERT_EQ(12u, actual_length_bytes);
244 EXPECT_EQ(std::string(kContents),
std::string(content_buf.data(), 12));
249 ASSERT_EQ(48u, length_bytes);
250 buf = GetFPDFWideStringBuffer(length_bytes);
251 EXPECT_EQ(48u, FPDFAttachment_GetStringValue(attachment,
kDateKey, buf.data(),
253 EXPECT_EQ(kDateW, GetPlatformWString(buf.data()));
258 ASSERT_EQ(70u, length_bytes);
259 buf = GetFPDFWideStringBuffer(length_bytes);
260 EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment,
kChecksumKey,
261 buf.data(), length_bytes));
262 EXPECT_EQ(kCheckSumW, GetPlatformWString(buf.data()));
266 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(),
nullptr, 0));
268 EXPECT_EQ(0u, length_bytes);
271 ASSERT_EQ(70u, length_bytes);
272 buf = GetFPDFWideStringBuffer(length_bytes);
273 EXPECT_EQ(70u, FPDFAttachment_GetStringValue(attachment,
kChecksumKey,
274 buf.data(), length_bytes));
275 EXPECT_EQ(L"<D41D8CD98F00B204E9800998ECF8427E>",
276 GetPlatformWString(buf.data()));
281 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
282 EXPECT_EQ(0, FPDFDoc_GetAttachmentCount(document()));
285 ScopedFPDFWideString file_name = GetFPDFWideString(L"0.txt");
286 FPDF_ATTACHMENT attachment =
287 FPDFDoc_AddAttachment(document(), file_name.get());
288 ASSERT_TRUE(attachment);
291 constexpr char kContents1[] =
"Hello!";
292 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), kContents1,
293 strlen(kContents1)));
294 EXPECT_EQ(1, FPDFDoc_GetAttachmentCount(document()));
297 attachment = FPDFDoc_GetAttachment(document(), 0);
298 ASSERT_TRUE(attachment);
300 ASSERT_EQ(12u, length_bytes);
301 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
302 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
303 EXPECT_EQ(L"0.txt", GetPlatformWString(buf.data()));
307 std::vector<
char> content_buf(length_bytes);
308 unsigned long actual_length_bytes;
309 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
310 length_bytes, &actual_length_bytes));
311 ASSERT_EQ(6u, actual_length_bytes);
312 EXPECT_EQ(std::string(kContents1),
std::string(content_buf.data(), 6));
315 file_name = GetFPDFWideString(L"z.txt");
316 attachment = FPDFDoc_AddAttachment(document(), file_name.get());
317 ASSERT_TRUE(attachment);
318 constexpr char kContents2[] =
"World!";
319 EXPECT_TRUE(FPDFAttachment_SetFile(attachment, document(), kContents2,
320 strlen(kContents2)));
321 EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
324 attachment = FPDFDoc_GetAttachment(document(), 1);
325 ASSERT_TRUE(attachment);
327 ASSERT_EQ(12u, length_bytes);
328 buf = GetFPDFWideStringBuffer(length_bytes);
329 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
330 EXPECT_EQ(L"z.txt", GetPlatformWString(buf.data()));
335 content_buf.resize(length_bytes);
336 ASSERT_TRUE(FPDFAttachment_GetFile(attachment, content_buf.data(),
337 length_bytes, &actual_length_bytes));
338 ASSERT_EQ(6u, actual_length_bytes);
339 EXPECT_EQ(std::string(kContents2),
std::string(content_buf.data(), 6));
344 ASSERT_TRUE(OpenDocument(
"embedded_attachments.pdf"));
345 EXPECT_EQ(2, FPDFDoc_GetAttachmentCount(document()));
348 FPDF_ATTACHMENT attachment = FPDFDoc_GetAttachment(document(), 0);
349 ASSERT_TRUE(attachment);
351 ASSERT_EQ(12u, length_bytes);
352 std::vector<FPDF_WCHAR> buf = GetFPDFWideStringBuffer(length_bytes);
353 EXPECT_EQ(12u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
354 EXPECT_EQ(L"1.txt", GetPlatformWString(buf.data()));
357 EXPECT_TRUE(FPDFDoc_DeleteAttachment(document(), 0));
358 EXPECT_EQ(1, FPDFDoc_GetAttachmentCount(document()));
361 attachment = FPDFDoc_GetAttachment(document(), 0);
362 ASSERT_TRUE(attachment);
364 ASSERT_EQ(26u, length_bytes);
365 buf = GetFPDFWideStringBuffer(length_bytes);
366 EXPECT_EQ(26u, FPDFAttachment_GetName(attachment, buf.data(), length_bytes));
367 EXPECT_EQ(L"attached.pdf", GetPlatformWString(buf.data()));