# Path: symsynd/libdebug.py
# class DebugInfo(object):
# 
#     def __init__(self):
#         raise TypeError('Cannot instanciate debug infos')
# 
#     @staticmethod
#     def _from_ptr(ptr):
#         rv = object.__new__(DebugInfo)
#         rv._ptr = ptr
#         return rv
# 
#     @staticmethod
#     def open_path(path):
#         di = rustcall(_lib.debug_info_open_path, to_bytes(path))
#         return DebugInfo._from_ptr(di)
# 
#     def _get_ptr(self):
#         if self._ptr is None:
#             raise RuntimeError('Debug info closed')
#         return self._ptr
# 
#     def get_compilation_dir(self, cpu_name, path):
#         ptr = self._get_ptr()
# 
#         try:
#             rv = rustcall(_lib.debug_info_get_compilation_dir,
#                           ptr, to_bytes(cpu_name), to_bytes(path))
#             rv = _ffi.string(rv)
#             if isinstance(path, text_type):
#                 rv = rv.decode('utf-8')
#             return rv
#         except exceptions.DwarfLookupError:
#             pass
# 
#     def get_variants(self):
#         ptr = self._get_ptr()
#         count = _ffi.new('int *')
#         arr = rustcall(_lib.debug_info_get_variants, ptr, count)
#         return [Variant(arr[x]) for x in range(count[0])]
# 
#     def get_variant(self, uuid_or_cpu_name):
#         if isinstance(uuid_or_cpu_name, uuid.UUID):
#             id = uuid_or_cpu_name
#             cpu_name = None
#         else:
#             try:
#                 id = uuid.UUID(uuid_or_cpu_name)
#                 cpu_name = None
#             except ValueError:
#                 id = None
#                 cpu_name = uuid_or_cpu_name
#         for variant in self.get_variants():
#             if (id is not None and variant.uuid == id) or \
#                (cpu_name is not None and variant.cpu_name == cpu_name):
#                 return variant
# 
#     def close(self):
#         if self._ptr:
#             _lib.debug_info_free(self._ptr)
#         self._ptr = None
# 
#     def __del__(self):
#         try:
#             self.close()
#         except Exception:
#             pass
# 
# def get_cpu_name(type, subtype):
#     try:
#         return str_from_slice(rustcall(_lib.debug_get_cpu_name, type, subtype))
#     except exceptions.NoSuchArch:
#         pass
# 
# def get_cpu_type_tuple(name):
#     try:
#         struct = rustcall(_lib.debug_get_cpu_type, to_bytes(name))
#         return (struct.cputype, struct.cpusubtype)
#     except exceptions.NoSuchArch:
#         pass


import os
from uuid import UUID
from symsynd import DebugInfo, get_cpu_name, get_cpu_type_tuple


def test_cpu_names():
    assert get_cpu_name(12, 9) == 'armv7'
    tup = get_cpu_type_tuple('arm64')
    assert get_cpu_name(*tup) == 'arm64'


def test_uuid(res_path):
    ct_dsym_path = os.path.join(
        res_path, 'Crash-Tester.app.dSYM', 'Contents', 'Resources',
        'DWARF', 'Crash-Tester')
    di = DebugInfo.open_path(ct_dsym_path)
    uuids = [(s.cpu_name, str(s.uuid)) for s in di.get_variants()]
    assert uuids == [
        ('armv7', '8094558b-3641-36f7-ba80-a1aaabcf72da'),
        ('arm64', 'f502dec3-e605-36fd-9b3d-7080a7c6f4fc'),
    ]


def test_variants(res_path):
    ct_dsym_path = os.path.join(
        res_path, 'Crash-Tester.app.dSYM', 'Contents', 'Resources',
        'DWARF', 'Crash-Tester')

# Path: symsynd/libdebug.py
# class DebugInfo(object):
# 
#     def __init__(self):
#         raise TypeError('Cannot instanciate debug infos')
# 
#     @staticmethod
#     def _from_ptr(ptr):
#         rv = object.__new__(DebugInfo)
#         rv._ptr = ptr
#         return rv
# 
#     @staticmethod
#     def open_path(path):
#         di = rustcall(_lib.debug_info_open_path, to_bytes(path))
#         return DebugInfo._from_ptr(di)
# 
#     def _get_ptr(self):
#         if self._ptr is None:
#             raise RuntimeError('Debug info closed')
#         return self._ptr
# 
#     def get_compilation_dir(self, cpu_name, path):
#         ptr = self._get_ptr()
# 
#         try:
#             rv = rustcall(_lib.debug_info_get_compilation_dir,
#                           ptr, to_bytes(cpu_name), to_bytes(path))
#             rv = _ffi.string(rv)
#             if isinstance(path, text_type):
#                 rv = rv.decode('utf-8')
#             return rv
#         except exceptions.DwarfLookupError:
#             pass
# 
#     def get_variants(self):
#         ptr = self._get_ptr()
#         count = _ffi.new('int *')
#         arr = rustcall(_lib.debug_info_get_variants, ptr, count)
#         return [Variant(arr[x]) for x in range(count[0])]
# 
#     def get_variant(self, uuid_or_cpu_name):
#         if isinstance(uuid_or_cpu_name, uuid.UUID):
#             id = uuid_or_cpu_name
#             cpu_name = None
#         else:
#             try:
#                 id = uuid.UUID(uuid_or_cpu_name)
#                 cpu_name = None
#             except ValueError:
#                 id = None
#                 cpu_name = uuid_or_cpu_name
#         for variant in self.get_variants():
#             if (id is not None and variant.uuid == id) or \
#                (cpu_name is not None and variant.cpu_name == cpu_name):
#                 return variant
# 
#     def close(self):
#         if self._ptr:
#             _lib.debug_info_free(self._ptr)
#         self._ptr = None
# 
#     def __del__(self):
#         try:
#             self.close()
#         except Exception:
#             pass
# 
# def get_cpu_name(type, subtype):
#     try:
#         return str_from_slice(rustcall(_lib.debug_get_cpu_name, type, subtype))
#     except exceptions.NoSuchArch:
#         pass
# 
# def get_cpu_type_tuple(name):
#     try:
#         struct = rustcall(_lib.debug_get_cpu_type, to_bytes(name))
#         return (struct.cputype, struct.cpusubtype)
#     except exceptions.NoSuchArch:
#         pass


# Path: tests/test_debug.py
import os
from uuid import UUID
from symsynd import DebugInfo, get_cpu_name, get_cpu_type_tuple



def test_cpu_names():
    assert get_cpu_name(12, 9) == 'armv7'
    tup = get_cpu_type_tuple('arm64')
    assert get_cpu_name(*tup) == 'arm64'


def test_uuid(res_path):
    ct_dsym_path = os.path.join(
        res_path, 'Crash-Tester.app.dSYM', 'Contents', 'Resources',
        'DWARF', 'Crash-Tester')
    di = DebugInfo.open_path(ct_dsym_path)
    uuids = [(s.cpu_name, str(s.uuid)) for s in di.get_variants()]
    assert uuids == [
        ('armv7', '8094558b-3641-36f7-ba80-a1aaabcf72da'),
        ('arm64', 'f502dec3-e605-36fd-9b3d-7080a7c6f4fc'),
    ]


def test_variants(res_path):
    ct_dsym_path = os.path.join(
        res_path, 'Crash-Tester.app.dSYM', 'Contents', 'Resources',
        'DWARF', 'Crash-Tester')

    di = DebugInfo.open_path(ct_dsym_path)