Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cpdf_creator_embeddertest.cpp
Go to the documentation of this file.
1
// Copyright 2017 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
include
<
string
.
h
>
6
7
#
include
<
string
>
8
9
#
include
"public/cpp/fpdf_scopers.h"
10
#
include
"public/fpdf_annot.h"
11
#
include
"public/fpdf_edit.h"
12
#
include
"public/fpdfview.h"
13
#
include
"testing/embedder_test.h"
14
#
include
"testing/fake_file_access.h"
15
#
include
"testing/gmock/include/gmock/gmock-matchers.h"
16
#
include
"testing/gtest/include/gtest/gtest.h"
17
#
include
"testing/utils/file_util.h"
18
19
class
CPDF_CreatorEmbedderTest
:
public
EmbedderTest
{};
20
21
TEST_F
(
CPDF_CreatorEmbedderTest
,
SavedDocsAreEqualAfterParse
) {
22
ASSERT_TRUE(OpenDocument(
"annotation_stamp_with_ap.pdf"
));
23
// Save without additional data reading.
24
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
25
const
std
::string saved_doc_1 = GetString();
26
ClearString();
27
28
{
29
// Do some read only operations.
30
ASSERT_GE(1, FPDF_GetPageCount(document()));
31
FPDF_PAGE page = LoadPage(0);
32
ASSERT_TRUE(page);
33
ScopedFPDFBitmap bitmap = RenderLoadedPageWithFlags(page,
FPDF_ANNOT
);
34
EXPECT_EQ(595, FPDFBitmap_GetWidth(bitmap.get()));
35
EXPECT_EQ(842, FPDFBitmap_GetHeight(bitmap.get()));
36
UnloadPage(page);
37
}
38
39
// Save when we have additional loaded data.
40
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
41
const
std
::string saved_doc_2 = GetString();
42
ClearString();
43
44
// The sizes of saved docs should be equal.
45
EXPECT_EQ(saved_doc_1.size(), saved_doc_2.size());
46
}
47
48
TEST_F
(
CPDF_CreatorEmbedderTest
,
Bug873
) {
49
ASSERT_TRUE(OpenDocument(
"embedded_attachments.pdf"
));
50
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
51
52
// Cannot match second part of the ID since it is randomly generated.
53
std
::string saved_data = GetString();
54
const
char
kTrailerBeforeSecondID[] =
55
"trailer\r\n<</Info 9 0 R /Root 11 0 R /Size "
56
"36/ID[<D889EB6B9ADF88E5EDA7DC08FE85978B><"
;
57
ASSERT_THAT(saved_data, testing::HasSubstr(kTrailerBeforeSecondID));
58
size_t trailer_start = saved_data.find(kTrailerBeforeSecondID);
59
constexpr
size_t kIdLen = 32;
60
size_t trailer_continuation =
61
trailer_start + strlen(kTrailerBeforeSecondID) + kIdLen;
62
std
::string data_after_second_id = saved_data.substr(trailer_continuation);
63
EXPECT_THAT(data_after_second_id, testing::StartsWith(
">]>>\r\n"
));
64
}
65
66
TEST_F
(
CPDF_CreatorEmbedderTest
,
SaveLinearizedInfo
) {
67
FileAccessForTesting file_acc(
"linearized.pdf"
);
68
FakeFileAccess
fake_acc(&file_acc);
69
70
CreateAvail(fake_acc
.
GetFileAvail
(
)
, fake_acc
.
GetFileAccess
(
)
);
71
while
(
PDF_DATA_AVAIL
!=
72
FPDFAvail_IsDocAvail(avail(), fake_acc
.
GetDownloadHints
(
)
)) {
73
fake_acc
.
SetRequestedDataAvailable
(
)
;
74
}
75
76
SetDocumentFromAvail();
77
ASSERT_TRUE(document());
78
79
// Load second page, to parse additional crossref sections.
80
while
(
PDF_DATA_AVAIL
!=
81
FPDFAvail_IsPageAvail(avail(), 1, fake_acc
.
GetDownloadHints
(
)
)) {
82
fake_acc
.
SetRequestedDataAvailable
(
)
;
83
}
84
// Simulate downloading of whole file.
85
fake_acc
.
SetWholeFileAvailable
(
)
;
86
// Save document.
87
EXPECT_TRUE(FPDF_SaveAsCopy(document(),
this
, 0));
88
const
std
::string saved_doc = GetString();
89
90
EXPECT_THAT(saved_doc, ::testing::HasSubstr(
"/Info"
));
91
}
CPDF_CreatorEmbedderTest
Definition
cpdf_creator_embeddertest.cpp:19
EmbedderTest
Definition
embedder_test.h:40
FakeFileAccess
Definition
fake_file_access.h:19
FakeFileAccess::SetRequestedDataAvailable
void SetRequestedDataAvailable()
Definition
fake_file_access.cpp:116
FakeFileAccess::SetWholeFileAvailable
void SetWholeFileAvailable()
Definition
fake_file_access.cpp:121
FakeFileAccess::GetDownloadHints
FX_DOWNLOADHINTS * GetDownloadHints() const
Definition
fake_file_access.cpp:88
FakeFileAccess::GetFileAvail
FX_FILEAVAIL * GetFileAvail() const
Definition
fake_file_access.cpp:84
FakeFileAccess::GetFileAccess
FPDF_FILEACCESS * GetFileAccess() const
Definition
fake_file_access.cpp:80
TEST_F
TEST_F(CPDF_CreatorEmbedderTest, SavedDocsAreEqualAfterParse)
Definition
cpdf_creator_embeddertest.cpp:21
PDF_DATA_AVAIL
#define PDF_DATA_AVAIL
Definition
fpdf_dataavail.h:21
FPDF_ANNOT
#define FPDF_ANNOT
Definition
fpdfview.h:790
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfapi
edit
cpdf_creator_embeddertest.cpp
Generated on
for Qt by
1.18.0