def test_get_func_and_typedef_from_text_in_json_type(self):
        text = 'typedef int INT; int f();'
        functions, types, _, _, _ = get_types_info_from_text(
            'file', text, 'json')

        self.assertEqual(functions,
                         {'f': FuncInfo('int f();', 'f', 'file', 'int', [])})
        self.assertEqual(types, [Param('INT', 'int')])
    def test_get_one_func_and_struct_from_text(self):
        text = 'int f(int a); struct s{int b;};'
        functions, _, structs, _, _ = get_types_info_from_text(
            'file', text, 'txt')

        self.assertEqual(
            functions, {
                'f':
                FuncInfo('int f(int a);', 'f', 'file', 'int',
                         [Param('a', 'int')], False)
            })
        self.assertEqual(structs,
                         {'s': Struct('s', '', [Param('b', 'int')], 'file')})
    def test_unwanted_functions_are_removed(self):
        text = """
            // Wanted functions.
            INT StrCmpA(LPCSTR lpszStr, LPCSTR lpszComp);
            INT StrCmpW(LPCWSTR lpszStr, LPCWSTR lpszComp);

            // Unwanted functions (see is_wanted() for more details).
            INT StrCmp(LPCTSTR lpszStr, LPCTSTR lpszComp);
            Calling VirtualFreeEx without the MEM_RELEASE not address descriptors(VADs);
        """
        functions, _, _, _, _ = get_types_info_from_text('file', text, 'txt')

        self.assertEqual(functions.keys(), {'StrCmpA', 'StrCmpW'})
示例#4
0
def parse_header(header_file, path, output_handler, output_dir, output_format, indent):
    """Get types information from header file and writes output in chosen
    format to file to output directory.

    Path to header set to functions is relative path from script's input path.
    """
    logging.info('Reading file: {}'.format(header_file))
    content = read_text_file(header_file)
    if os.path.isfile(path):
        relative_path = os.path.basename(path)
    else:
        relative_path = os.path.relpath(header_file, path)

    functions, types, structs, unions, enums = get_types_info_from_text(
        relative_path, content, output_format)

    out_f = get_output_file(header_file, path, output_format, output_dir)
    with open(out_f, 'w') as output_file:
        output_handler(
            output_file, functions, types, structs, unions, enums, indent
        )
    def test_get_union_from_text_in_json_type(self):
        text = 'typedef union{}Tu;'
        _, _, _, unions, _ = get_types_info_from_text('file', text, 'json')

        self.assertEqual(unions, {'Tu': Union('', 'Tu', [], 'file')})
    def test_get_union_from_text(self):
        text = 'union s{int b;};'
        _, _, _, unions, _ = get_types_info_from_text('file', text, 'txt')

        self.assertEqual(unions,
                         {'s': Union('s', '', [Param('b', 'int')], 'file')})
    def test_convert_enum_to_type_for_json(self):
        text = 'enum e{a};'
        _, _, _, _, enums = get_types_info_from_text('file', text, 'json')

        self.assertEqual(enums, [Enum('e', '', [EnumItem('a', 0)], 'file')])
    def test_convert_struct_without_param_to_json_type(self):
        text = 'typedef struct {}tname;'
        _, _, structs, _, _ = get_types_info_from_text('file', text, 'json')

        self.assertEqual(structs, {'tname': Struct('', 'tname', [], 'file')})