typedrva_unittest.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2013 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. #include <stdint.h>
  5. #include "courgette/base_test_unittest.h"
  6. #include "courgette/disassembler_elf_32_x86.h"
  7. #include "courgette/image_utils.h"
  8. class TypedRVATest : public BaseTest {
  9. public:
  10. void TestRelativeTargetX86(courgette::RVA word, courgette::RVA expected)
  11. const;
  12. };
  13. void TypedRVATest::TestRelativeTargetX86(courgette::RVA word,
  14. courgette::RVA expected) const {
  15. courgette::DisassemblerElf32X86::TypedRVAX86* typed_rva
  16. = new courgette::DisassemblerElf32X86::TypedRVAX86(0);
  17. const uint8_t* op_pointer = reinterpret_cast<const uint8_t*>(&word);
  18. EXPECT_TRUE(typed_rva->ComputeRelativeTarget(op_pointer));
  19. EXPECT_EQ(typed_rva->relative_target(), expected);
  20. delete typed_rva;
  21. }
  22. uint32_t Read32LittleEndian(const void* address) {
  23. return *reinterpret_cast<const uint32_t*>(address);
  24. }
  25. TEST_F(TypedRVATest, TestX86) {
  26. TestRelativeTargetX86(0x0, 0x4);
  27. }