Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "courgette/base_test_unittest.h" | |
| 5 #include "courgette/image_info.h" | 6 #include "courgette/image_info.h" |
| 6 | 7 |
| 7 #include <string> | 8 class ImageInfoTest : public BaseTest { |
| 8 | |
| 9 #include "base/path_service.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/string_util.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 class ImageInfoTest : public testing::Test { | |
| 16 public: | 9 public: |
| 17 | 10 |
| 18 void TestExe() const; | 11 void TestExe() const; |
| 19 void TestResourceDll() const; | 12 void TestResourceDll() const; |
| 20 | 13 |
| 21 private: | 14 protected: |
|
Michael Krebs
2011/10/17 21:22:14
Did you intend to change ExpectExecutable() to be
dgarrett
2011/10/17 21:50:59
No, but don't really care either way. I can switch
| |
| 22 void SetUp() { | |
| 23 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_); | |
| 24 test_dir_ = test_dir_.AppendASCII("courgette"); | |
| 25 test_dir_ = test_dir_.AppendASCII("testdata"); | |
| 26 } | |
| 27 | |
| 28 void TearDown() { | |
| 29 } | |
| 30 | |
| 31 void ExpectExecutable(courgette::PEInfo* info) const; | 15 void ExpectExecutable(courgette::PEInfo* info) const; |
| 32 | 16 |
| 33 std::string FileContents(const char* file_name) const; | |
| 34 | |
| 35 FilePath test_dir_; | |
| 36 }; | 17 }; |
| 37 | 18 |
| 38 // Reads a test file into a string. | |
| 39 std::string ImageInfoTest::FileContents(const char* file_name) const { | |
| 40 FilePath file_path = test_dir_; | |
| 41 file_path = file_path.AppendASCII(file_name); | |
| 42 std::string file_bytes; | |
| 43 if (!file_util::ReadFileToString(file_path, &file_bytes)) { | |
| 44 EXPECT_TRUE(!"Could not read test data"); | |
| 45 } | |
| 46 return file_bytes; | |
| 47 } | |
| 48 | |
| 49 void ImageInfoTest::ExpectExecutable(courgette::PEInfo* info) const { | 19 void ImageInfoTest::ExpectExecutable(courgette::PEInfo* info) const { |
| 50 EXPECT_TRUE(info->ok()); | 20 EXPECT_TRUE(info->ok()); |
| 51 EXPECT_TRUE(info->has_text_section()); | 21 EXPECT_TRUE(info->has_text_section()); |
| 52 } | 22 } |
| 53 | 23 |
| 54 void ImageInfoTest::TestExe() const { | 24 void ImageInfoTest::TestExe() const { |
| 55 std::string file1 = FileContents("setup1.exe"); | 25 std::string file1 = FileContents("setup1.exe"); |
| 56 | 26 |
| 57 scoped_ptr<courgette::PEInfo> info(new courgette::PEInfo()); | 27 scoped_ptr<courgette::PEInfo> info(new courgette::PEInfo()); |
| 58 info->Init(reinterpret_cast<const uint8*>(file1.c_str()), file1.length()); | 28 info->Init(reinterpret_cast<const uint8*>(file1.c_str()), file1.length()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 | 67 |
| 98 EXPECT_TRUE(info->ok()); | 68 EXPECT_TRUE(info->ok()); |
| 99 EXPECT_FALSE(info->has_text_section()); | 69 EXPECT_FALSE(info->has_text_section()); |
| 100 EXPECT_EQ(0U, info->size_of_code()); | 70 EXPECT_EQ(0U, info->size_of_code()); |
| 101 } | 71 } |
| 102 | 72 |
| 103 TEST_F(ImageInfoTest, All) { | 73 TEST_F(ImageInfoTest, All) { |
| 104 TestExe(); | 74 TestExe(); |
| 105 TestResourceDll(); | 75 TestResourceDll(); |
| 106 } | 76 } |
| OLD | NEW |