# Path: cle/address_translator.py
# AT = AddressTranslator


import nose
import cle
from cle.address_translator import AT



class MockBackend(cle.Backend):
    def __init__(self, linked_base, mapped_base, *nargs, **kwargs):
        super().__init__("/dev/zero", None, *nargs, **kwargs)
        regions = [
            cle.Region(0x000000, 0x8048000, 0x1b2d30, 0x1b2d30),
            cle.Region(0x1b3260, 0x81fc260, 0x002c74, 0x0057bc)
        ]
        self.linked_base = linked_base
        self.mapped_base = mapped_base
        self.segments = cle.Regions(lst=regions)
        self.sections = self.segments
        self.segments._rebase(self.image_base_delta)
        self._is_mapped = True


owner = MockBackend(0x8048000, 0xa000000)


def test_lva_mva_translation():
    nose.tools.assert_equal(AT.from_lva(0x8048000, owner).to_mva(), 0xa000000)
    nose.tools.assert_equal(AT.from_mva(0xa1b9a1b, owner).to_lva(), 0x8201a1b)


def test_va_rva_translation():

# Path: cle/address_translator.py
# AT = AddressTranslator


# Path: tests/test_address_translator.py
import nose
import cle
from cle.address_translator import AT




class MockBackend(cle.Backend):
    def __init__(self, linked_base, mapped_base, *nargs, **kwargs):
        super().__init__("/dev/zero", None, *nargs, **kwargs)
        regions = [
            cle.Region(0x000000, 0x8048000, 0x1b2d30, 0x1b2d30),
            cle.Region(0x1b3260, 0x81fc260, 0x002c74, 0x0057bc)
        ]
        self.linked_base = linked_base
        self.mapped_base = mapped_base
        self.segments = cle.Regions(lst=regions)
        self.sections = self.segments
        self.segments._rebase(self.image_base_delta)
        self._is_mapped = True


owner = MockBackend(0x8048000, 0xa000000)


def test_lva_mva_translation():
    nose.tools.assert_equal(AT.from_lva(0x8048000, owner).to_mva(), 0xa000000)
    nose.tools.assert_equal(AT.from_mva(0xa1b9a1b, owner).to_lva(), 0x8201a1b)


def test_va_rva_translation():

    nose.tools.assert_equal(AT.from_rva(0, owner).to_va(), 0xa000000)