OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <windows.h> | 6 #include <windows.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/basictypes.h" | |
13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
15 #include "base/files/memory_mapped_file.h" | 14 #include "base/files/memory_mapped_file.h" |
16 #include "base/path_service.h" | 15 #include "base/path_service.h" |
17 #include "base/strings/pattern.h" | 16 #include "base/strings/pattern.h" |
18 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
19 #include "base/win/pe_image.h" | 18 #include "base/win/pe_image.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 | 20 |
22 namespace { | 21 namespace { |
(...skipping 12 matching lines...) Expand all Loading... |
35 } | 34 } |
36 | 35 |
37 void GetImports(const base::FilePath& module_path, | 36 void GetImports(const base::FilePath& module_path, |
38 std::vector<std::string>* imports) { | 37 std::vector<std::string>* imports) { |
39 ASSERT_TRUE(imports != NULL); | 38 ASSERT_TRUE(imports != NULL); |
40 | 39 |
41 base::MemoryMappedFile module_mmap; | 40 base::MemoryMappedFile module_mmap; |
42 | 41 |
43 ASSERT_TRUE(module_mmap.Initialize(module_path)); | 42 ASSERT_TRUE(module_mmap.Initialize(module_path)); |
44 base::win::PEImageAsData pe_image_data( | 43 base::win::PEImageAsData pe_image_data( |
45 reinterpret_cast<HMODULE>(const_cast<uint8*>(module_mmap.data()))); | 44 reinterpret_cast<HMODULE>(const_cast<uint8_t*>(module_mmap.data()))); |
46 pe_image_data.EnumImportChunks(ELFImportsTest::ImportsCallback, imports); | 45 pe_image_data.EnumImportChunks(ELFImportsTest::ImportsCallback, imports); |
47 } | 46 } |
48 }; | 47 }; |
49 | 48 |
50 // Run this test only in Release builds. | 49 // Run this test only in Release builds. |
51 // | 50 // |
52 // This test makes sure that chrome_elf.dll has only certain types of imports. | 51 // This test makes sure that chrome_elf.dll has only certain types of imports. |
53 // However, it directly and indirectly depends on base, which has lots more | 52 // However, it directly and indirectly depends on base, which has lots more |
54 // imports than are allowed here. | 53 // imports than are allowed here. |
55 // | 54 // |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " | 113 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " |
115 "target was built, instead of chrome_elf_unittests.exe"; | 114 "target was built, instead of chrome_elf_unittests.exe"; |
116 | 115 |
117 // Chrome.exe's first import must be ELF. | 116 // Chrome.exe's first import must be ELF. |
118 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << | 117 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << |
119 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " | 118 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " |
120 "target was built, instead of just chrome_elf_unittests.exe)"; | 119 "target was built, instead of just chrome_elf_unittests.exe)"; |
121 } | 120 } |
122 | 121 |
123 } // namespace | 122 } // namespace |
OLD | NEW |