OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "base/pe_image.h" | 8 #include "base/pe_image.h" |
| 9 #include "base/win_util.h" |
9 | 10 |
10 // Just counts the number of invocations. | 11 // Just counts the number of invocations. |
11 bool ExportsCallback(const PEImage &image, | 12 bool ExportsCallback(const PEImage &image, |
12 DWORD ordinal, | 13 DWORD ordinal, |
13 DWORD hint, | 14 DWORD hint, |
14 LPCSTR name, | 15 LPCSTR name, |
15 PVOID function, | 16 PVOID function, |
16 LPCSTR forward, | 17 LPCSTR forward, |
17 PVOID cookie) { | 18 PVOID cookie) { |
18 int* count = reinterpret_cast<int*>(cookie); | 19 int* count = reinterpret_cast<int*>(cookie); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 os = 2; // 6.x | 131 os = 2; // 6.x |
131 else | 132 else |
132 return 0; | 133 return 0; |
133 | 134 |
134 return expected[value][os]; | 135 return expected[value][os]; |
135 } | 136 } |
136 | 137 |
137 // Tests that we are able to enumerate stuff from a PE file, and that | 138 // Tests that we are able to enumerate stuff from a PE file, and that |
138 // the actual number of items found is within the expected range. | 139 // the actual number of items found is within the expected range. |
139 TEST(PEImageTest, EnumeratesPE) { | 140 TEST(PEImageTest, EnumeratesPE) { |
| 141 // TODO(rvargas): Quick workaround until this issue is fixed: |
| 142 // http://code.google.com/p/chromium/issues/detail?id=2732 |
| 143 // Note that this bug is about Windows 2003 x64, not Win2k3 in general. |
| 144 if (win_util::GetWinVersion() == win_util::WINVERSION_SERVER_2003) |
| 145 return; |
140 HMODULE module = LoadLibrary(L"advapi32.dll"); | 146 HMODULE module = LoadLibrary(L"advapi32.dll"); |
141 ASSERT_TRUE(NULL != module); | 147 ASSERT_TRUE(NULL != module); |
142 | 148 |
143 PEImage pe(module); | 149 PEImage pe(module); |
144 int count = 0; | 150 int count = 0; |
145 EXPECT_TRUE(pe.VerifyMagic()); | 151 EXPECT_TRUE(pe.VerifyMagic()); |
146 | 152 |
147 DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; | 153 DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; |
148 os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; | 154 os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; |
149 | 155 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 199 |
194 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); | 200 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); |
195 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal)); | 201 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal)); |
196 EXPECT_TRUE(address1 != NULL); | 202 EXPECT_TRUE(address1 != NULL); |
197 EXPECT_TRUE(address2 != NULL); | 203 EXPECT_TRUE(address2 != NULL); |
198 EXPECT_TRUE(address1 == address2); | 204 EXPECT_TRUE(address1 == address2); |
199 | 205 |
200 FreeLibrary(module); | 206 FreeLibrary(module); |
201 } | 207 } |
202 | 208 |
OLD | NEW |