# Path: tests/conftest.py
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


from tests.conftest import setup_debugger
# -*- coding: utf-8 -*-

"""
This test is made towards a specific version of GDB and operating system
(i686), so it may not work elsewhere.
"""


TEST_FILE = "test_disassemble"
SRC_FILE = "src/{}.cpp".format(TEST_FILE)


def generate_instructions(instruction, reg32bit, reg64bit):
    return (instruction.format(reg32bit),
            instruction.format(reg64bit))


def test_address_invalid_file(debugger):
    def test_address_invalid_file_cb():
        assert debugger.file_manager.get_line_address("x.cpp", 0) is None


# Path: tests/conftest.py
# def setup_debugger(debugger, binary, lines, on_state_change=None,
#                    startup_info=None, cont=True, wait=True):
#     assert debugger.load_binary("src/{}".format(binary))
# 
#     test_exception = []
# 
#     if not isinstance(lines, Iterable):
#         lines = [lines]
# 
#     for line in lines:
#         assert debugger.breakpoint_manager.add_breakpoint(
#             "src/{}.cpp".format(binary), line)
# 
#     if on_state_change:
#         def on_stop(state, data):
#             if state == ProcessState.Stopped:
#                 try:
#                     on_state_change()
#                     if cont:
#                         debugger.exec_continue()
#                 except Exception as exc:
#                     test_exception.append(traceback.format_exc(exc))
#                     debugger.quit_program()
# 
#         debugger.on_process_state_changed.subscribe(on_stop)
# 
#     assert debugger.launch(startup_info)
# 
#     if wait:
#         debugger.wait_for_exit()
# 
#     if len(test_exception) > 0:
#         pytest.fail(test_exception[0], pytrace=False)


# Path: tests/test_mi_disassemble.py
from tests.conftest import setup_debugger

# -*- coding: utf-8 -*-

"""
This test is made towards a specific version of GDB and operating system
(i686), so it may not work elsewhere.
"""


TEST_FILE = "test_disassemble"
SRC_FILE = "src/{}.cpp".format(TEST_FILE)


def generate_instructions(instruction, reg32bit, reg64bit):
    return (instruction.format(reg32bit),
            instruction.format(reg64bit))


def test_address_invalid_file(debugger):
    def test_address_invalid_file_cb():
        assert debugger.file_manager.get_line_address("x.cpp", 0) is None


    setup_debugger(debugger, TEST_FILE, 3, test_address_invalid_file_cb)