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

Side by Side Diff: minidump/minidump_simple_string_dictionary_writer_test.cc

Issue 670853002: minidump: Migrate the rest of the tests to MinidumpWritableAtLocationDescriptor<>() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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
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 <string> 17 #include <string>
18 18
19 #include "gtest/gtest.h" 19 #include "gtest/gtest.h"
20 #include "minidump/minidump_extensions.h" 20 #include "minidump/minidump_extensions.h"
21 #include "minidump/test/minidump_string_writer_test_util.h" 21 #include "minidump/test/minidump_string_writer_test_util.h"
22 #include "minidump/test/minidump_writable_test_util.h"
22 #include "util/file/string_file_writer.h" 23 #include "util/file/string_file_writer.h"
23 24
24 namespace crashpad { 25 namespace crashpad {
25 namespace test { 26 namespace test {
26 namespace { 27 namespace {
27 28
28 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryCast( 29 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart(
29 const StringFileWriter& file_writer) { 30 const std::string& file_contents,
30 return reinterpret_cast<const MinidumpSimpleStringDictionary*>( 31 size_t count) {
31 &file_writer.string()[0]); 32 MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
33 location_descriptor.DataSize =
34 sizeof(MinidumpSimpleStringDictionary) +
35 count * sizeof(MinidumpSimpleStringDictionaryEntry);
36 location_descriptor.Rva = 0;
37 return MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
38 file_contents, location_descriptor);
32 } 39 }
33 40
34 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) { 41 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) {
35 StringFileWriter file_writer; 42 StringFileWriter file_writer;
36 43
37 MinidumpSimpleStringDictionaryWriter dictionary_writer; 44 MinidumpSimpleStringDictionaryWriter dictionary_writer;
38 45
39 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 46 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
40 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary), 47 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary),
41 file_writer.string().size()); 48 file_writer.string().size());
42 49
43 const MinidumpSimpleStringDictionary* dictionary = 50 const MinidumpSimpleStringDictionary* dictionary =
44 MinidumpSimpleStringDictionaryCast(file_writer); 51 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 0);
52 ASSERT_TRUE(dictionary);
45 EXPECT_EQ(0u, dictionary->count); 53 EXPECT_EQ(0u, dictionary->count);
46 } 54 }
47 55
48 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) { 56 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
49 StringFileWriter file_writer; 57 StringFileWriter file_writer;
50 58
51 MinidumpSimpleStringDictionaryWriter dictionary_writer; 59 MinidumpSimpleStringDictionaryWriter dictionary_writer;
52 MinidumpSimpleStringDictionaryEntryWriter entry_writer; 60 MinidumpSimpleStringDictionaryEntryWriter entry_writer;
53 dictionary_writer.AddEntry(&entry_writer); 61 dictionary_writer.AddEntry(&entry_writer);
54 62
55 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 63 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
56 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 64 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
57 sizeof(MinidumpSimpleStringDictionaryEntry) + 65 sizeof(MinidumpSimpleStringDictionaryEntry) +
58 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding 66 2 * sizeof(MinidumpUTF8String) + 1 + 3 + 1, // 3 for padding
59 file_writer.string().size()); 67 file_writer.string().size());
60 68
61 const MinidumpSimpleStringDictionary* dictionary = 69 const MinidumpSimpleStringDictionary* dictionary =
62 MinidumpSimpleStringDictionaryCast(file_writer); 70 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
71 ASSERT_TRUE(dictionary);
63 EXPECT_EQ(1u, dictionary->count); 72 EXPECT_EQ(1u, dictionary->count);
64 EXPECT_EQ(12u, dictionary->entries[0].key); 73 EXPECT_EQ(12u, dictionary->entries[0].key);
65 EXPECT_EQ(20u, dictionary->entries[0].value); 74 EXPECT_EQ(20u, dictionary->entries[0].value);
66 EXPECT_EQ("", 75 EXPECT_EQ("",
67 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 76 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
68 dictionary->entries[0].key)); 77 dictionary->entries[0].key));
69 EXPECT_EQ("", 78 EXPECT_EQ("",
70 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 79 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
71 dictionary->entries[0].value)); 80 dictionary->entries[0].value));
72 } 81 }
73 82
74 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) { 83 TEST(MinidumpSimpleStringDictionaryWriter, OneKeyValue) {
75 StringFileWriter file_writer; 84 StringFileWriter file_writer;
76 85
77 char kKey[] = "key"; 86 char kKey[] = "key";
78 char kValue[] = "value"; 87 char kValue[] = "value";
79 88
80 MinidumpSimpleStringDictionaryWriter dictionary_writer; 89 MinidumpSimpleStringDictionaryWriter dictionary_writer;
81 MinidumpSimpleStringDictionaryEntryWriter entry_writer; 90 MinidumpSimpleStringDictionaryEntryWriter entry_writer;
82 entry_writer.SetKeyValue(kKey, kValue); 91 entry_writer.SetKeyValue(kKey, kValue);
83 dictionary_writer.AddEntry(&entry_writer); 92 dictionary_writer.AddEntry(&entry_writer);
84 93
85 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 94 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
86 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 95 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
87 sizeof(MinidumpSimpleStringDictionaryEntry) + 96 sizeof(MinidumpSimpleStringDictionaryEntry) +
88 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue), 97 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue),
89 file_writer.string().size()); 98 file_writer.string().size());
90 99
91 const MinidumpSimpleStringDictionary* dictionary = 100 const MinidumpSimpleStringDictionary* dictionary =
92 MinidumpSimpleStringDictionaryCast(file_writer); 101 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
102 ASSERT_TRUE(dictionary);
93 EXPECT_EQ(1u, dictionary->count); 103 EXPECT_EQ(1u, dictionary->count);
94 EXPECT_EQ(12u, dictionary->entries[0].key); 104 EXPECT_EQ(12u, dictionary->entries[0].key);
95 EXPECT_EQ(20u, dictionary->entries[0].value); 105 EXPECT_EQ(20u, dictionary->entries[0].value);
96 EXPECT_EQ(kKey, 106 EXPECT_EQ(kKey,
97 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 107 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
98 dictionary->entries[0].key)); 108 dictionary->entries[0].key));
99 EXPECT_EQ(kValue, 109 EXPECT_EQ(kValue,
100 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 110 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
101 dictionary->entries[0].value)); 111 dictionary->entries[0].value));
102 } 112 }
(...skipping 21 matching lines...) Expand all
124 134
125 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 135 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
126 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 136 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
127 3 * sizeof(MinidumpSimpleStringDictionaryEntry) + 137 3 * sizeof(MinidumpSimpleStringDictionaryEntry) +
128 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) + 138 6 * sizeof(MinidumpUTF8String) + sizeof(kKey2) +
129 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 + 139 sizeof(kValue2) + 3 + sizeof(kKey0) + 1 + sizeof(kValue0) + 1 +
130 sizeof(kKey1) + 3 + sizeof(kValue1), 140 sizeof(kKey1) + 3 + sizeof(kValue1),
131 file_writer.string().size()); 141 file_writer.string().size());
132 142
133 const MinidumpSimpleStringDictionary* dictionary = 143 const MinidumpSimpleStringDictionary* dictionary =
134 MinidumpSimpleStringDictionaryCast(file_writer); 144 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 3);
145 ASSERT_TRUE(dictionary);
135 EXPECT_EQ(3u, dictionary->count); 146 EXPECT_EQ(3u, dictionary->count);
136 EXPECT_EQ(28u, dictionary->entries[0].key); 147 EXPECT_EQ(28u, dictionary->entries[0].key);
137 EXPECT_EQ(36u, dictionary->entries[0].value); 148 EXPECT_EQ(36u, dictionary->entries[0].value);
138 EXPECT_EQ(48u, dictionary->entries[1].key); 149 EXPECT_EQ(48u, dictionary->entries[1].key);
139 EXPECT_EQ(56u, dictionary->entries[1].value); 150 EXPECT_EQ(56u, dictionary->entries[1].value);
140 EXPECT_EQ(68u, dictionary->entries[2].key); 151 EXPECT_EQ(68u, dictionary->entries[2].key);
141 EXPECT_EQ(80u, dictionary->entries[2].value); 152 EXPECT_EQ(80u, dictionary->entries[2].value);
142 153
143 // The entries don’t appear in the order they were added. The current 154 // The entries don’t appear in the order they were added. The current
144 // implementation uses a std::map and sorts keys, so the entires appear in 155 // implementation uses a std::map and sorts keys, so the entires appear in
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 entry_writer_1.SetKeyValue(kKey, kValue1); 192 entry_writer_1.SetKeyValue(kKey, kValue1);
182 dictionary_writer.AddEntry(&entry_writer_1); 193 dictionary_writer.AddEntry(&entry_writer_1);
183 194
184 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 195 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
185 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 196 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
186 sizeof(MinidumpSimpleStringDictionaryEntry) + 197 sizeof(MinidumpSimpleStringDictionaryEntry) +
187 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1), 198 2 * sizeof(MinidumpUTF8String) + sizeof(kKey) + sizeof(kValue1),
188 file_writer.string().size()); 199 file_writer.string().size());
189 200
190 const MinidumpSimpleStringDictionary* dictionary = 201 const MinidumpSimpleStringDictionary* dictionary =
191 MinidumpSimpleStringDictionaryCast(file_writer); 202 MinidumpSimpleStringDictionaryAtStart(file_writer.string(), 1);
203 ASSERT_TRUE(dictionary);
192 EXPECT_EQ(1u, dictionary->count); 204 EXPECT_EQ(1u, dictionary->count);
193 EXPECT_EQ(12u, dictionary->entries[0].key); 205 EXPECT_EQ(12u, dictionary->entries[0].key);
194 EXPECT_EQ(20u, dictionary->entries[0].value); 206 EXPECT_EQ(20u, dictionary->entries[0].value);
195 EXPECT_EQ(kKey, 207 EXPECT_EQ(kKey,
196 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 208 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
197 dictionary->entries[0].key)); 209 dictionary->entries[0].key));
198 EXPECT_EQ(kValue1, 210 EXPECT_EQ(kValue1,
199 MinidumpUTF8StringAtRVAAsString(file_writer.string(), 211 MinidumpUTF8StringAtRVAAsString(file_writer.string(),
200 dictionary->entries[0].value)); 212 dictionary->entries[0].value));
201 } 213 }
202 214
203 } // namespace 215 } // namespace
204 } // namespace test 216 } // namespace test
205 } // namespace crashpad 217 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698