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

Side by Side Diff: courgette/image_info_unittest.cc

Issue 8166013: Further refactoring, move ImageInfo into Disassembler/DisassemblerWin32X86. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase over other changes, fix nit. Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « courgette/image_info.cc ('k') | courgette/types_win_pe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "courgette/base_test_unittest.h"
6 #include "courgette/image_info.h"
7
8 class ImageInfoTest : public BaseTest {
9 public:
10
11 void TestExe() const;
12 void TestResourceDll() const;
13
14 private:
15 void ExpectExecutable(courgette::PEInfo* info) const;
16
17 };
18
19 void ImageInfoTest::ExpectExecutable(courgette::PEInfo* info) const {
20 EXPECT_TRUE(info->ok());
21 EXPECT_TRUE(info->has_text_section());
22 }
23
24 void ImageInfoTest::TestExe() const {
25 std::string file1 = FileContents("setup1.exe");
26
27 scoped_ptr<courgette::PEInfo> info(new courgette::PEInfo());
28 info->Init(reinterpret_cast<const uint8*>(file1.c_str()), file1.length());
29
30 bool can_parse_header = info->ParseHeader();
31 EXPECT_TRUE(can_parse_header);
32
33 // The executable is the whole file, not 'embedded' with the file
34 EXPECT_EQ(file1.length(), info->length());
35
36 ExpectExecutable(info.get());
37 EXPECT_EQ(449536U, info->size_of_code());
38 EXPECT_EQ(SectionName(info->RVAToSection(0x00401234 - 0x00400000)),
39 std::string(".text"));
40
41 EXPECT_EQ(0, info->RVAToFileOffset(0));
42 EXPECT_EQ(1024, info->RVAToFileOffset(4096));
43 EXPECT_EQ(46928, info->RVAToFileOffset(50000));
44
45 std::vector<courgette::RVA> relocs;
46 bool can_parse_relocs = info->ParseRelocs(&relocs);
47 EXPECT_TRUE(can_parse_relocs);
48
49 const uint8* p = info->RVAToPointer(0);
50 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()),
51 reinterpret_cast<const void*>(p));
52 EXPECT_EQ('M', p[0]);
53 EXPECT_EQ('Z', p[1]);
54 }
55
56 void ImageInfoTest::TestResourceDll() const {
57 std::string file1 = FileContents("en-US.dll");
58
59 scoped_ptr<courgette::PEInfo> info(new courgette::PEInfo());
60 info->Init(reinterpret_cast<const uint8*>(file1.c_str()), file1.length());
61
62 // This is expected to fail, since we don't really support them yet.
63 bool can_parse_header = info->ParseHeader();
64 EXPECT_FALSE(can_parse_header);
65
66 // The executable is the whole file, not 'embedded' with the file
67 EXPECT_EQ(file1.length(), info->length());
68
69 EXPECT_FALSE(info->ok());
70 EXPECT_FALSE(info->has_text_section());
71 EXPECT_EQ(0U, info->size_of_code());
72 }
73
74 TEST_F(ImageInfoTest, All) {
75 TestExe();
76 TestResourceDll();
77 }
OLDNEW
« no previous file with comments | « courgette/image_info.cc ('k') | courgette/types_win_pe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698