OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/include/fpdfdoc/fpdf_doc.h" | 5 #include "core/include/fpdfdoc/fpdf_doc.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Relative path. | 45 // Relative path. |
46 {L"./docs/test.pdf", L"./docs/test.pdf"}, | 46 {L"./docs/test.pdf", L"./docs/test.pdf"}, |
47 // Relative path with parent dir. | 47 // Relative path with parent dir. |
48 {L"../test_docs/test.pdf", L"../test_docs/test.pdf"}, | 48 {L"../test_docs/test.pdf", L"../test_docs/test.pdf"}, |
49 // Absolute path. | 49 // Absolute path. |
50 {L"/usr/local/home/test.pdf", L"/usr/local/home/test.pdf"}, | 50 {L"/usr/local/home/test.pdf", L"/usr/local/home/test.pdf"}, |
51 #endif | 51 #endif |
52 }; | 52 }; |
53 for (const auto& data : test_data) { | 53 for (const auto& data : test_data) { |
54 CFX_WideString encoded_str = CPDF_FileSpec::EncodeFileName(data.input); | 54 CFX_WideString encoded_str = CPDF_FileSpec::EncodeFileName(data.input); |
55 EXPECT_TRUE(encoded_str.Equal(data.expected)); | 55 EXPECT_TRUE(encoded_str == data.expected); |
56 // DecodeFileName is the reverse procedure of EncodeFileName. | 56 // DecodeFileName is the reverse procedure of EncodeFileName. |
57 CFX_WideString decoded_str = CPDF_FileSpec::DecodeFileName(data.expected); | 57 CFX_WideString decoded_str = CPDF_FileSpec::DecodeFileName(data.expected); |
58 EXPECT_TRUE(decoded_str.Equal(data.input)); | 58 EXPECT_TRUE(decoded_str == data.input); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 TEST(doc_basic_filespec, GetFileName) { | 62 TEST(doc_basic_filespec, GetFileName) { |
63 { | 63 { |
64 // String object. | 64 // String object. |
65 pdfium::NullTermWstrFuncTestData test_data = { | 65 pdfium::NullTermWstrFuncTestData test_data = { |
66 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 66 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
67 L"/C/docs/test.pdf", | 67 L"/C/docs/test.pdf", |
68 L"C:\\docs\\test.pdf" | 68 L"C:\\docs\\test.pdf" |
69 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 69 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
70 L"/Mac HD/docs/test.pdf", | 70 L"/Mac HD/docs/test.pdf", |
71 L"Mac HD:docs:test.pdf" | 71 L"Mac HD:docs:test.pdf" |
72 #else | 72 #else |
73 L"/docs/test.pdf", | 73 L"/docs/test.pdf", |
74 L"/docs/test.pdf" | 74 L"/docs/test.pdf" |
75 #endif | 75 #endif |
76 }; | 76 }; |
77 ScopedObj str_obj(new CPDF_String(test_data.input)); | 77 ScopedObj str_obj(new CPDF_String(test_data.input)); |
78 CPDF_FileSpec file_spec(str_obj.get()); | 78 CPDF_FileSpec file_spec(str_obj.get()); |
79 CFX_WideString file_name; | 79 CFX_WideString file_name; |
80 EXPECT_TRUE(file_spec.GetFileName(&file_name)); | 80 EXPECT_TRUE(file_spec.GetFileName(&file_name)); |
81 EXPECT_TRUE(file_name.Equal(test_data.expected)); | 81 EXPECT_TRUE(file_name == test_data.expected); |
82 } | 82 } |
83 { | 83 { |
84 // Dictionary object. | 84 // Dictionary object. |
85 pdfium::NullTermWstrFuncTestData test_data[5] = { | 85 pdfium::NullTermWstrFuncTestData test_data[5] = { |
86 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 86 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
87 {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"}, | 87 {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"}, |
88 {L"/D/docs/test.pdf", L"D:\\docs\\test.pdf"}, | 88 {L"/D/docs/test.pdf", L"D:\\docs\\test.pdf"}, |
89 {L"/E/docs/test.pdf", L"E:\\docs\\test.pdf"}, | 89 {L"/E/docs/test.pdf", L"E:\\docs\\test.pdf"}, |
90 {L"/F/docs/test.pdf", L"F:\\docs\\test.pdf"}, | 90 {L"/F/docs/test.pdf", L"F:\\docs\\test.pdf"}, |
91 {L"/G/docs/test.pdf", L"G:\\docs\\test.pdf"}, | 91 {L"/G/docs/test.pdf", L"G:\\docs\\test.pdf"}, |
(...skipping 12 matching lines...) Expand all Loading... |
104 #endif | 104 #endif |
105 }; | 105 }; |
106 // Keyword fields in reverse order of precedence to retrieve the file name. | 106 // Keyword fields in reverse order of precedence to retrieve the file name. |
107 const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"}; | 107 const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"}; |
108 ScopedDict dict_obj(new CPDF_Dictionary); | 108 ScopedDict dict_obj(new CPDF_Dictionary); |
109 CPDF_FileSpec file_spec(dict_obj.get()); | 109 CPDF_FileSpec file_spec(dict_obj.get()); |
110 CFX_WideString file_name; | 110 CFX_WideString file_name; |
111 for (int i = 0; i < 5; ++i) { | 111 for (int i = 0; i < 5; ++i) { |
112 dict_obj->SetAt(keywords[i], new CPDF_String(test_data[i].input)); | 112 dict_obj->SetAt(keywords[i], new CPDF_String(test_data[i].input)); |
113 EXPECT_TRUE(file_spec.GetFileName(&file_name)); | 113 EXPECT_TRUE(file_spec.GetFileName(&file_name)); |
114 EXPECT_TRUE(file_name.Equal(test_data[i].expected)); | 114 EXPECT_TRUE(file_name == test_data[i].expected); |
115 } | 115 } |
116 | 116 |
117 // With all the former fields and 'FS' field suggests 'URL' type. | 117 // With all the former fields and 'FS' field suggests 'URL' type. |
118 dict_obj->SetAtString("FS", "URL"); | 118 dict_obj->SetAtString("FS", "URL"); |
119 EXPECT_TRUE(file_spec.GetFileName(&file_name)); | 119 EXPECT_TRUE(file_spec.GetFileName(&file_name)); |
120 // Url string is not decoded. | 120 // Url string is not decoded. |
121 EXPECT_TRUE(file_name.Equal(test_data[4].input)); | 121 EXPECT_TRUE(file_name == test_data[4].input); |
122 } | 122 } |
123 { | 123 { |
124 // Invalid object. | 124 // Invalid object. |
125 ScopedObj name_obj(new CPDF_Name("test.pdf")); | 125 ScopedObj name_obj(new CPDF_Name("test.pdf")); |
126 CPDF_FileSpec file_spec(name_obj.get()); | 126 CPDF_FileSpec file_spec(name_obj.get()); |
127 CFX_WideString file_name; | 127 CFX_WideString file_name; |
128 EXPECT_FALSE(file_spec.GetFileName(&file_name)); | 128 EXPECT_FALSE(file_spec.GetFileName(&file_name)); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
(...skipping 13 matching lines...) Expand all Loading... |
145 // String object. | 145 // String object. |
146 ScopedObj str_obj(new CPDF_String(L"babababa")); | 146 ScopedObj str_obj(new CPDF_String(L"babababa")); |
147 CPDF_FileSpec file_spec1(str_obj.get()); | 147 CPDF_FileSpec file_spec1(str_obj.get()); |
148 file_spec1.SetFileName(test_data.input); | 148 file_spec1.SetFileName(test_data.input); |
149 // Check internal object value. | 149 // Check internal object value. |
150 CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected); | 150 CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected); |
151 EXPECT_TRUE(str == str_obj->GetString()); | 151 EXPECT_TRUE(str == str_obj->GetString()); |
152 // Check we can get the file name back. | 152 // Check we can get the file name back. |
153 CFX_WideString file_name; | 153 CFX_WideString file_name; |
154 EXPECT_TRUE(file_spec1.GetFileName(&file_name)); | 154 EXPECT_TRUE(file_spec1.GetFileName(&file_name)); |
155 EXPECT_TRUE(file_name.Equal(test_data.input)); | 155 EXPECT_TRUE(file_name == test_data.input); |
156 | 156 |
157 // Dictionary object. | 157 // Dictionary object. |
158 ScopedDict dict_obj(new CPDF_Dictionary); | 158 ScopedDict dict_obj(new CPDF_Dictionary); |
159 CPDF_FileSpec file_spec2(dict_obj.get()); | 159 CPDF_FileSpec file_spec2(dict_obj.get()); |
160 file_spec2.SetFileName(test_data.input); | 160 file_spec2.SetFileName(test_data.input); |
161 // Check internal object value. | 161 // Check internal object value. |
162 file_name = dict_obj->GetUnicodeTextBy("F"); | 162 file_name = dict_obj->GetUnicodeTextBy("F"); |
163 EXPECT_TRUE(file_name.Equal(test_data.expected)); | 163 EXPECT_TRUE(file_name == test_data.expected); |
164 file_name = dict_obj->GetUnicodeTextBy("UF"); | 164 file_name = dict_obj->GetUnicodeTextBy("UF"); |
165 EXPECT_TRUE(file_name.Equal(test_data.expected)); | 165 EXPECT_TRUE(file_name == test_data.expected); |
166 // Check we can get the file name back. | 166 // Check we can get the file name back. |
167 EXPECT_TRUE(file_spec2.GetFileName(&file_name)); | 167 EXPECT_TRUE(file_spec2.GetFileName(&file_name)); |
168 EXPECT_TRUE(file_name.Equal(test_data.input)); | 168 EXPECT_TRUE(file_name == test_data.input); |
169 } | 169 } |
OLD | NEW |