24 static const std::vector<pdfium::NullTermWstrFuncTestData> test_data = {
28 {L"test.pdf", L"test.pdf"},
31 {L"r:\\pdfdocs\\spec.pdf", L"/r/pdfdocs/spec.pdf"},
33 {L"My Document\\test.pdf", L"My Document/test.pdf"},
35 {L"\\pdfdocs\\spec.pdf", L"//pdfdocs/spec.pdf"},
37 {L"\\\\pdfdocs\\spec.pdf", L"/pdfdocs/spec.pdf"},
40#elif BUILDFLAG(IS_APPLE)
42 {L"Mac HD:PDFDocs:spec.pdf", L"/Mac HD/PDFDocs/spec.pdf"},
44 {L"PDFDocs:spec.pdf", L"PDFDocs/spec.pdf"},
47 {L"./docs/test.pdf", L"./docs/test.pdf"},
49 {L"../test_docs/test.pdf", L"../test_docs/test.pdf"},
51 {L"/usr/local/home/test.pdf", L"/usr/local/home/test.pdf"},
54 for (
const auto& data : test_data) {
55 EXPECT_STREQ(data.expected,
56 CPDF_FileSpec::EncodeFileName(data.input).c_str());
58 EXPECT_STREQ(data.input,
59 CPDF_FileSpec::DecodeFileName(data.expected).c_str());
70#elif BUILDFLAG(IS_APPLE)
71 L"/Mac HD/docs/test.pdf",
72 L"Mac HD:docs:test.pdf"
78 auto str_obj = pdfium::MakeRetain<CPDF_String>(
nullptr, test_data
.input);
86 {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"},
87 {L"/D/docs/test.pdf", L"D:\\docs\\test.pdf"},
88 {L"/E/docs/test.pdf", L"E:\\docs\\test.pdf"},
89 {L"/F/docs/test.pdf", L"F:\\docs\\test.pdf"},
90 {L"/G/docs/test.pdf", L"G:\\docs\\test.pdf"},
91#elif BUILDFLAG(IS_APPLE)
92 {L"/Mac HD/docs1/test.pdf", L"Mac HD:docs1:test.pdf"},
93 {L"/Mac HD/docs2/test.pdf", L"Mac HD:docs2:test.pdf"},
94 {L"/Mac HD/docs3/test.pdf", L"Mac HD:docs3:test.pdf"},
95 {L"/Mac HD/docs4/test.pdf", L"Mac HD:docs4:test.pdf"},
96 {L"/Mac HD/docs5/test.pdf", L"Mac HD:docs5:test.pdf"},
98 {L"/docs/a/test.pdf", L"/docs/a/test.pdf"},
99 {L"/docs/b/test.pdf", L"/docs/b/test.pdf"},
100 {L"/docs/c/test.pdf", L"/docs/c/test.pdf"},
101 {L"/docs/d/test.pdf", L"/docs/d/test.pdf"},
102 {L"/docs/e/test.pdf", L"/docs/e/test.pdf"},
106 const char*
const keywords[] = {
"Unix",
"Mac",
"DOS",
"F",
"UF"};
107 static_assert(
std::size(test_data) ==
std::size(keywords),
"size mismatch");
108 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
111 for (size_t i = 0; i <
std::size(keywords); ++i) {
112 dict_obj->SetNewFor<CPDF_String>(keywords[i], test_data[i].input);
117 dict_obj->SetNewFor<CPDF_String>(
"FS",
"URL",
false);
123 auto name_obj = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"test.pdf");
129 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
131 for (
const char* key : {
"Unix",
"Mac",
"DOS",
"F",
"UF"}) {
132 dict_obj->SetNewFor<CPDF_Name>(key,
"http://evil.org");
133 EXPECT_TRUE(file_spec.GetFileName().IsEmpty());
135 dict_obj->SetNewFor<CPDF_String>(
"FS",
"URL",
false);
143 auto name_obj = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"test.pdf");
149 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
155 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
156 dict_obj->SetNewFor<CPDF_Dictionary>(
"EF");
163 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
164 dict_obj->SetNewFor<CPDF_Dictionary>(
"EF");
167 const wchar_t file_name[] = L"test.pdf";
168 const char*
const keys[] = {
"Unix",
"Mac",
"DOS",
"F",
"UF"};
169 const char*
const streams[] = {
"test1",
"test2",
"test3",
"test4",
"test5"};
170 static_assert(
std::size(keys) ==
std::size(streams),
"size mismatch");
171 RetainPtr<CPDF_Dictionary> file_dict = dict_obj->GetMutableDictFor(
"EF");
174 for (size_t i = 0; i <
std::size(keys); ++i) {
176 dict_obj->SetNewFor<CPDF_String>(keys[i], file_name);
179 size_t buf_len = strlen(streams[i]) + 1;
180 auto stream_object = object_holder.NewIndirect<CPDF_Stream>(
181 DataVector<uint8_t>(streams[i], streams[i] + buf_len),
182 pdfium::MakeRetain<CPDF_Dictionary>());
183 ASSERT_TRUE(stream_object);
184 const uint32_t stream_object_number = stream_object->GetObjNum();
185 ASSERT_GT(stream_object_number, 0u);
186 file_dict->SetNewFor<CPDF_Reference>(keys[i], &object_holder,
187 stream_object_number);
192 file_spec.GetFileStream()->GetUnicodeText().ToUTF8().c_str());
195 dict_obj->SetNewFor<CPDF_String>(
"FS",
"URL",
false);
205 auto name_obj = pdfium::MakeRetain<CPDF_Name>(
nullptr,
"test.pdf");
213 auto dict_obj = pdfium::MakeRetain<CPDF_Dictionary>();
214 dict_obj->SetNewFor<CPDF_Dictionary>(
"EF");
215 dict_obj->SetNewFor<CPDF_String>(
"UF", L"test.pdf");
220 RetainPtr<CPDF_Dictionary> file_dict = dict_obj->GetMutableDictFor(
"EF");
221 static constexpr char kHello[] =
"hello";
222 auto stream_object = object_holder.NewIndirect<CPDF_Stream>(
223 DataVector<uint8_t>(
std::begin(kHello),
std::end(kHello)),
224 pdfium::MakeRetain<CPDF_Dictionary>());
225 ASSERT_TRUE(stream_object);
226 const uint32_t stream_object_number = stream_object->GetObjNum();
227 ASSERT_GT(stream_object_number, 0u);
228 file_dict->SetNewFor<CPDF_Reference>(
"UF", &object_holder,
229 stream_object_number);
232 RetainPtr<CPDF_Stream> stream = file_dict->GetMutableStreamFor(
"UF");
233 RetainPtr<CPDF_Dictionary> stream_dict = stream->GetMutableDict();
234 stream_dict->SetNewFor<CPDF_Dictionary>(
"Params");
239 stream_dict->GetMutableDictFor(
"Params");
240 params_dict->SetNewFor<CPDF_Number>(
"Size", 6);
241 EXPECT_EQ(6, file_spec.GetParamsDict()->GetIntegerFor(
"Size"));