| 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 <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
| 11 #include "core/fpdfdoc/include/cpdf_filespec.h" | 11 #include "core/fpdfdoc/include/cpdf_filespec.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/test_support.h" | 13 #include "testing/test_support.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using ScopedObj = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; | 17 using ScopedObj = std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>>; |
| 18 using ScopedDict = | 18 using ScopedDict = |
| 19 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; | 19 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>>; |
| 20 } | 20 } |
| 21 | 21 |
| 22 TEST(doc_basic_filespec, EncodeDecodeFileName) { | 22 TEST(cpdf_filespec, EncodeDecodeFileName) { |
| 23 std::vector<pdfium::NullTermWstrFuncTestData> test_data = { | 23 std::vector<pdfium::NullTermWstrFuncTestData> test_data = { |
| 24 // Empty src string. | 24 // Empty src string. |
| 25 {L"", L""}, | 25 {L"", L""}, |
| 26 // only file name. | 26 // only file name. |
| 27 {L"test.pdf", L"test.pdf"}, | 27 {L"test.pdf", L"test.pdf"}, |
| 28 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 28 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 29 // With drive identifier. | 29 // With drive identifier. |
| 30 {L"r:\\pdfdocs\\spec.pdf", L"/r/pdfdocs/spec.pdf"}, | 30 {L"r:\\pdfdocs\\spec.pdf", L"/r/pdfdocs/spec.pdf"}, |
| 31 // Relative path. | 31 // Relative path. |
| 32 {L"My Document\\test.pdf", L"My Document/test.pdf"}, | 32 {L"My Document\\test.pdf", L"My Document/test.pdf"}, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 == 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 == data.input); | 58 EXPECT_TRUE(decoded_str == data.input); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(doc_basic_filespec, GetFileName) { | 62 TEST(cpdf_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 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 132 TEST(doc_basic_filespec, SetFileName) { | 132 TEST(cpdf_filespec, SetFileName) { |
| 133 pdfium::NullTermWstrFuncTestData test_data = { | 133 pdfium::NullTermWstrFuncTestData test_data = { |
| 134 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 134 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 135 L"C:\\docs\\test.pdf", | 135 L"C:\\docs\\test.pdf", |
| 136 L"/C/docs/test.pdf" | 136 L"/C/docs/test.pdf" |
| 137 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 137 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 138 L"Mac HD:docs:test.pdf", | 138 L"Mac HD:docs:test.pdf", |
| 139 L"/Mac HD/docs/test.pdf" | 139 L"/Mac HD/docs/test.pdf" |
| 140 #else | 140 #else |
| 141 L"/docs/test.pdf", | 141 L"/docs/test.pdf", |
| 142 L"/docs/test.pdf" | 142 L"/docs/test.pdf" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 == 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 == 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 == test_data.input); | 168 EXPECT_TRUE(file_name == test_data.input); |
| 169 } | 169 } |
| OLD | NEW |