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

Side by Side Diff: minidump/minidump_simple_string_dictionary_writer_test.cc

Issue 674153002: minidump: Change the ownership model (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 6 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 | « minidump/minidump_simple_string_dictionary_writer.cc ('k') | minidump/minidump_stream_writer.h » ('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,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const MinidumpSimpleStringDictionary* dictionary = 50 const MinidumpSimpleStringDictionary* dictionary =
51 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 0); 51 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 0);
52 ASSERT_TRUE(dictionary); 52 ASSERT_TRUE(dictionary);
53 EXPECT_EQ(0u, dictionary->count); 53 EXPECT_EQ(0u, dictionary->count);
54 } 54 }
55 55
56 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) { 56 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
57 StringFileWriter file_writer; 57 StringFileWriter file_writer;
58 58
59 MinidumpSimpleStringDictionaryWriter dictionary_writer; 59 MinidumpSimpleStringDictionaryWriter dictionary_writer;
60 MinidumpSimpleStringDictionaryEntryWriter entry_writer; 60 auto entry_writer =
61 dictionary_writer.AddEntry(&entry_writer); 61 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
62 dictionary_writer.AddEntry(entry_writer.Pass());
62 63
63 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 64 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
64 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 65 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
65 sizeof(MinidumpSimpleStringDictionaryEntry) + 66 sizeof(MinidumpSimpleStringDictionaryEntry) +
66 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding 67 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding
67 file_writer.string().size()); 68 file_writer.string().size());
68 69
69 const MinidumpSimpleStringDictionary* dictionary = 70 const MinidumpSimpleStringDictionary* dictionary =
70 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 71 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
71 ASSERT_TRUE(dictionary); 72 ASSERT_TRUE(dictionary);
72 EXPECT_EQ(1u, dictionary->count); 73 EXPECT_EQ(1u, dictionary->count);
73 EXPECT_EQ(12u, dictionary->entries[0].key); 74 EXPECT_EQ(12u, dictionary->entries[0].key);
74 EXPECT_EQ(20u, dictionary->entries[0].value); 75 EXPECT_EQ(20u, dictionary->entries[0].value);
75 EXPECT_EQ("", 76 EXPECT_EQ("",
76 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 77 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
77 dictionary->entries[0].key)); 78 dictionary->entries[0].key));
78 EXPECT_EQ("", 79 EXPECT_EQ("",
79 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 80 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
80 dictionary->entries[0].value)); 81 dictionary->entries[0].value));
81 } 82 }
82 83
83 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) { 84 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) {
84 StringFileWriter file_writer; 85 StringFileWriter file_writer;
85 86
86 char kKey[] = "key"; 87 char kKey[] = "key";
87 char kValue[] = "value"; 88 char kValue[] = "value";
88 89
89 MinidumpSimpleStringDictionaryWriter dictionary_writer; 90 MinidumpSimpleStringDictionaryWriter dictionary_writer;
90 MinidumpSimpleStringDictionaryEntryWriter entry_writer; 91 auto entry_writer =
91 entry_writer.SetKeyValue(kKey, kValue); 92 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
92 dictionary_writer.AddEntry(&entry_writer); 93 entry_writer->SetKeyValue(kKey, kValue);
94 dictionary_writer.AddEntry(entry_writer.Pass());
93 95
94 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 96 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
95 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 97 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
96 sizeof(MinidumpSimpleStringDictionaryEntry) + 98 sizeof(MinidumpSimpleStringDictionaryEntry) +
97 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue), 99 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue),
98 file_writer.string().size()); 100 file_writer.string().size());
99 101
100 const MinidumpSimpleStringDictionary* dictionary = 102 const MinidumpSimpleStringDictionary* dictionary =
101 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 103 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
102 ASSERT_TRUE(dictionary); 104 ASSERT_TRUE(dictionary);
(...skipping 12 matching lines...) Expand all
115 StringFileWriter file_writer; 117 StringFileWriter file_writer;
116 118
117 char kKey0[] = "m0"; 119 char kKey0[] = "m0";
118 char kValue0[] = "value0"; 120 char kValue0[] = "value0";
119 char kKey1[] = "zzz1"; 121 char kKey1[] = "zzz1";
120 char kValue1[] = "v1"; 122 char kValue1[] = "v1";
121 char kKey2[] = "aa2"; 123 char kKey2[] = "aa2";
122 char kValue2[] = "val2"; 124 char kValue2[] = "val2";
123 125
124 MinidumpSimpleStringDictionaryWriter dictionary_writer; 126 MinidumpSimpleStringDictionaryWriter dictionary_writer;
125 MinidumpSimpleStringDictionaryEntryWriter entry_writer_0; 127 auto entry_writer_0 =
126 entry_writer_0.SetKeyValue(kKey0, kValue0); 128 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
127 dictionary_writer.AddEntry(&entry_writer_0); 129 entry_writer_0->SetKeyValue(kKey0, kValue0);
128 MinidumpSimpleStringDictionaryEntryWriter entry_writer_1; 130 dictionary_writer.AddEntry(entry_writer_0.Pass());
129 entry_writer_1.SetKeyValue(kKey1, kValue1); 131 auto entry_writer_1 =
130 dictionary_writer.AddEntry(&entry_writer_1); 132 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
131 MinidumpSimpleStringDictionaryEntryWriter entry_writer_2; 133 entry_writer_1->SetKeyValue(kKey1, kValue1);
132 entry_writer_2.SetKeyValue(kKey2, kValue2); 134 dictionary_writer.AddEntry(entry_writer_1.Pass());
133 dictionary_writer.AddEntry(&entry_writer_2); 135 auto entry_writer_2 =
136 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
137 entry_writer_2->SetKeyValue(kKey2, kValue2);
138 dictionary_writer.AddEntry(entry_writer_2.Pass());
134 139
135 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 140 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
136 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 141 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
137 3 * sizeof(MinidumpSimpleStringDictionaryEntry) + 142 3 * sizeof(MinidumpSimpleStringDictionaryEntry) +
138 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) + 143 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) +
139 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 + 144 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 +
140 sizeof(kKey1) + 3 + sizeof(kValue1), 145 sizeof(kKey1) + 3 + sizeof(kValue1),
141 file_writer.string().size()); 146 file_writer.string().size());
142 147
143 const MinidumpSimpleStringDictionary* dictionary = 148 const MinidumpSimpleStringDictionary* dictionary =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 183 }
179 184
180 TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) { 185 TEST(MinidumpSimpleStringDictionaryWriter, DuplicateKeyValue) {
181 StringFileWriter file_writer; 186 StringFileWriter file_writer;
182 187
183 char kKey[] = "key"; 188 char kKey[] = "key";
184 char kValue0[] = "fake_value"; 189 char kValue0[] = "fake_value";
185 char kValue1[] = "value"; 190 char kValue1[] = "value";
186 191
187 MinidumpSimpleStringDictionaryWriter dictionary_writer; 192 MinidumpSimpleStringDictionaryWriter dictionary_writer;
188 MinidumpSimpleStringDictionaryEntryWriter entry_writer_0; 193 auto entry_writer_0 =
189 entry_writer_0.SetKeyValue(kKey, kValue0); 194 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
190 dictionary_writer.AddEntry(&entry_writer_0); 195 entry_writer_0->SetKeyValue(kKey, kValue0);
191 MinidumpSimpleStringDictionaryEntryWriter entry_writer_1; 196 dictionary_writer.AddEntry(entry_writer_0.Pass());
192 entry_writer_1.SetKeyValue(kKey, kValue1); 197 auto entry_writer_1 =
193 dictionary_writer.AddEntry(&entry_writer_1); 198 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter());
199 entry_writer_1->SetKeyValue(kKey, kValue1);
200 dictionary_writer.AddEntry(entry_writer_1.Pass());
194 201
195 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 202 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
196 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 203 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
197 sizeof(MinidumpSimpleStringDictionaryEntry) + 204 sizeof(MinidumpSimpleStringDictionaryEntry) +
198 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1), 205 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1),
199 file_writer.string().size()); 206 file_writer.string().size());
200 207
201 const MinidumpSimpleStringDictionary* dictionary = 208 const MinidumpSimpleStringDictionary* dictionary =
202 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1); 209 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
203 ASSERT_TRUE(dictionary); 210 ASSERT_TRUE(dictionary);
204 EXPECT_EQ(1u, dictionary->count); 211 EXPECT_EQ(1u, dictionary->count);
205 EXPECT_EQ(12u, dictionary->entries[0].key); 212 EXPECT_EQ(12u, dictionary->entries[0].key);
206 EXPECT_EQ(20u, dictionary->entries[0].value); 213 EXPECT_EQ(20u, dictionary->entries[0].value);
207 EXPECT_EQ(kKey, 214 EXPECT_EQ(kKey,
208 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 215 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
209 dictionary->entries[0].key)); 216 dictionary->entries[0].key));
210 EXPECT_EQ(kValue1, 217 EXPECT_EQ(kValue1,
211 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 218 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
212 dictionary->entries[0].value)); 219 dictionary->entries[0].value));
213 } 220 }
214 221
215 } // namespace 222 } // namespace
216 } // namespace test 223 } // namespace test
217 } // namespace crashpad 224 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_simple_string_dictionary_writer.cc ('k') | minidump/minidump_stream_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698