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

Side by Side Diff: chrome_elf/elf_imports_unittest.cc

Issue 1226673003: Move MatchPattern to its own header and the base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « chrome/common/trace_event_args_whitelist.cc ('k') | components/domain_reliability/config.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/memory_mapped_file.h" 15 #include "base/files/memory_mapped_file.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/pattern.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/win/pe_image.h" 19 #include "base/win/pe_image.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 23
23 class ELFImportsTest : public testing::Test { 24 class ELFImportsTest : public testing::Test {
24 protected: 25 protected:
25 static bool ImportsCallback(const base::win::PEImage &image, 26 static bool ImportsCallback(const base::win::PEImage &image,
26 LPCSTR module, 27 LPCSTR module,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #if defined(ADDRESS_SANITIZER) && defined(COMPONENT_BUILD) 70 #if defined(ADDRESS_SANITIZER) && defined(COMPONENT_BUILD)
70 "clang_rt.asan_dynamic-i386.dll", 71 "clang_rt.asan_dynamic-i386.dll",
71 #endif 72 #endif
72 "ADVAPI32.dll" 73 "ADVAPI32.dll"
73 }; 74 };
74 75
75 // Make sure all of ELF's imports are in the valid imports list. 76 // Make sure all of ELF's imports are in the valid imports list.
76 for (; it != elf_imports.end(); it++) { 77 for (; it != elf_imports.end(); it++) {
77 bool match = false; 78 bool match = false;
78 for (int i = 0; i < arraysize(kValidFilePatterns); ++i) { 79 for (int i = 0; i < arraysize(kValidFilePatterns); ++i) {
79 if (MatchPattern(*it, kValidFilePatterns[i])) 80 if (base::MatchPattern(*it, kValidFilePatterns[i]))
80 match = true; 81 match = true;
81 } 82 }
82 ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << *it; 83 ASSERT_TRUE(match) << "Illegal import in chrome_elf.dll: " << *it;
83 } 84 }
84 } 85 }
85 86
86 TEST_F(ELFImportsTest, ChromeExeSanityCheck) { 87 TEST_F(ELFImportsTest, ChromeExeSanityCheck) {
87 std::vector<std::string> exe_imports; 88 std::vector<std::string> exe_imports;
88 89
89 base::FilePath exe; 90 base::FilePath exe;
90 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe)); 91 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe));
91 exe = exe.Append(L"chrome.exe"); 92 exe = exe.Append(L"chrome.exe");
92 GetImports(exe, &exe_imports); 93 GetImports(exe, &exe_imports);
93 94
94 // Check that chrome.exe has imports. 95 // Check that chrome.exe has imports.
95 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests " 96 ASSERT_LT(0u, exe_imports.size()) << "Ensure the chrome_elf_unittests "
96 "target was built, instead of chrome_elf_unittests.exe"; 97 "target was built, instead of chrome_elf_unittests.exe";
97 98
98 // Chrome.exe's first import must be ELF. 99 // Chrome.exe's first import must be ELF.
99 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) << 100 EXPECT_EQ("chrome_elf.dll", exe_imports[0]) <<
100 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest " 101 "Illegal import order in chrome.exe (ensure the chrome_elf_unittest "
101 "target was built, instead of just chrome_elf_unittests.exe)"; 102 "target was built, instead of just chrome_elf_unittests.exe)";
102 } 103 }
103 104
104 } // namespace 105 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/trace_event_args_whitelist.cc ('k') | components/domain_reliability/config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698