| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/win/windows_version.h" |
| 10 | 10 |
| 11 // Just counts the number of invocations. | 11 // Just counts the number of invocations. |
| 12 bool ExportsCallback(const PEImage &image, | 12 bool ExportsCallback(const PEImage &image, |
| 13 DWORD ordinal, | 13 DWORD ordinal, |
| 14 DWORD hint, | 14 DWORD hint, |
| 15 LPCSTR name, | 15 LPCSTR name, |
| 16 PVOID function, | 16 PVOID function, |
| 17 LPCSTR forward, | 17 LPCSTR forward, |
| 18 PVOID cookie) { | 18 PVOID cookie) { |
| 19 int* count = reinterpret_cast<int*>(cookie); | 19 int* count = reinterpret_cast<int*>(cookie); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 else | 140 else |
| 141 return 0; | 141 return 0; |
| 142 | 142 |
| 143 return expected[value][os]; | 143 return expected[value][os]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Tests that we are able to enumerate stuff from a PE file, and that | 146 // Tests that we are able to enumerate stuff from a PE file, and that |
| 147 // the actual number of items found is within the expected range. | 147 // the actual number of items found is within the expected range. |
| 148 TEST(PEImageTest, EnumeratesPE) { | 148 TEST(PEImageTest, EnumeratesPE) { |
| 149 // Windows Server 2003 is not supported as a test environment for this test. | 149 // Windows Server 2003 is not supported as a test environment for this test. |
| 150 if (win_util::GetWinVersion() == win_util::WINVERSION_SERVER_2003) | 150 if (base::win::GetVersion() == base::win::VERSION_SERVER_2003) |
| 151 return; | 151 return; |
| 152 HMODULE module = LoadLibrary(L"advapi32.dll"); | 152 HMODULE module = LoadLibrary(L"advapi32.dll"); |
| 153 ASSERT_TRUE(NULL != module); | 153 ASSERT_TRUE(NULL != module); |
| 154 | 154 |
| 155 PEImage pe(module); | 155 PEImage pe(module); |
| 156 int count = 0; | 156 int count = 0; |
| 157 EXPECT_TRUE(pe.VerifyMagic()); | 157 EXPECT_TRUE(pe.VerifyMagic()); |
| 158 | 158 |
| 159 DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; | 159 DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; |
| 160 os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; | 160 os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 EXPECT_TRUE(pe.GetProcOrdinal("RegEnumKeyExW", &ordinal)); | 204 EXPECT_TRUE(pe.GetProcOrdinal("RegEnumKeyExW", &ordinal)); |
| 205 | 205 |
| 206 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); | 206 FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); |
| 207 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal)); | 207 FARPROC address2 = pe.GetProcAddress(reinterpret_cast<char*>(ordinal)); |
| 208 EXPECT_TRUE(address1 != NULL); | 208 EXPECT_TRUE(address1 != NULL); |
| 209 EXPECT_TRUE(address2 != NULL); | 209 EXPECT_TRUE(address2 != NULL); |
| 210 EXPECT_TRUE(address1 == address2); | 210 EXPECT_TRUE(address1 == address2); |
| 211 | 211 |
| 212 FreeLibrary(module); | 212 FreeLibrary(module); |
| 213 } | 213 } |
| OLD | NEW |