Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: core/fpdfdoc/cpdf_filespec_unittest.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_filespec.cpp ('k') | core/fpdfdoc/cpdf_formcontrol.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/parser/cpdf_dictionary.h" 8 #include "core/fpdfapi/parser/cpdf_dictionary.h"
9 #include "core/fpdfapi/parser/cpdf_name.h" 9 #include "core/fpdfapi/parser/cpdf_name.h"
10 #include "core/fpdfapi/parser/cpdf_string.h" 10 #include "core/fpdfapi/parser/cpdf_string.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 L"/C/docs/test.pdf", 60 L"/C/docs/test.pdf",
61 L"C:\\docs\\test.pdf" 61 L"C:\\docs\\test.pdf"
62 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 62 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
63 L"/Mac HD/docs/test.pdf", 63 L"/Mac HD/docs/test.pdf",
64 L"Mac HD:docs:test.pdf" 64 L"Mac HD:docs:test.pdf"
65 #else 65 #else
66 L"/docs/test.pdf", 66 L"/docs/test.pdf",
67 L"/docs/test.pdf" 67 L"/docs/test.pdf"
68 #endif 68 #endif
69 }; 69 };
70 std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(test_data.input)); 70 std::unique_ptr<CPDF_Object> str_obj(
71 new CPDF_String(nullptr, test_data.input));
71 CPDF_FileSpec file_spec(str_obj.get()); 72 CPDF_FileSpec file_spec(str_obj.get());
72 CFX_WideString file_name; 73 CFX_WideString file_name;
73 EXPECT_TRUE(file_spec.GetFileName(&file_name)); 74 EXPECT_TRUE(file_spec.GetFileName(&file_name));
74 EXPECT_TRUE(file_name == test_data.expected); 75 EXPECT_TRUE(file_name == test_data.expected);
75 } 76 }
76 { 77 {
77 // Dictionary object. 78 // Dictionary object.
78 pdfium::NullTermWstrFuncTestData test_data[5] = { 79 pdfium::NullTermWstrFuncTestData test_data[5] = {
79 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 80 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
80 {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"}, 81 {L"/C/docs/test.pdf", L"C:\\docs\\test.pdf"},
(...skipping 14 matching lines...) Expand all
95 {L"/docs/d/test.pdf", L"/docs/d/test.pdf"}, 96 {L"/docs/d/test.pdf", L"/docs/d/test.pdf"},
96 {L"/docs/e/test.pdf", L"/docs/e/test.pdf"}, 97 {L"/docs/e/test.pdf", L"/docs/e/test.pdf"},
97 #endif 98 #endif
98 }; 99 };
99 // Keyword fields in reverse order of precedence to retrieve the file name. 100 // Keyword fields in reverse order of precedence to retrieve the file name.
100 const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"}; 101 const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"};
101 std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary()); 102 std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary());
102 CPDF_FileSpec file_spec(dict_obj.get()); 103 CPDF_FileSpec file_spec(dict_obj.get());
103 CFX_WideString file_name; 104 CFX_WideString file_name;
104 for (int i = 0; i < 5; ++i) { 105 for (int i = 0; i < 5; ++i) {
105 dict_obj->SetFor(keywords[i], new CPDF_String(test_data[i].input)); 106 dict_obj->SetNewFor<CPDF_String>(keywords[i], test_data[i].input);
106 EXPECT_TRUE(file_spec.GetFileName(&file_name)); 107 EXPECT_TRUE(file_spec.GetFileName(&file_name));
107 EXPECT_TRUE(file_name == test_data[i].expected); 108 EXPECT_TRUE(file_name == test_data[i].expected);
108 } 109 }
109 110
110 // With all the former fields and 'FS' field suggests 'URL' type. 111 // With all the former fields and 'FS' field suggests 'URL' type.
111 dict_obj->SetStringFor("FS", "URL"); 112 dict_obj->SetNewFor<CPDF_String>("FS", "URL", false);
112 EXPECT_TRUE(file_spec.GetFileName(&file_name)); 113 EXPECT_TRUE(file_spec.GetFileName(&file_name));
113 // Url string is not decoded. 114 // Url string is not decoded.
114 EXPECT_TRUE(file_name == test_data[4].input); 115 EXPECT_TRUE(file_name == test_data[4].input);
115 } 116 }
116 { 117 {
117 // Invalid object. 118 // Invalid object.
118 std::unique_ptr<CPDF_Object> name_obj(new CPDF_Name(nullptr, "test.pdf")); 119 std::unique_ptr<CPDF_Object> name_obj(new CPDF_Name(nullptr, "test.pdf"));
119 CPDF_FileSpec file_spec(name_obj.get()); 120 CPDF_FileSpec file_spec(name_obj.get());
120 CFX_WideString file_name; 121 CFX_WideString file_name;
121 EXPECT_FALSE(file_spec.GetFileName(&file_name)); 122 EXPECT_FALSE(file_spec.GetFileName(&file_name));
122 } 123 }
123 } 124 }
124 125
125 TEST(cpdf_filespec, SetFileName) { 126 TEST(cpdf_filespec, SetFileName) {
126 pdfium::NullTermWstrFuncTestData test_data = { 127 pdfium::NullTermWstrFuncTestData test_data = {
127 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 128 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
128 L"C:\\docs\\test.pdf", 129 L"C:\\docs\\test.pdf",
129 L"/C/docs/test.pdf" 130 L"/C/docs/test.pdf"
130 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 131 #elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
131 L"Mac HD:docs:test.pdf", 132 L"Mac HD:docs:test.pdf",
132 L"/Mac HD/docs/test.pdf" 133 L"/Mac HD/docs/test.pdf"
133 #else 134 #else
134 L"/docs/test.pdf", 135 L"/docs/test.pdf",
135 L"/docs/test.pdf" 136 L"/docs/test.pdf"
136 #endif 137 #endif
137 }; 138 };
138 // String object. 139 // String object.
139 std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(L"babababa")); 140 std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(nullptr, L"babababa"));
140 CPDF_FileSpec file_spec1(str_obj.get()); 141 CPDF_FileSpec file_spec1(str_obj.get());
141 file_spec1.SetFileName(test_data.input); 142 file_spec1.SetFileName(test_data.input);
142 // Check internal object value. 143 // Check internal object value.
143 CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected); 144 CFX_ByteString str = CFX_ByteString::FromUnicode(test_data.expected);
144 EXPECT_TRUE(str == str_obj->GetString()); 145 EXPECT_TRUE(str == str_obj->GetString());
145 // Check we can get the file name back. 146 // Check we can get the file name back.
146 CFX_WideString file_name; 147 CFX_WideString file_name;
147 EXPECT_TRUE(file_spec1.GetFileName(&file_name)); 148 EXPECT_TRUE(file_spec1.GetFileName(&file_name));
148 EXPECT_TRUE(file_name == test_data.input); 149 EXPECT_TRUE(file_name == test_data.input);
149 150
150 // Dictionary object. 151 // Dictionary object.
151 std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary()); 152 std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary());
152 CPDF_FileSpec file_spec2(dict_obj.get()); 153 CPDF_FileSpec file_spec2(dict_obj.get());
153 file_spec2.SetFileName(test_data.input); 154 file_spec2.SetFileName(test_data.input);
154 // Check internal object value. 155 // Check internal object value.
155 file_name = dict_obj->GetUnicodeTextFor("F"); 156 file_name = dict_obj->GetUnicodeTextFor("F");
156 EXPECT_TRUE(file_name == test_data.expected); 157 EXPECT_TRUE(file_name == test_data.expected);
157 file_name = dict_obj->GetUnicodeTextFor("UF"); 158 file_name = dict_obj->GetUnicodeTextFor("UF");
158 EXPECT_TRUE(file_name == test_data.expected); 159 EXPECT_TRUE(file_name == test_data.expected);
159 // Check we can get the file name back. 160 // Check we can get the file name back.
160 EXPECT_TRUE(file_spec2.GetFileName(&file_name)); 161 EXPECT_TRUE(file_spec2.GetFileName(&file_name));
161 EXPECT_TRUE(file_name == test_data.input); 162 EXPECT_TRUE(file_name == test_data.input);
162 } 163 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_filespec.cpp ('k') | core/fpdfdoc/cpdf_formcontrol.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698