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

Side by Side Diff: minidump/minidump_handle_writer_test.cc

Issue 1421473005: Fix mac after https://codereview.chromium.org/1419623003/ (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 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 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 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_handle_writer.h" 15 #include "minidump/minidump_handle_writer.h"
16 16
17 #include <string> 17 #include <string>
18 18
19 #include "base/strings/utf_string_conversions.h"
19 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
20 #include "minidump/minidump_file_writer.h" 21 #include "minidump/minidump_file_writer.h"
21 #include "minidump/test/minidump_file_writer_test_util.h" 22 #include "minidump/test/minidump_file_writer_test_util.h"
22 #include "minidump/test/minidump_string_writer_test_util.h" 23 #include "minidump/test/minidump_string_writer_test_util.h"
23 #include "minidump/test/minidump_writable_test_util.h" 24 #include "minidump/test/minidump_writable_test_util.h"
24 #include "util/file/string_file.h" 25 #include "util/file/string_file.h"
25 26
26 namespace crashpad { 27 namespace crashpad {
27 namespace test { 28 namespace test {
28 namespace { 29 namespace {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 EXPECT_EQ(0u, handle_data_stream->NumberOfDescriptors); 73 EXPECT_EQ(0u, handle_data_stream->NumberOfDescriptors);
73 } 74 }
74 75
75 TEST(MinidumpHandleDataWriter, OneHandle) { 76 TEST(MinidumpHandleDataWriter, OneHandle) {
76 MinidumpFileWriter minidump_file_writer; 77 MinidumpFileWriter minidump_file_writer;
77 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter()); 78 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter());
78 79
79 HandleSnapshot handle_snapshot; 80 HandleSnapshot handle_snapshot;
80 handle_snapshot.handle = 0x1234; 81 handle_snapshot.handle = 0x1234;
81 handle_snapshot.type_name = L"Something"; 82 handle_snapshot.type_name = "Something";
Mark Mentovai 2015/10/21 18:31:28 It looks like this was the only offending use. An
scottmg 2015/10/21 18:35:44 Yeah, that's what I tried at first, but the SetUTF
82 handle_snapshot.attributes = 0x12345678; 83 handle_snapshot.attributes = 0x12345678;
83 handle_snapshot.granted_access = 0x9abcdef0; 84 handle_snapshot.granted_access = 0x9abcdef0;
84 handle_snapshot.pointer_count = 4567; 85 handle_snapshot.pointer_count = 4567;
85 handle_snapshot.handle_count = 9876; 86 handle_snapshot.handle_count = 9876;
86 87
87 std::vector<HandleSnapshot> snapshot; 88 std::vector<HandleSnapshot> snapshot;
88 snapshot.push_back(handle_snapshot); 89 snapshot.push_back(handle_snapshot);
89 90
90 handle_data_writer->InitializeFromSnapshot(snapshot); 91 handle_data_writer->InitializeFromSnapshot(snapshot);
91 92
92 minidump_file_writer.AddStream(handle_data_writer.Pass()); 93 minidump_file_writer.AddStream(handle_data_writer.Pass());
93 94
94 StringFile string_file; 95 StringFile string_file;
95 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); 96 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
96 97
97 const size_t kTypeNameStringDataLength = 98 const size_t kTypeNameStringDataLength =
98 (handle_snapshot.type_name.size() + 1) * 99 (handle_snapshot.type_name.size() + 1) * sizeof(base::char16);
99 sizeof(handle_snapshot.type_name[0]);
100 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 100 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
101 sizeof(MINIDUMP_HANDLE_DATA_STREAM) + 101 sizeof(MINIDUMP_HANDLE_DATA_STREAM) +
102 sizeof(MINIDUMP_HANDLE_DESCRIPTOR) + sizeof(MINIDUMP_STRING) + 102 sizeof(MINIDUMP_HANDLE_DESCRIPTOR) + sizeof(MINIDUMP_STRING) +
103 kTypeNameStringDataLength, 103 kTypeNameStringDataLength,
104 string_file.string().size()); 104 string_file.string().size());
105 105
106 const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr; 106 const MINIDUMP_HANDLE_DATA_STREAM* handle_data_stream = nullptr;
107 ASSERT_NO_FATAL_FAILURE( 107 ASSERT_NO_FATAL_FAILURE(
108 GetHandleDataStream(string_file.string(), &handle_data_stream)); 108 GetHandleDataStream(string_file.string(), &handle_data_stream));
109 109
110 EXPECT_EQ(1u, handle_data_stream->NumberOfDescriptors); 110 EXPECT_EQ(1u, handle_data_stream->NumberOfDescriptors);
111 const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor = 111 const MINIDUMP_HANDLE_DESCRIPTOR* handle_descriptor =
112 reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>( 112 reinterpret_cast<const MINIDUMP_HANDLE_DESCRIPTOR*>(
113 &handle_data_stream[1]); 113 &handle_data_stream[1]);
114 EXPECT_EQ(handle_snapshot.handle, handle_descriptor->Handle); 114 EXPECT_EQ(handle_snapshot.handle, handle_descriptor->Handle);
115 EXPECT_EQ(handle_snapshot.type_name, 115 EXPECT_EQ(handle_snapshot.type_name,
116 MinidumpStringAtRVAAsString(string_file.string(), 116 base::UTF16ToUTF8(MinidumpStringAtRVAAsString(
117 handle_descriptor->TypeNameRva)); 117 string_file.string(), handle_descriptor->TypeNameRva)));
118 EXPECT_EQ(0u, handle_descriptor->ObjectNameRva); 118 EXPECT_EQ(0u, handle_descriptor->ObjectNameRva);
119 EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes); 119 EXPECT_EQ(handle_snapshot.attributes, handle_descriptor->Attributes);
120 EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess); 120 EXPECT_EQ(handle_snapshot.granted_access, handle_descriptor->GrantedAccess);
121 EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount); 121 EXPECT_EQ(handle_snapshot.handle_count, handle_descriptor->HandleCount);
122 EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount); 122 EXPECT_EQ(handle_snapshot.pointer_count, handle_descriptor->PointerCount);
123 } 123 }
124 124
125 } // namespace 125 } // namespace
126 } // namespace test 126 } // namespace test
127 } // namespace crashpad 127 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698