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

Side by Side Diff: base/win/pe_image_unittest.cc

Issue 1370843003: Remove warning pragmas in pe_image.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
« base/win/pe_image.cc ('K') | « base/win/pe_image_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains unit tests for PEImage. 5 // This file contains unit tests for PEImage.
6 #include <algorithm> 6 #include <algorithm>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 base::FilePath pe_image_test_path; 95 base::FilePath pe_image_test_path;
96 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &pe_image_test_path)); 96 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &pe_image_test_path));
97 pe_image_test_path = pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image")); 97 pe_image_test_path = pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image"));
98 98
99 #if defined(ARCH_CPU_64_BITS) 99 #if defined(ARCH_CPU_64_BITS)
100 pe_image_test_path = 100 pe_image_test_path =
101 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_64.dll")); 101 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_64.dll"));
102 const int sections = 6; 102 const int sections = 6;
103 const int imports_dlls = 2; 103 const int imports_dlls = 2;
104 const int delay_dlls = 2; 104 const int delay_dlls = 2;
105 const int exports = 2; 105 const int exports = 3;
106 const int imports = 69; 106 const int imports = 70;
107 const int delay_imports = 2; 107 const int delay_imports = 2;
108 const int relocs = 632; 108 const int relocs = 976;
109 #else 109 #else
110 pe_image_test_path = 110 pe_image_test_path =
111 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_32.dll")); 111 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_32.dll"));
112 const int sections = 5; 112 const int sections = 5;
113 const int imports_dlls = 2; 113 const int imports_dlls = 2;
114 const int delay_dlls = 2; 114 const int delay_dlls = 2;
115 const int exports = 2; 115 const int exports = 3;
116 const int imports = 66; 116 const int imports = 66;
117 const int delay_imports = 2; 117 const int delay_imports = 2;
118 const int relocs = 1586; 118 const int relocs = 2114;
119 #endif 119 #endif
120 120
121 HMODULE module = LoadLibrary(pe_image_test_path.value().c_str()); 121 HMODULE module = LoadLibrary(pe_image_test_path.value().c_str());
122 ASSERT_TRUE(NULL != module); 122 ASSERT_TRUE(NULL != module);
123 123
124 PEImage pe(module); 124 PEImage pe(module);
125 int count = 0; 125 int count = 0;
126 EXPECT_TRUE(pe.VerifyMagic()); 126 EXPECT_TRUE(pe.VerifyMagic());
127 127
128 pe.EnumSections(SectionsCallback, &count); 128 pe.EnumSections(SectionsCallback, &count);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); 168 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW");
169 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal)); 169 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal));
170 EXPECT_TRUE(address1 != NULL); 170 EXPECT_TRUE(address1 != NULL);
171 EXPECT_TRUE(address2 != NULL); 171 EXPECT_TRUE(address2 != NULL);
172 EXPECT_TRUE(address1 == address2); 172 EXPECT_TRUE(address1 == address2);
173 173
174 FreeLibrary(module); 174 FreeLibrary(module);
175 } 175 }
176 176
177 // Tests that we can locate a forwarded export.
178 TEST(PEImageTest, ForwardedExport) {
179 base::FilePath pe_image_test_path;
180 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &pe_image_test_path));
181 pe_image_test_path = pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image"));
182
183 #if defined(ARCH_CPU_64_BITS)
184 pe_image_test_path =
185 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_64.dll"));
186 #else
187 pe_image_test_path =
188 pe_image_test_path.Append(FILE_PATH_LITERAL("pe_image_test_32.dll"));
189 #endif
190
191 HMODULE module = LoadLibrary(pe_image_test_path.value().c_str());
192 ASSERT_TRUE(NULL != module);
193
194 PEImage pe(module);
195
196 FARPROC addr = pe.GetProcAddress("FwdExport");
197 EXPECT_EQ(FARPROC(-1), addr);
Nico 2015/12/24 14:11:11 same question
Will Harris 2015/12/24 19:22:03 Acknowledged.
198
199 PDWORD export_entry = pe.GetExportEntry("FwdExport");
200 EXPECT_NE(nullptr, export_entry);
201 PVOID fwd_addr = pe.RVAToAddr(*export_entry);
202 const char expected_fwd[] = "KERNEL32.CreateFileA";
203 EXPECT_STREQ(expected_fwd, reinterpret_cast<char*>(fwd_addr));
204
205 FreeLibrary(module);
Nico 2015/12/24 14:11:11 (i'm a bit surprised we don't have a ScopedFoo for
Will Harris 2015/12/24 19:22:03 yes, we do, it's base::ScopedNativeLibrary so I sw
206 }
207
177 // Test that we can get debug id out of a module. 208 // Test that we can get debug id out of a module.
178 TEST(PEImageTest, GetDebugId) { 209 TEST(PEImageTest, GetDebugId) {
179 HMODULE module = LoadLibrary(L"advapi32.dll"); 210 HMODULE module = LoadLibrary(L"advapi32.dll");
180 ASSERT_TRUE(NULL != module); 211 ASSERT_TRUE(NULL != module);
181 212
182 PEImage pe(module); 213 PEImage pe(module);
183 GUID guid = {0}; 214 GUID guid = {0};
184 DWORD age = 0; 215 DWORD age = 0;
185 EXPECT_TRUE(pe.GetDebugId(&guid, &age)); 216 EXPECT_TRUE(pe.GetDebugId(&guid, &age));
186 217
187 GUID empty_guid = {0}; 218 GUID empty_guid = {0};
188 EXPECT_TRUE(!IsEqualGUID(empty_guid, guid)); 219 EXPECT_TRUE(!IsEqualGUID(empty_guid, guid));
189 EXPECT_NE(0U, age); 220 EXPECT_NE(0U, age);
190 FreeLibrary(module); 221 FreeLibrary(module);
191 } 222 }
192 223
193 } // namespace win 224 } // namespace win
194 } // namespace base 225 } // namespace base
OLDNEW
« base/win/pe_image.cc ('K') | « base/win/pe_image_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698