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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/memory_mapped_file.h" | 6 #include "base/files/memory_mapped_file.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/browser/safe_browsing/pe_image_reader_win.h" | 8 #include "chrome/browser/safe_browsing/pe_image_reader_win.h" |
9 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 struct TestData { | 12 struct TestData { |
13 const char* filename; | 13 const char* filename; |
14 safe_browsing::PeImageReader::WordSize word_size; | 14 safe_browsing::PeImageReader::WordSize word_size; |
15 WORD machine_identifier; | 15 WORD machine_identifier; |
16 WORD optional_header_size; | 16 WORD optional_header_size; |
17 size_t number_of_sections; | 17 size_t number_of_sections; |
18 size_t number_of_debug_entries; | 18 size_t number_of_debug_entries; |
19 }; | 19 }; |
20 | 20 |
21 // A test fixture parameterized on test data containing the name of a PE image | 21 // A test fixture parameterized on test data containing the name of a PE image |
22 // to parse and the expected values to be read from it. The file is read from | 22 // to parse and the expected values to be read from it. The file is read from |
23 // the src/chrome/test/data/safe_browsing directory. | 23 // the src/chrome/test/data/safe_browsing directory. |
24 class PeImageReaderTest : public testing::TestWithParam<const TestData*> { | 24 class PeImageReaderTest : public testing::TestWithParam<const TestData*> { |
25 protected: | 25 protected: |
26 PeImageReaderTest() : expected_data_(GetParam()) {} | 26 PeImageReaderTest() : expected_data_(GetParam()) {} |
27 | 27 |
28 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() override { |
29 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_file_path_)); | 29 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_file_path_)); |
30 data_file_path_ = data_file_path_.AppendASCII("safe_browsing"); | 30 data_file_path_ = data_file_path_.AppendASCII("safe_browsing"); |
31 data_file_path_ = data_file_path_.AppendASCII(expected_data_->filename); | 31 data_file_path_ = data_file_path_.AppendASCII(expected_data_->filename); |
32 | 32 |
33 ASSERT_TRUE(data_file_.Initialize(data_file_path_)); | 33 ASSERT_TRUE(data_file_.Initialize(data_file_path_)); |
34 | 34 |
35 ASSERT_TRUE(image_reader_.Initialize(data_file_.data(), | 35 ASSERT_TRUE(image_reader_.Initialize(data_file_.data(), |
36 data_file_.length())); | 36 data_file_.length())); |
37 } | 37 } |
38 | 38 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 }; | 148 }; |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 INSTANTIATE_TEST_CASE_P(WordSize32, | 152 INSTANTIATE_TEST_CASE_P(WordSize32, |
153 PeImageReaderTest, | 153 PeImageReaderTest, |
154 testing::Values(&kTestData[0])); | 154 testing::Values(&kTestData[0])); |
155 INSTANTIATE_TEST_CASE_P(WordSize64, | 155 INSTANTIATE_TEST_CASE_P(WordSize64, |
156 PeImageReaderTest, | 156 PeImageReaderTest, |
157 testing::Values(&kTestData[1])); | 157 testing::Values(&kTestData[1])); |
OLD | NEW |