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

Side by Side Diff: snapshot/win/pe_image_reader_test.cc

Issue 1336823002: win x86: Grab bag of restructuring to get tests working on x86-on-x86 (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes2 Created 5 years, 3 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 "snapshot/win/pe_image_reader.h" 15 #include "snapshot/win/pe_image_reader.h"
16 16
17 #define PSAPI_VERSION 1
17 #include <psapi.h> 18 #include <psapi.h>
18 19
19 #include "gtest/gtest.h" 20 #include "gtest/gtest.h"
20 #include "snapshot/win/process_reader_win.h" 21 #include "snapshot/win/process_reader_win.h"
21 22
22 extern "C" IMAGE_DOS_HEADER __ImageBase; 23 extern "C" IMAGE_DOS_HEADER __ImageBase;
23 24
24 namespace crashpad { 25 namespace crashpad {
25 namespace test { 26 namespace test {
26 namespace { 27 namespace {
27 28
29 BOOL CrashpadGetModuleInformation(HANDLE process,
30 HMODULE module,
31 MODULEINFO* module_info,
32 DWORD cb) {
33 static decltype(GetModuleInformation)* get_module_information =
34 reinterpret_cast<decltype(GetModuleInformation)*>(
35 GetProcAddress(LoadLibrary(L"psapi.dll"), "GetModuleInformation"));
36 DCHECK(get_module_information);
37 return get_module_information(process, module, module_info, cb);
38 }
39
28 TEST(PEImageReader, DebugDirectory) { 40 TEST(PEImageReader, DebugDirectory) {
29 PEImageReader pe_image_reader; 41 PEImageReader pe_image_reader;
30 ProcessReaderWin process_reader; 42 ProcessReaderWin process_reader;
31 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(), 43 ASSERT_TRUE(process_reader.Initialize(GetCurrentProcess(),
32 ProcessSuspensionState::kRunning)); 44 ProcessSuspensionState::kRunning));
33 HMODULE self = reinterpret_cast<HMODULE>(&__ImageBase); 45 HMODULE self = reinterpret_cast<HMODULE>(&__ImageBase);
34 MODULEINFO module_info; 46 MODULEINFO module_info;
35 ASSERT_TRUE(GetModuleInformation( 47 ASSERT_TRUE(CrashpadGetModuleInformation(
36 GetCurrentProcess(), self, &module_info, sizeof(module_info))); 48 GetCurrentProcess(), self, &module_info, sizeof(module_info)));
37 EXPECT_EQ(self, module_info.lpBaseOfDll); 49 EXPECT_EQ(self, module_info.lpBaseOfDll);
38 EXPECT_TRUE(pe_image_reader.Initialize(&process_reader, 50 EXPECT_TRUE(pe_image_reader.Initialize(&process_reader,
39 reinterpret_cast<WinVMAddress>(self), 51 reinterpret_cast<WinVMAddress>(self),
40 module_info.SizeOfImage, 52 module_info.SizeOfImage,
41 "self")); 53 "self"));
42 UUID uuid; 54 UUID uuid;
43 DWORD age; 55 DWORD age;
44 std::string pdbname; 56 std::string pdbname;
45 EXPECT_TRUE(pe_image_reader.DebugDirectoryInformation(&uuid, &age, &pdbname)); 57 EXPECT_TRUE(pe_image_reader.DebugDirectoryInformation(&uuid, &age, &pdbname));
46 EXPECT_NE(std::string::npos, pdbname.find("crashpad_snapshot_test")); 58 EXPECT_NE(std::string::npos, pdbname.find("crashpad_snapshot_test"));
47 const std::string suffix(".pdb"); 59 const std::string suffix(".pdb");
48 EXPECT_EQ( 60 EXPECT_EQ(
49 0, 61 0,
50 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); 62 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix));
51 } 63 }
52 64
53 } // namespace 65 } // namespace
54 } // namespace test 66 } // namespace test
55 } // namespace crashpad 67 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698