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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "courgette/assembly_program.h" | 8 #include "courgette/assembly_program.h" |
6 #include "courgette/base_test_unittest.h" | 9 #include "courgette/base_test_unittest.h" |
7 #include "courgette/disassembler_elf_32_x86.h" | 10 #include "courgette/disassembler_elf_32_x86.h" |
8 | 11 |
9 class DisassemblerElf32X86Test : public BaseTest { | 12 class DisassemblerElf32X86Test : public BaseTest { |
10 public: | 13 public: |
11 | 14 |
12 void TestExe(const char* file_name, | 15 void TestExe(const char* file_name, |
13 size_t expected_abs_count, | 16 size_t expected_abs_count, |
14 size_t expected_rel_count) const; | 17 size_t expected_rel_count) const; |
15 }; | 18 }; |
16 | 19 |
17 void DisassemblerElf32X86Test::TestExe(const char* file_name, | 20 void DisassemblerElf32X86Test::TestExe(const char* file_name, |
18 size_t expected_abs_count, | 21 size_t expected_abs_count, |
19 size_t expected_rel_count) const { | 22 size_t expected_rel_count) const { |
20 std::string file1 = FileContents(file_name); | 23 std::string file1 = FileContents(file_name); |
21 | 24 |
22 scoped_ptr<courgette::DisassemblerElf32X86> disassembler( | 25 scoped_ptr<courgette::DisassemblerElf32X86> disassembler( |
23 new courgette::DisassemblerElf32X86(file1.c_str(), file1.length())); | 26 new courgette::DisassemblerElf32X86(file1.c_str(), file1.length())); |
24 | 27 |
25 bool can_parse_header = disassembler->ParseHeader(); | 28 bool can_parse_header = disassembler->ParseHeader(); |
26 EXPECT_TRUE(can_parse_header); | 29 EXPECT_TRUE(can_parse_header); |
27 EXPECT_TRUE(disassembler->ok()); | 30 EXPECT_TRUE(disassembler->ok()); |
28 | 31 |
29 // The length of the disassembled value will be slightly smaller than the | 32 // The length of the disassembled value will be slightly smaller than the |
30 // real file, since trailing debug info is not included | 33 // real file, since trailing debug info is not included |
31 EXPECT_EQ(file1.length(), disassembler->length()); | 34 EXPECT_EQ(file1.length(), disassembler->length()); |
32 | 35 |
33 const uint8* offset_p = disassembler->OffsetToPointer(0); | 36 const uint8_t* offset_p = disassembler->OffsetToPointer(0); |
34 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), | 37 EXPECT_EQ(reinterpret_cast<const void*>(file1.c_str()), |
35 reinterpret_cast<const void*>(offset_p)); | 38 reinterpret_cast<const void*>(offset_p)); |
36 EXPECT_EQ(0x7F, offset_p[0]); | 39 EXPECT_EQ(0x7F, offset_p[0]); |
37 EXPECT_EQ('E', offset_p[1]); | 40 EXPECT_EQ('E', offset_p[1]); |
38 EXPECT_EQ('L', offset_p[2]); | 41 EXPECT_EQ('L', offset_p[2]); |
39 EXPECT_EQ('F', offset_p[3]); | 42 EXPECT_EQ('F', offset_p[3]); |
40 | 43 |
41 courgette::AssemblyProgram* program = | 44 courgette::AssemblyProgram* program = |
42 new courgette::AssemblyProgram(courgette::EXE_ELF_32_X86); | 45 new courgette::AssemblyProgram(courgette::EXE_ELF_32_X86); |
43 | 46 |
(...skipping 30 matching lines...) Expand all Loading... |
74 } | 77 } |
75 } | 78 } |
76 EXPECT_TRUE(!found); | 79 EXPECT_TRUE(!found); |
77 } | 80 } |
78 delete program; | 81 delete program; |
79 } | 82 } |
80 | 83 |
81 TEST_F(DisassemblerElf32X86Test, All) { | 84 TEST_F(DisassemblerElf32X86Test, All) { |
82 TestExe("elf-32-1", 200, 3442); | 85 TestExe("elf-32-1", 200, 3442); |
83 } | 86 } |
OLD | NEW |