def test_parse_ptr_to_function_no_params_to_type_for_json(self): types = {} fptr = 'void * (*)()' fptr_type = parse_type_to_type_for_json(fptr, types) types[fptr_type.type_hash] = fptr_type ret = PrimitiveType('void') ret_type = PointerType(ret) func_type = FunctionType(ret_type, []) ptr = PointerType(func_type) expected = { ret_type.type_hash: ret_type, ret.type_hash: ret, func_type.type_hash: func_type, ptr.type_hash: ptr } self.assertEqual(types, expected)
def test_union_with_func_ptr_to_type_for_json(self): types = {} union = 'union s{int *(* ptr)();};' s_info = parse_union(union, 'file') parse_union_to_type_for_json(s_info, types) tint = PrimitiveType('int') ptrint = PointerType(tint) func = FunctionType(ptrint, []) func_ptr = PointerType(func) st = UnionType('s', [func_ptr]) expected = { tint.type_hash: tint, ptrint.type_hash: ptrint, func.type_hash: func, func_ptr.type_hash: func_ptr, st.type_hash: st } self.assertEqual(types, expected)
def test_parse_ptr_to_function_with_ptr_to_func_as_param(self): types = {} fptr = 'void (*)(void (*)())' fptr_type = parse_type_to_type_for_json(fptr, types) types[fptr_type.type_hash] = fptr_type ret_type = PrimitiveType('void') param = FunctionType(ret_type, []) param_ptr = PointerType(param) func_type = FunctionType(ret_type, [Param('', param_ptr.type_hash)]) ptr = PointerType(func_type) expected = { ret_type.type_hash: ret_type, param.type_hash: param, param_ptr.type_hash: param_ptr, func_type.type_hash: func_type, ptr.type_hash: ptr } self.assertEqual(types, expected)
def test_parse_typedef_ptr_to_union_to_type_for_json(self): types = {} union = 'typedef union xy {} *ptr_s;' s_info = parse_union(union, 'file') parse_union_to_type_for_json(s_info, types) st = UnionType('xy', []) ptr = PointerType(st) typedef = TypedefedType('ptr_s', ptr) expected = { st.type_hash: st, ptr.type_hash: ptr, typedef.type_hash: typedef } self.assertEqual(types, expected)
def test_parse_typedef_ptr_to_struct_to_type_for_json(self): types = {} struct = 'typedef struct xy {} *ptr_s;' s_info = parse_struct(struct, 'file') parse_struct_to_type_for_json(s_info, types) st = StructType('xy', []) ptr = PointerType(st) typedef = TypedefedType('ptr_s', ptr) expected = { st.type_hash: st, ptr.type_hash: ptr, typedef.type_hash: typedef } self.assertEqual(types, expected)
def test_parse_typedefed_ptr_to_enum_to_type_for_json(self): types = {} enum = 'typedef enum x{One = 1, Two = 3} my_type, *ptr;' enum_info = parse_enum(enum, 'file') parse_enum_to_type_for_json(enum_info, types) e = EnumType('x', [EnumItem('One', 1), EnumItem('Two', 3)]) typ = TypedefedType('my_type', e) ptr = PointerType(e) tptr = TypedefedType('ptr', ptr) expected = { e.type_hash: e, typ.type_hash: typ, tptr.type_hash: tptr, ptr.type_hash: ptr } self.assertEqual(types, expected)
def test_parse_ptr_to_function_with_call_conv_to_type_for_json(self): types = {} fptr = 'void (__cdecl*)(int p1)' fptr_type = parse_type_to_type_for_json(fptr, types) types[fptr_type.type_hash] = fptr_type ret_type = VoidType() p1 = PrimitiveType('int') func_type = FunctionType(ret_type, [Param('p1', p1.type_hash)], False, 'cdecl') ptr = PointerType(func_type) expected = { ret_type.type_hash: ret_type, p1.type_hash: p1, func_type.type_hash: func_type, ptr.type_hash: ptr } self.assertEqual(types, expected)
def test_parse_ptr_to_vararg_function_to_type_for_json(self): types = {} fptr = 'void (*)(int p1, ...)' fptr_type = parse_type_to_type_for_json(fptr, types) types[fptr_type.type_hash] = fptr_type ret_type = PrimitiveType('void') p1 = PrimitiveType('int') func_type = FunctionType(ret_type, [Param('p1', p1.type_hash)], True) ptr = PointerType(func_type) expected = { ret_type.type_hash: ret_type, p1.type_hash: p1, func_type.type_hash: func_type, ptr.type_hash: ptr } self.assertEqual(types, expected)
def test_pointer_type_correct_string_repr(self): prim = PrimitiveType('int') self.assertEqual( PointerType(prim).__repr__(), "PointerType('{}')".format(prim.type_hash))
def test_ptr_ptr_char_is_pointer_type_to_pointer_type_to_primitive_type( self): self.assertEqual(parse_type_to_type_for_json('char **', {}), PointerType(PointerType(PrimitiveType('char'))))
def test_parse_ptr_to_const_struct_inversion(self): self.assertEqual( parse_type_to_type_for_json('struct info const *', {}), PointerType(QualifierType('const', StructType('info'))))
def test_ptr_to_const_ptr_to_void_is_(self): self.assertEqual( parse_type_to_type_for_json('void * const *', {}), PointerType( QualifierType('const', PointerType(PrimitiveType('void')))))
def test_more_modifiers_in_one_type_parsed_correctly(self): self.assertEqual( parse_type_to_type_for_json('volatile char * const', {}), QualifierType( 'const', PointerType(QualifierType('volatile', PrimitiveType('char')))))
def test_char_const_ptr_is_pointer_type_to_const_type_of_primitive_type( self): self.assertEqual( parse_type_to_type_for_json('char const *', {}), PointerType(QualifierType('const', PrimitiveType('char'))))
def test_parse_ptr_to_common_typedef_correctly(self): self.assertEqual(parse_type_to_type_for_json('BOOL * MYAPI', {}), PointerType(TypedefedType('BOOL')))
def test_function_type_correct_string_repr(self): ptr = PointerType(PrimitiveType('int')) self.assertEqual( FunctionType(ptr).__repr__(), "FunctionType('{}', [])".format(ptr.type_hash))
def test_parse_ptr_to_primitive_type_with_some_trash(self): self.assertEqual(parse_type_to_type_for_json('int ** MACRO', {}), PointerType(PointerType(PrimitiveType('int'))))