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

Side by Side Diff: minidump/minidump_simple_string_dictionary_writer_test.cc

Issue 936153002: Add FileReaderInterface. Move StringFileWriter to StringFile and (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused #include Created 5 years, 10 months 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 | « minidump/minidump_rva_list_writer_test.cc ('k') | minidump/minidump_string_writer_test.cc » ('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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_simple_string_dictionary_writer.h" 15 #include "minidump/minidump_simple_string_dictionary_writer.h"
16 16
17 #include <map> 17 #include <map>
18 #include <string> 18 #include <string>
19 19
20 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
21 #include "minidump/minidump_extensions.h" 21 #include "minidump/minidump_extensions.h"
22 #include "minidump/test/minidump_string_writer_test_util.h" 22 #include "minidump/test/minidump_string_writer_test_util.h"
23 #include "minidump/test/minidump_writable_test_util.h" 23 #include "minidump/test/minidump_writable_test_util.h"
24 #include "util/file/string_file_writer.h" 24 #include "util/file/string_file.h"
25 25
26 namespace crashpad { 26 namespace crashpad {
27 namespace test { 27 namespace test {
28 namespace { 28 namespace {
29 29
30 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart( 30 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart(
31 const std::string& file_contents, 31 const std::string& file_contents,
32 size_t count) { 32 size_t count) {
33 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor; 33 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
34 location_descriptor.DataSize = 34 location_descriptor.DataSize =
35 sizeof(MinidumpSimpleStringDictionary) + 35 sizeof(MinidumpSimpleStringDictionary) +
36 count * sizeof(MinidumpSimpleStringDictionaryEntry); 36 count * sizeof(MinidumpSimpleStringDictionaryEntry);
37 location_descriptor.Rva = 0; 37 location_descriptor.Rva = 0;
38 return MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>( 38 return MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
39 file_contents, location_descriptor); 39 file_contents, location_descriptor);
40 } 40 }
41 41
42 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) { 42 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) {
43 StringFileWriter file_writer; 43 StringFile string_file;
44 44
45 MinidumpSimpleStringDictionaryWriter dictionary_writer; 45 MinidumpSimpleStringDictionaryWriter dictionary_writer;
46 46
47 EXPECT_FALSE(dictionary_writer.IsUseful()); 47 EXPECT_FALSE(dictionary_writer.IsUseful());
48 48
49 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 49 EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
50 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary), 50 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary),
51 file_writer.string().size()); 51 string_file.string().size());
52 52
53 const MinidumpSimpleStringDictionary* dictionary = 53 const MinidumpSimpleStringDictionary* dictionary =
54 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 0); 54 MinidumpSimpleStringDictionaryAtStart(string_file.string(), 0);
55 ASSERT_TRUE(dictionary); 55 ASSERT_TRUE(dictionary);
56 EXPECT_EQ(0u, dictionary->count); 56 EXPECT_EQ(0u, dictionary->count);
57 } 57 }
58 58
59 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) { 59 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
60 StringFileWriter file_writer; 60 StringFile string_file;
61 61
62 MinidumpSimpleStringDictionaryWriter dictionary_writer; 62 MinidumpSimpleStringDictionaryWriter dictionary_writer;
63 auto entry_writer = 63 auto entry_writer =
64 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 64 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
65 dictionary_writer.AddEntry(entry_writer.Pass()); 65 dictionary_writer.AddEntry(entry_writer.Pass());
66 66
67 EXPECT_TRUE(dictionary_writer.IsUseful()); 67 EXPECT_TRUE(dictionary_writer.IsUseful());
68 68
69 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 69 EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
70 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 70 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
71 sizeof(MinidumpSimpleStringDictionaryEntry) + 71 sizeof(MinidumpSimpleStringDictionaryEntry) +
72 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding 72 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding
73 file_writer.string().size()); 73 string_file.string().size());
74 74
75 const MinidumpSimpleStringDictionary* dictionary = 75 const MinidumpSimpleStringDictionary* dictionary =
76 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 76 MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
77 ASSERT_TRUE(dictionary); 77 ASSERT_TRUE(dictionary);
78 EXPECT_EQ(1u, dictionary->count); 78 EXPECT_EQ(1u, dictionary->count);
79 EXPECT_EQ(12u, dictionary->entries[0].key); 79 EXPECT_EQ(12u, dictionary->entries[0].key);
80 EXPECT_EQ(20u, dictionary->entries[0].value); 80 EXPECT_EQ(20u, dictionary->entries[0].value);
81 EXPECT_EQ("", 81 EXPECT_EQ("",
82 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 82 MinidumpUTF8StringAtRVAAsString(string_file.string(),
83 dictionary->entries[0].key)); 83 dictionary->entries[0].key));
84 EXPECT_EQ("", 84 EXPECT_EQ("",
85 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 85 MinidumpUTF8StringAtRVAAsString(string_file.string(),
86 dictionary->entries[0].value)); 86 dictionary->entries[0].value));
87 } 87 }
88 88
89 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) { 89 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) {
90 StringFileWriter file_writer; 90 StringFile string_file;
91 91
92 char kKey[] = "key"; 92 char kKey[] = "key";
93 char kValue[] = "value"; 93 char kValue[] = "value";
94 94
95 MinidumpSimpleStringDictionaryWriter dictionary_writer; 95 MinidumpSimpleStringDictionaryWriter dictionary_writer;
96 auto entry_writer = 96 auto entry_writer =
97 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 97 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
98 entry_writer->SetKeyValue(kKey, kValue); 98 entry_writer->SetKeyValue(kKey, kValue);
99 dictionary_writer.AddEntry(entry_writer.Pass()); 99 dictionary_writer.AddEntry(entry_writer.Pass());
100 100
101 EXPECT_TRUE(dictionary_writer.IsUseful()); 101 EXPECT_TRUE(dictionary_writer.IsUseful());
102 102
103 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 103 EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
104 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 104 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
105 sizeof(MinidumpSimpleStringDictionaryEntry) + 105 sizeof(MinidumpSimpleStringDictionaryEntry) +
106 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue), 106 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue),
107 file_writer.string().size()); 107 string_file.string().size());
108 108
109 const MinidumpSimpleStringDictionary* dictionary = 109 const MinidumpSimpleStringDictionary* dictionary =
110 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 110 MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
111 ASSERT_TRUE(dictionary); 111 ASSERT_TRUE(dictionary);
112 EXPECT_EQ(1u, dictionary->count); 112 EXPECT_EQ(1u, dictionary->count);
113 EXPECT_EQ(12u, dictionary->entries[0].key); 113 EXPECT_EQ(12u, dictionary->entries[0].key);
114 EXPECT_EQ(20u, dictionary->entries[0].value); 114 EXPECT_EQ(20u, dictionary->entries[0].value);
115 EXPECT_EQ(kKey, 115 EXPECT_EQ(kKey,
116 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 116 MinidumpUTF8StringAtRVAAsString(string_file.string(),
117 dictionary->entries[0].key)); 117 dictionary->entries[0].key));
118 EXPECT_EQ(kValue, 118 EXPECT_EQ(kValue,
119 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 119 MinidumpUTF8StringAtRVAAsString(string_file.string(),
120 dictionary->entries[0].value)); 120 dictionary->entries[0].value));
121 } 121 }
122 122
123 TEST(MinidumpSimpleStringDictionaryWriter, ThreeKeysValues) { 123 TEST(MinidumpSimpleStringDictionaryWriter, ThreeKeysValues) {
124 StringFileWriter file_writer; 124 StringFile string_file;
125 125
126 char kKey0[] = "m0"; 126 char kKey0[] = "m0";
127 char kValue0[] = "value0"; 127 char kValue0[] = "value0";
128 char kKey1[] = "zzz1"; 128 char kKey1[] = "zzz1";
129 char kValue1[] = "v1"; 129 char kValue1[] = "v1";
130 char kKey2[] = "aa2"; 130 char kKey2[] = "aa2";
131 char kValue2[] = "val2"; 131 char kValue2[] = "val2";
132 132
133 MinidumpSimpleStringDictionaryWriter dictionary_writer; 133 MinidumpSimpleStringDictionaryWriter dictionary_writer;
134 auto entry_writer_0 = 134 auto entry_writer_0 =
135 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 135 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
136 entry_writer_0->SetKeyValue(kKey0, kValue0); 136 entry_writer_0->SetKeyValue(kKey0, kValue0);
137 dictionary_writer.AddEntry(entry_writer_0.Pass()); 137 dictionary_writer.AddEntry(entry_writer_0.Pass());
138 auto entry_writer_1 = 138 auto entry_writer_1 =
139 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 139 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
140 entry_writer_1->SetKeyValue(kKey1, kValue1); 140 entry_writer_1->SetKeyValue(kKey1, kValue1);
141 dictionary_writer.AddEntry(entry_writer_1.Pass()); 141 dictionary_writer.AddEntry(entry_writer_1.Pass());
142 auto entry_writer_2 = 142 auto entry_writer_2 =
143 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 143 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
144 entry_writer_2->SetKeyValue(kKey2, kValue2); 144 entry_writer_2->SetKeyValue(kKey2, kValue2);
145 dictionary_writer.AddEntry(entry_writer_2.Pass()); 145 dictionary_writer.AddEntry(entry_writer_2.Pass());
146 146
147 EXPECT_TRUE(dictionary_writer.IsUseful()); 147 EXPECT_TRUE(dictionary_writer.IsUseful());
148 148
149 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 149 EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
150 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 150 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
151 3 * sizeof(MinidumpSimpleStringDictionaryEntry) + 151 3 * sizeof(MinidumpSimpleStringDictionaryEntry) +
152 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) + 152 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) +
153 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 + 153 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 +
154 sizeof(kKey1) + 3 + sizeof(kValue1), 154 sizeof(kKey1) + 3 + sizeof(kValue1),
155 file_writer.string().size()); 155 string_file.string().size());
156 156
157 const MinidumpSimpleStringDictionary* dictionary = 157 const MinidumpSimpleStringDictionary* dictionary =
158 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 3); 158 MinidumpSimpleStringDictionaryAtStart(string_file.string(), 3);
159 ASSERT_TRUE(dictionary); 159 ASSERT_TRUE(dictionary);
160 EXPECT_EQ(3u, dictionary->count); 160 EXPECT_EQ(3u, dictionary->count);
161 EXPECT_EQ(28u, dictionary->entries[0].key); 161 EXPECT_EQ(28u, dictionary->entries[0].key);
162 EXPECT_EQ(36u, dictionary->entries[0].value); 162 EXPECT_EQ(36u, dictionary->entries[0].value);
163 EXPECT_EQ(48u, dictionary->entries[1].key); 163 EXPECT_EQ(48u, dictionary->entries[1].key);
164 EXPECT_EQ(56u, dictionary->entries[1].value); 164 EXPECT_EQ(56u, dictionary->entries[1].value);
165 EXPECT_EQ(68u, dictionary->entries[2].key); 165 EXPECT_EQ(68u, dictionary->entries[2].key);
166 EXPECT_EQ(80u, dictionary->entries[2].value); 166 EXPECT_EQ(80u, dictionary->entries[2].value);
167 167
168 // The entries don’t appear in the order they were added. The current 168 // The entries don’t appear in the order they were added. The current
169 // implementation uses a std::map and sorts keys, so the entires appear in 169 // implementation uses a std::map and sorts keys, so the entires appear in
170 // alphabetical order. However, this is an implementation detail, and it’s OK 170 // alphabetical order. However, this is an implementation detail, and it’s OK
171 // if the writer stops sorting in this order. Testing for a specific order is 171 // if the writer stops sorting in this order. Testing for a specific order is
172 // just the easiest way to write this test while the writer will output things 172 // just the easiest way to write this test while the writer will output things
173 // in a known order. 173 // in a known order.
174 EXPECT_EQ(kKey2, 174 EXPECT_EQ(kKey2,
175 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 175 MinidumpUTF8StringAtRVAAsString(string_file.string(),
176 dictionary->entries[0].key)); 176 dictionary->entries[0].key));
177 EXPECT_EQ(kValue2, 177 EXPECT_EQ(kValue2,
178 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 178 MinidumpUTF8StringAtRVAAsString(string_file.string(),
179 dictionary->entries[0].value)); 179 dictionary->entries[0].value));
180 EXPECT_EQ(kKey0, 180 EXPECT_EQ(kKey0,
181 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 181 MinidumpUTF8StringAtRVAAsString(string_file.string(),
182 dictionary->entries[1].key)); 182 dictionary->entries[1].key));
183 EXPECT_EQ(kValue0, 183 EXPECT_EQ(kValue0,
184 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 184 MinidumpUTF8StringAtRVAAsString(string_file.string(),
185 dictionary->entries[1].value)); 185 dictionary->entries[1].value));
186 EXPECT_EQ(kKey1, 186 EXPECT_EQ(kKey1,
187 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 187 MinidumpUTF8StringAtRVAAsString(string_file.string(),
188 dictionary->entries[2].key)); 188 dictionary->entries[2].key));
189 EXPECT_EQ(kValue1, 189 EXPECT_EQ(kValue1,
190 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 190 MinidumpUTF8StringAtRVAAsString(string_file.string(),
191 dictionary->entries[2].value)); 191 dictionary->entries[2].value));
192 } 192 }
193 193
194 TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) { 194 TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) {
195 StringFileWriter file_writer; 195 StringFile string_file;
196 196
197 char kKey[] = "key"; 197 char kKey[] = "key";
198 char kValue0[] = "fake_value"; 198 char kValue0[] = "fake_value";
199 char kValue1[] = "value"; 199 char kValue1[] = "value";
200 200
201 MinidumpSimpleStringDictionaryWriter dictionary_writer; 201 MinidumpSimpleStringDictionaryWriter dictionary_writer;
202 auto entry_writer_0 = 202 auto entry_writer_0 =
203 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 203 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
204 entry_writer_0->SetKeyValue(kKey, kValue0); 204 entry_writer_0->SetKeyValue(kKey, kValue0);
205 dictionary_writer.AddEntry(entry_writer_0.Pass()); 205 dictionary_writer.AddEntry(entry_writer_0.Pass());
206 auto entry_writer_1 = 206 auto entry_writer_1 =
207 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); 207 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
208 entry_writer_1->SetKeyValue(kKey, kValue1); 208 entry_writer_1->SetKeyValue(kKey, kValue1);
209 dictionary_writer.AddEntry(entry_writer_1.Pass()); 209 dictionary_writer.AddEntry(entry_writer_1.Pass());
210 210
211 EXPECT_TRUE(dictionary_writer.IsUseful()); 211 EXPECT_TRUE(dictionary_writer.IsUseful());
212 212
213 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 213 EXPECT_TRUE(dictionary_writer.WriteEverything(&string_file));
214 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 214 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
215 sizeof(MinidumpSimpleStringDictionaryEntry) + 215 sizeof(MinidumpSimpleStringDictionaryEntry) +
216 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1), 216 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1),
217 file_writer.string().size()); 217 string_file.string().size());
218 218
219 const MinidumpSimpleStringDictionary* dictionary = 219 const MinidumpSimpleStringDictionary* dictionary =
220 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 220 MinidumpSimpleStringDictionaryAtStart(string_file.string(), 1);
221 ASSERT_TRUE(dictionary); 221 ASSERT_TRUE(dictionary);
222 EXPECT_EQ(1u, dictionary->count); 222 EXPECT_EQ(1u, dictionary->count);
223 EXPECT_EQ(12u, dictionary->entries[0].key); 223 EXPECT_EQ(12u, dictionary->entries[0].key);
224 EXPECT_EQ(20u, dictionary->entries[0].value); 224 EXPECT_EQ(20u, dictionary->entries[0].value);
225 EXPECT_EQ(kKey, 225 EXPECT_EQ(kKey,
226 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 226 MinidumpUTF8StringAtRVAAsString(string_file.string(),
227 dictionary->entries[0].key)); 227 dictionary->entries[0].key));
228 EXPECT_EQ(kValue1, 228 EXPECT_EQ(kValue1,
229 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 229 MinidumpUTF8StringAtRVAAsString(string_file.string(),
230 dictionary->entries[0].value)); 230 dictionary->entries[0].value));
231 } 231 }
232 232
233 TEST(MinidumpSimpleStringDictionaryWriter, InitializeFromMap) { 233 TEST(MinidumpSimpleStringDictionaryWriter, InitializeFromMap) {
234 char kKey0[] = "Dictionaries"; 234 char kKey0[] = "Dictionaries";
235 char kValue0[] = "USEFUL*"; 235 char kValue0[] = "USEFUL*";
236 char kKey1[] = "#1 Key!"; 236 char kKey1[] = "#1 Key!";
237 char kValue1[] = ""; 237 char kValue1[] = "";
238 char kKey2[] = "key two"; 238 char kKey2[] = "key two";
239 char kValue2[] = "value two"; 239 char kValue2[] = "value two";
240 240
241 std::map<std::string, std::string> map; 241 std::map<std::string, std::string> map;
242 map[kKey0] = kValue0; 242 map[kKey0] = kValue0;
243 map[kKey1] = kValue1; 243 map[kKey1] = kValue1;
244 map[kKey2] = kValue2; 244 map[kKey2] = kValue2;
245 245
246 MinidumpSimpleStringDictionaryWriter dictionary_writer; 246 MinidumpSimpleStringDictionaryWriter dictionary_writer;
247 dictionary_writer.InitializeFromMap(map); 247 dictionary_writer.InitializeFromMap(map);
248 248
249 EXPECT_TRUE(dictionary_writer.IsUseful()); 249 EXPECT_TRUE(dictionary_writer.IsUseful());
250 250
251 StringFileWriter file_writer; 251 StringFile string_file;
252 ASSERT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 252 ASSERT_TRUE(dictionary_writer.WriteEverything(&string_file));
253 253
254 const MinidumpSimpleStringDictionary* dictionary = 254 const MinidumpSimpleStringDictionary* dictionary =
255 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), map.size()); 255 MinidumpSimpleStringDictionaryAtStart(string_file.string(), map.size());
256 ASSERT_TRUE(dictionary); 256 ASSERT_TRUE(dictionary);
257 ASSERT_EQ(3u, dictionary->count); 257 ASSERT_EQ(3u, dictionary->count);
258 258
259 // The entries don’t appear in the order they were added. The current 259 // The entries don’t appear in the order they were added. The current
260 // implementation uses a std::map and sorts keys, so the entires appear in 260 // implementation uses a std::map and sorts keys, so the entires appear in
261 // alphabetical order. However, this is an implementation detail, and it’s OK 261 // alphabetical order. However, this is an implementation detail, and it’s OK
262 // if the writer stops sorting in this order. Testing for a specific order is 262 // if the writer stops sorting in this order. Testing for a specific order is
263 // just the easiest way to write this test while the writer will output things 263 // just the easiest way to write this test while the writer will output things
264 // in a known order. 264 // in a known order.
265 EXPECT_EQ(kKey1, 265 EXPECT_EQ(kKey1,
266 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 266 MinidumpUTF8StringAtRVAAsString(string_file.string(),
267 dictionary->entries[0].key)); 267 dictionary->entries[0].key));
268 EXPECT_EQ(kValue1, 268 EXPECT_EQ(kValue1,
269 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 269 MinidumpUTF8StringAtRVAAsString(string_file.string(),
270 dictionary->entries[0].value)); 270 dictionary->entries[0].value));
271 EXPECT_EQ(kKey0, 271 EXPECT_EQ(kKey0,
272 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 272 MinidumpUTF8StringAtRVAAsString(string_file.string(),
273 dictionary->entries[1].key)); 273 dictionary->entries[1].key));
274 EXPECT_EQ(kValue0, 274 EXPECT_EQ(kValue0,
275 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 275 MinidumpUTF8StringAtRVAAsString(string_file.string(),
276 dictionary->entries[1].value)); 276 dictionary->entries[1].value));
277 EXPECT_EQ(kKey2, 277 EXPECT_EQ(kKey2,
278 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 278 MinidumpUTF8StringAtRVAAsString(string_file.string(),
279 dictionary->entries[2].key)); 279 dictionary->entries[2].key));
280 EXPECT_EQ(kValue2, 280 EXPECT_EQ(kValue2,
281 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 281 MinidumpUTF8StringAtRVAAsString(string_file.string(),
282 dictionary->entries[2].value)); 282 dictionary->entries[2].value));
283 } 283 }
284 284
285 } // namespace 285 } // namespace
286 } // namespace test 286 } // namespace test
287 } // namespace crashpad 287 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_rva_list_writer_test.cc ('k') | minidump/minidump_string_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698