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

Side by Side Diff: minidump/minidump_simple_string_dictionary_writer_test.cc

Issue 654573003: Add MinidumpCrashpadInfoWriter and its test (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/minidump_string_writer_test_util.h"
21 #include "util/file/string_file_writer.h" 22 #include "util/file/string_file_writer.h"
22 23
23 namespace crashpad { 24 namespace crashpad {
24 namespace test { 25 namespace test {
25 namespace { 26 namespace {
26 27
27 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryCast( 28 const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryCast(
28 const StringFileWriter& file_writer) { 29 const StringFileWriter& file_writer) {
29 return reinterpret_cast<const MinidumpSimpleStringDictionary*>( 30 return reinterpret_cast<const MinidumpSimpleStringDictionary*>(
30 &file_writer.string()[0]); 31 &file_writer.string()[0]);
31 } 32 }
32 33
33 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) { 34 TEST(MinidumpSimpleStringDictionaryWriter, EmptySimpleStringDictionary) {
34 StringFileWriter file_writer; 35 StringFileWriter file_writer;
35 36
36 MinidumpSimpleStringDictionaryWriter dictionary_writer; 37 MinidumpSimpleStringDictionaryWriter dictionary_writer;
37 38
38 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 39 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
39 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary), 40 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary),
40 file_writer.string().size()); 41 file_writer.string().size());
41 42
42 const MinidumpSimpleStringDictionary* dictionary = 43 const MinidumpSimpleStringDictionary* dictionary =
43 MinidumpSimpleStringDictionaryCast(file_writer); 44 MinidumpSimpleStringDictionaryCast(file_writer);
44 EXPECT_EQ(0u, dictionary->count); 45 EXPECT_EQ(0u, dictionary->count);
45 } 46 }
46 47
47 std::string MinidumpUTF8StringAtRVA(const StringFileWriter& file_writer,
48 RVA rva) {
49 const std::string& contents = file_writer.string();
50 if (rva == 0) {
51 return std::string();
52 }
53
54 if (rva + sizeof(MinidumpUTF8String) > contents.size()) {
55 ADD_FAILURE()
56 << "rva " << rva << " too large for contents " << contents.size();
57 return std::string();
58 }
59
60 const MinidumpUTF8String* minidump_string =
61 reinterpret_cast<const MinidumpUTF8String*>(&contents[rva]);
62
63 // Verify that the file has enough data for the string’s stated length plus
64 // its required NUL terminator.
65 if (rva + sizeof(MinidumpUTF8String) + minidump_string->Length + 1 >
66 contents.size()) {
67 ADD_FAILURE()
68 << "rva " << rva << ", length " << minidump_string->Length
69 << " too large for contents " << contents.size();
70 return std::string();
71 }
72
73 std::string minidump_string_data(
74 reinterpret_cast<const char*>(&minidump_string->Buffer[0]),
75 minidump_string->Length);
76 return minidump_string_data;
77 }
78
79 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) { 48 TEST(MinidumpSimpleStringDictionaryWriter, EmptyKeyValue) {
80 StringFileWriter file_writer; 49 StringFileWriter file_writer;
81 50
82 MinidumpSimpleStringDictionaryWriter dictionary_writer; 51 MinidumpSimpleStringDictionaryWriter dictionary_writer;
83 MinidumpSimpleStringDictionaryEntryWriter entry_writer; 52 MinidumpSimpleStringDictionaryEntryWriter entry_writer;
84 dictionary_writer.AddEntry(&entry_writer); 53 dictionary_writer.AddEntry(&entry_writer);
85 54
86 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer)); 55 EXPECT_TRUE(dictionary_writer.WriteEverything(&file_writer));
87 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) + 56 ASSERT_EQ(sizeof(MinidumpSimpleStringDictionary) +
88 sizeof(MinidumpSimpleStringDictionaryEntry) + 57 sizeof(MinidumpSimpleStringDictionaryEntry) +
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EXPECT_EQ(20u, dictionary->entries[0].value); 184 EXPECT_EQ(20u, dictionary->entries[0].value);
216 EXPECT_EQ(kKey, 185 EXPECT_EQ(kKey,
217 MinidumpUTF8StringAtRVA(file_writer, dictionary->entries[0].key)); 186 MinidumpUTF8StringAtRVA(file_writer, dictionary->entries[0].key));
218 EXPECT_EQ(kValue1, 187 EXPECT_EQ(kValue1,
219 MinidumpUTF8StringAtRVA(file_writer, dictionary->entries[0].value)); 188 MinidumpUTF8StringAtRVA(file_writer, dictionary->entries[0].value));
220 } 189 }
221 190
222 } // namespace 191 } // namespace
223 } // namespace test 192 } // namespace test
224 } // namespace crashpad 193 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698