Merged PR 4695: Integration and Hierarchy

Added support for struct hierarchy. Now each struct has a list of the structs it depends on.
Changed 'obj_type_list' to 'struct_list'.
Changed 'struct_name' and 'function_name' to 'name' on the SimpleSchema.
Created a deserialization IntegrationTest to make sure that the output from CppToJson matches the SimpleSchema.
Removed function AddVar, and instead now the variables are set on the constructor.
This commit is contained in:
Teo Magnino Chaban 2019-07-12 19:55:07 +00:00
Родитель ec092c4d35
Коммит a9649457e8
7 изменённых файлов: 388 добавлений и 127 удалений

Просмотреть файл

@ -1,6 +1,6 @@
<FileInfo *>:
<function_list *>:
<func_name string>
<name string>
<raw_return_type string>
<simple_return_type string>
@ -13,7 +13,7 @@
<definition_line int min=1 ?>
<struct_list *>:
<struct_name string>
<name string>
<var_names string *>
<raw_var_types string *>
@ -21,6 +21,8 @@
<definition_line int min=1 ?>
<base_structs string *>
<constructor_list *>:
<var_names string *>
<raw_var_types string *>

Просмотреть файл

@ -257,7 +257,7 @@ def ObtainFunctions(
# ----------------------------------------------------------------------
filename = input_filename
filename = os.path.realpath(input_filename)
these_results = ParseFile(filename)
# If the original file was a temp file, make the key None rather than
@ -302,12 +302,16 @@ def ObtainFunctions(
if GetObjType(arg_type) != obj_type and not VerifyObjType(GetObjType(arg_type)) and not TestAndVerify(arg_type):
invalid_reasons.append("\t- Invalid type {} on constructor argument.".format(arg_type))
for parent_struct in obj_type.base_structs:
if not VerifyObjType(GetObjType(parent_struct)):
invalid_reasons.append("\t- Invalid base struct {}".format(parent_struct))
if not obj_type.has_move_constructor:
invalid_reasons.append("\t- Struct doesn't have a move constructor.")
if obj_type.has_copy_constructor:
invalid_reasons.append("\t- Struct has a copy constructor.")
if obj_type.has_private:
invalid_reasons.append("\t- Struct has private variables.")
invalid_reasons.append("\t- Struct has a private variable or inherits from a private struct.")
if obj_type.has_other:
invalid_reasons.append("\t- Struct has an unsupported definition.")
@ -401,10 +405,6 @@ class _FuncWithArguments(object):
def __eq__(self, other):
return self.__hash__() == other.__hash__()
# ----------------------------------------------------------------------
def AddVar(self, var_name, raw_var_type, simple_var_type):
self.VariableInfo.append((var_name, raw_var_type, simple_var_type))
# ----------------------------------------------------------------------
def ToDict(self):
new_dict = {}
@ -439,7 +439,8 @@ class ClassLikeObject(_FuncWithArguments):
name,
definition_line,
filename,
variable_info=None,
variable_info,
base_structs=None,
constructor_list=None,
has_move_constructor=None,
has_copy_constructor=None,
@ -455,6 +456,7 @@ class ClassLikeObject(_FuncWithArguments):
self.Filename = filename
self.constructor_list = constructor_list or []
self.base_structs = base_structs or []
self.has_move_constructor = has_move_constructor or False
self.has_copy_constructor = has_copy_constructor or False
@ -476,6 +478,7 @@ class ClassLikeObject(_FuncWithArguments):
results[k] = v
results["constructor_list"] = [constructor.ToDict() for constructor in self.constructor_list]
results["base_structs"] = self.base_structs
return results
@ -549,16 +552,16 @@ class Constructor(_FuncWithArguments):
def __init__(
self,
definition_line,
variable_info=None,
variable_info,
):
self._definition_line = definition_line
self.DefinitionLine = definition_line
super(Constructor, self).__init__(
variable_info=variable_info,
)
# ----------------------------------------------------------------------
def __hash__(self):
return hash((self._definition_line, super(Constructor, self).__hash__()))
return hash((self.DefinitionLine, super(Constructor, self).__hash__()))
# ----------------------------------------------------------------------
def ToDict(self):
@ -568,7 +571,7 @@ class Constructor(_FuncWithArguments):
if len(new_dict["var_names"]) == 1 and not new_dict["var_names"][0]:
new_dict["var_names"] = ["other"]
new_dict["definition_line"] = self._definition_line
new_dict["definition_line"] = self.DefinitionLine
return new_dict
@ -592,7 +595,7 @@ class Results(object):
new_dict = {}
new_dict["function_list"] = self.function_list
new_dict["object_type_list"] = self.object_type_list
new_dict["struct_list"] = self.object_type_list
new_dict["include_list"] = self.include_list
return new_dict
@ -621,10 +624,14 @@ def _GetObjectType(node, SimpleVarType, FullVarType):
This function will return the Object Type that this node refers to. It will return None if there were
errors.
"""
object_type = ClassLikeObject(_FullName(node), node.location.line, os.path.realpath(node.location.file.name))
# The way to see if this is a definition or not, is to see if 'node' has any children.
struct_class_pattern = re.compile(
textwrap.dedent(
r"""(?#
Not a letter)(?<!\w)(?#
Keyword with a space)(?P<keyword>struct\s|class\s)(?#
)"""
)
)
is_def = True
# There are a few kinds that are supported, even though they are not directly exposed.
accepted_kinds = [cindex.CursorKind.CXX_ACCESS_SPEC_DECL]
@ -642,17 +649,28 @@ def _GetObjectType(node, SimpleVarType, FullVarType):
# ----------------------------------------------------------------------
object_vars = []
for child in node.get_children():
if child.kind == cindex.CursorKind.FIELD_DECL:
var_type = FullVarType(child.type.spelling)
object_vars.append((child.spelling, var_type, SimpleVarType(var_type)))
object_type = ClassLikeObject(_FullName(node), node.location.line, os.path.realpath(node.location.file.name), object_vars)
for child in node.get_children():
# The way to see if this is a definition or not, is to see if 'node' has any children.
is_def = False
if child.kind == cindex.CursorKind.CONSTRUCTOR:
# If this constructor ends in "=delete", ignore it.
if DeleteDefault(child, "delete"):
continue
constructor = Constructor(child.location.line)
constructor_args = []
for arg in child.get_arguments():
arg_type = FullVarType(arg.type.spelling)
constructor.AddVar(arg.spelling, arg_type, SimpleVarType(arg_type))
constructor_args.append((arg.spelling, arg_type, SimpleVarType(arg_type)))
constructor = Constructor(child.location.line, constructor_args)
object_type.constructor_list.append(constructor)
@ -668,8 +686,6 @@ def _GetObjectType(node, SimpleVarType, FullVarType):
object_type.has_copy_constructor = True
elif child.kind == cindex.CursorKind.FIELD_DECL:
var_type = FullVarType(child.type.spelling)
object_type.AddVar(child.spelling, var_type, SimpleVarType(var_type))
if child.access_specifier != cindex.AccessSpecifier.PUBLIC:
object_type.has_private = True
@ -690,10 +706,13 @@ def _GetObjectType(node, SimpleVarType, FullVarType):
object_type.has_other = True
elif child.kind == cindex.CursorKind.CXX_BASE_SPECIFIER:
# TODO: This means that this classLikeObject depends on another one
# there is the need to verify if the one that this one depends on is valid.
# Check that this is public.
pass
if child.access_specifier != cindex.AccessSpecifier.PUBLIC:
object_type.has_private = True
struct_name = child.spelling
struct_name = struct_class_pattern.sub(r'', struct_name)
object_type.base_structs.append(struct_name.strip())
elif child.kind not in accepted_kinds:
object_type.has_other = True

Просмотреть файл

@ -5,7 +5,7 @@
# | future invocations of the generator!
# |
# | Generated by: <SimpleSchemaGenerator>/Plugins/Impl/PythonSerializationImpl.py
# | Generated on: 2019-07-02 14:47:04.572330
# | Generated on: 2019-07-11 09:56:55.630862
# |
# --------------------------------------------------------------------------------
import copy
@ -150,16 +150,16 @@ def Deserialize_FileInfo(
# | Type Infos
# |
# ----------------------------------------------------------------------
FileInfo_TypeInfo = ClassTypeInfo(OrderedDict([ ( "function_list", ClassTypeInfo(OrderedDict([ ( "func_name", StringTypeInfo(min_length=1) ), ( "raw_return_type", StringTypeInfo(min_length=1) ), ( "simple_return_type", StringTypeInfo(min_length=1) ), ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "declaration_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ), ( "struct_list", ClassTypeInfo(OrderedDict([ ( "struct_name", StringTypeInfo(min_length=1) ), ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ), ( "constructor_list", ClassTypeInfo(OrderedDict([ ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ), ( "include_list", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ) ]), require_exact_match=True, arity=Arity.FromString('*'))
FileInfo_TypeInfo = ClassTypeInfo(OrderedDict([ ( "function_list", ClassTypeInfo(OrderedDict([ ( "name", StringTypeInfo(min_length=1) ), ( "raw_return_type", StringTypeInfo(min_length=1) ), ( "simple_return_type", StringTypeInfo(min_length=1) ), ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "declaration_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ), ( "struct_list", ClassTypeInfo(OrderedDict([ ( "name", StringTypeInfo(min_length=1) ), ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ), ( "base_structs", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "constructor_list", ClassTypeInfo(OrderedDict([ ( "var_names", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "raw_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "simple_var_types", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ), ( "definition_line", IntTypeInfo(min=1, arity=Arity.FromString('?')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ) ]), require_exact_match=True, arity=Arity.FromString('*')) ), ( "include_list", StringTypeInfo(min_length=1, arity=Arity.FromString('*')) ) ]), require_exact_match=True, arity=Arity.FromString('*'))
_FileInfo_TypeInfo_Contents = OrderedDict([("function_list", GenericTypeInfo(arity=Arity.FromString('*'))), ("struct_list", GenericTypeInfo(arity=Arity.FromString('*'))), ("include_list", GenericTypeInfo(arity=Arity.FromString('*')))])
_FileInfo_function_list_TypeInfo_Contents = OrderedDict([("func_name", GenericTypeInfo()), ("raw_return_type", GenericTypeInfo()), ("simple_return_type", GenericTypeInfo()), ("var_names", GenericTypeInfo(arity=Arity.FromString('*'))), ("raw_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("simple_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("declaration_line", GenericTypeInfo(arity=Arity.FromString('?'))), ("definition_line", GenericTypeInfo(arity=Arity.FromString('?')))])
_FileInfo_struct_list_TypeInfo_Contents = OrderedDict([("struct_name", GenericTypeInfo()), ("var_names", GenericTypeInfo(arity=Arity.FromString('*'))), ("raw_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("simple_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("definition_line", GenericTypeInfo(arity=Arity.FromString('?'))), ("constructor_list", GenericTypeInfo(arity=Arity.FromString('*')))])
_FileInfo_function_list_TypeInfo_Contents = OrderedDict([("name", GenericTypeInfo()), ("raw_return_type", GenericTypeInfo()), ("simple_return_type", GenericTypeInfo()), ("var_names", GenericTypeInfo(arity=Arity.FromString('*'))), ("raw_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("simple_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("declaration_line", GenericTypeInfo(arity=Arity.FromString('?'))), ("definition_line", GenericTypeInfo(arity=Arity.FromString('?')))])
_FileInfo_struct_list_TypeInfo_Contents = OrderedDict([("name", GenericTypeInfo()), ("var_names", GenericTypeInfo(arity=Arity.FromString('*'))), ("raw_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("simple_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("definition_line", GenericTypeInfo(arity=Arity.FromString('?'))), ("base_structs", GenericTypeInfo(arity=Arity.FromString('*'))), ("constructor_list", GenericTypeInfo(arity=Arity.FromString('*')))])
_FileInfo_struct_list_constructor_list_TypeInfo_Contents = OrderedDict([("var_names", GenericTypeInfo(arity=Arity.FromString('*'))), ("raw_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("simple_var_types", GenericTypeInfo(arity=Arity.FromString('*'))), ("definition_line", GenericTypeInfo(arity=Arity.FromString('?')))])
_FileInfo_TypeInfo = AnyOfTypeInfo([ClassTypeInfo(_FileInfo_TypeInfo_Contents, require_exact_match=False), DictTypeInfo(_FileInfo_TypeInfo_Contents, require_exact_match=False)], arity=Arity.FromString('*'))
_FileInfo_function_list_TypeInfo = AnyOfTypeInfo([ClassTypeInfo(_FileInfo_function_list_TypeInfo_Contents, require_exact_match=False), DictTypeInfo(_FileInfo_function_list_TypeInfo_Contents, require_exact_match=False)], arity=Arity.FromString('*'))
_FileInfo_function_list_func_name_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_function_list_name_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_function_list_raw_return_type_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_function_list_simple_return_type_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_function_list_var_names_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
@ -168,11 +168,12 @@ _FileInfo_function_list_simple_var_types_TypeInfo = St
_FileInfo_function_list_declaration_line_TypeInfo = IntTypeInfo(min=1, arity=Arity.FromString('?'))
_FileInfo_function_list_definition_line_TypeInfo = IntTypeInfo(min=1, arity=Arity.FromString('?'))
_FileInfo_struct_list_TypeInfo = AnyOfTypeInfo([ClassTypeInfo(_FileInfo_struct_list_TypeInfo_Contents, require_exact_match=False), DictTypeInfo(_FileInfo_struct_list_TypeInfo_Contents, require_exact_match=False)], arity=Arity.FromString('*'))
_FileInfo_struct_list_struct_name_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_struct_list_name_TypeInfo = StringTypeInfo(min_length=1)
_FileInfo_struct_list_var_names_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
_FileInfo_struct_list_raw_var_types_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
_FileInfo_struct_list_simple_var_types_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
_FileInfo_struct_list_definition_line_TypeInfo = IntTypeInfo(min=1, arity=Arity.FromString('?'))
_FileInfo_struct_list_base_structs_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
_FileInfo_struct_list_constructor_list_TypeInfo = AnyOfTypeInfo([ClassTypeInfo(_FileInfo_struct_list_constructor_list_TypeInfo_Contents, require_exact_match=False), DictTypeInfo(_FileInfo_struct_list_constructor_list_TypeInfo_Contents, require_exact_match=False)], arity=Arity.FromString('*'))
_FileInfo_struct_list_constructor_list_var_names_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
_FileInfo_struct_list_constructor_list_raw_var_types_TypeInfo = StringTypeInfo(min_length=1, arity=Arity.FromString('*'))
@ -227,14 +228,14 @@ class Deserializer(object):
# ----------------------------------------------------------------------
@classmethod
def FileInfo_function_list_func_name(cls, item):
def FileInfo_function_list_name(cls, item):
if item in [DoesNotExist, None]:
_FileInfo_function_list_func_name_TypeInfo.ValidateArity(None)
_FileInfo_function_list_name_TypeInfo.ValidateArity(None)
return DoesNotExist
result = cls._FileInfo_function_list_func_name_Item(item)
result = cls._FileInfo_function_list_name_Item(item)
_FileInfo_function_list_func_name_TypeInfo.ValidateArity(result)
_FileInfo_function_list_name_TypeInfo.ValidateArity(result)
return result
@ -368,14 +369,14 @@ class Deserializer(object):
# ----------------------------------------------------------------------
@classmethod
def FileInfo_struct_list_struct_name(cls, item):
def FileInfo_struct_list_name(cls, item):
if item in [DoesNotExist, None]:
_FileInfo_struct_list_struct_name_TypeInfo.ValidateArity(None)
_FileInfo_struct_list_name_TypeInfo.ValidateArity(None)
return DoesNotExist
result = cls._FileInfo_struct_list_struct_name_Item(item)
result = cls._FileInfo_struct_list_name_Item(item)
_FileInfo_struct_list_struct_name_TypeInfo.ValidateArity(result)
_FileInfo_struct_list_name_TypeInfo.ValidateArity(result)
return result
@ -449,6 +450,25 @@ class Deserializer(object):
return result
# ----------------------------------------------------------------------
@classmethod
def FileInfo_struct_list_base_structs(cls, items):
if items in [DoesNotExist, None, []]:
_FileInfo_struct_list_base_structs_TypeInfo.ValidateArity(None)
return DoesNotExist
results = []
for this_index, this_item in enumerate(items or []):
try:
results.append(cls._FileInfo_struct_list_base_structs_Item(this_item))
except:
_DecorateActiveException("Index {}".format(this_index))
_FileInfo_struct_list_base_structs_TypeInfo.ValidateArity(results)
return results
# ----------------------------------------------------------------------
@classmethod
def FileInfo_struct_list_constructor_list(cls, items, always_include_optional, process_additional_data):
@ -607,18 +627,18 @@ class Deserializer(object):
attributes=None,
)
# func_name
# name
try:
setattr(result, "func_name", cls.FileInfo_function_list_func_name(
setattr(result, "name", cls.FileInfo_function_list_name(
cls._GetPythonAttribute(
item,
"func_name",
"name",
is_optional=False,
),
)
)
except:
_DecorateActiveException("func_name")
_DecorateActiveException("name")
# raw_return_type
try:
@ -681,7 +701,7 @@ class Deserializer(object):
cls._ApplyAdditionalData(
item,
result,
exclude_names={"func_name", "raw_return_type", "simple_return_type", "var_names", "raw_var_types", "simple_var_types", "declaration_line", "definition_line"},
exclude_names={"name", "raw_return_type", "simple_return_type", "var_names", "raw_var_types", "simple_var_types", "declaration_line", "definition_line"},
)
_FileInfo_function_list_TypeInfo.ValidateItem(
@ -694,8 +714,8 @@ class Deserializer(object):
# ----------------------------------------------------------------------
@classmethod
def _FileInfo_function_list_func_name_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_function_list_func_name_TypeInfo, item, **{})
def _FileInfo_function_list_name_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_function_list_name_TypeInfo, item, **{})
# ----------------------------------------------------------------------
@classmethod
@ -739,18 +759,18 @@ class Deserializer(object):
attributes=None,
)
# struct_name
# name
try:
setattr(result, "struct_name", cls.FileInfo_struct_list_struct_name(
setattr(result, "name", cls.FileInfo_struct_list_name(
cls._GetPythonAttribute(
item,
"struct_name",
"name",
is_optional=False,
),
)
)
except:
_DecorateActiveException("struct_name")
_DecorateActiveException("name")
# var_names
try:
@ -776,6 +796,12 @@ class Deserializer(object):
except:
_DecorateActiveException("definition_line")
# base_structs
try:
cls._ApplyOptionalChildren(item, "base_structs", result, cls.FileInfo_struct_list_base_structs, always_include_optional)
except:
_DecorateActiveException("base_structs")
# constructor_list
try:
cls._ApplyOptionalChildren(item, "constructor_list", result, lambda value: cls.FileInfo_struct_list_constructor_list(value, always_include_optional, process_additional_data), always_include_optional)
@ -787,7 +813,7 @@ class Deserializer(object):
cls._ApplyAdditionalData(
item,
result,
exclude_names={"struct_name", "var_names", "raw_var_types", "simple_var_types", "definition_line", "constructor_list"},
exclude_names={"name", "var_names", "raw_var_types", "simple_var_types", "definition_line", "base_structs", "constructor_list"},
)
_FileInfo_struct_list_TypeInfo.ValidateItem(
@ -800,8 +826,8 @@ class Deserializer(object):
# ----------------------------------------------------------------------
@classmethod
def _FileInfo_struct_list_struct_name_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_struct_list_struct_name_TypeInfo, item, **{})
def _FileInfo_struct_list_name_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_struct_list_name_TypeInfo, item, **{})
# ----------------------------------------------------------------------
@classmethod
@ -823,6 +849,11 @@ class Deserializer(object):
def _FileInfo_struct_list_definition_line_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_struct_list_definition_line_TypeInfo, item, **{})
# ----------------------------------------------------------------------
@classmethod
def _FileInfo_struct_list_base_structs_Item(cls, item):
return JsonSerialization.DeserializeItem(_FileInfo_struct_list_base_structs_TypeInfo, item, **{})
# ----------------------------------------------------------------------
@classmethod
def _FileInfo_struct_list_constructor_list_Item(cls, item, always_include_optional, process_additional_data):

Просмотреть файл

@ -29,7 +29,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
}
@ -39,7 +39,7 @@ class TestSuite(unittest.TestCase):
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].function_list[0].func_name, "Name")
self.assertEqual(result[0].function_list[0].name, "Name")
self.assertEqual(result[0].function_list[0].raw_return_type, "int1")
self.assertEqual(result[0].function_list[0].simple_return_type, "int2")
self.assertTrue(not hasattr(result[0].function_list[0], "var_names"))
@ -58,7 +58,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["a", "b",],
@ -73,7 +73,7 @@ class TestSuite(unittest.TestCase):
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].function_list[0].func_name, "Name")
self.assertEqual(result[0].function_list[0].name, "Name")
self.assertEqual(result[0].function_list[0].raw_return_type, "int1")
self.assertEqual(result[0].function_list[0].simple_return_type, "int2")
self.assertEqual(result[0].function_list[0].var_names, ["a", "b",])
@ -92,13 +92,13 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name1",
"name": "Name1",
"raw_return_type": "int1",
"simple_return_type": "int2",
"definition_line": 12,
},
{
"func_name": "Name2",
"name": "Name2",
"raw_return_type": "int3",
"simple_return_type": "int4",
"definition_line": 34,
@ -110,7 +110,7 @@ class TestSuite(unittest.TestCase):
self.assertEqual(len(result[0].function_list), 2)
self.assertEqual(result[0].function_list[0].func_name, "Name1")
self.assertEqual(result[0].function_list[0].name, "Name1")
self.assertEqual(result[0].function_list[0].raw_return_type, "int1")
self.assertEqual(result[0].function_list[0].simple_return_type, "int2")
self.assertEqual(result[0].function_list[0].definition_line, 12)
@ -119,7 +119,7 @@ class TestSuite(unittest.TestCase):
self.assertTrue(not hasattr(result[0].function_list[0], "simple_var_types"))
self.assertTrue(not hasattr(result[0].function_list[0], "declaration_line"))
self.assertEqual(result[0].function_list[1].func_name, "Name2")
self.assertEqual(result[0].function_list[1].name, "Name2")
self.assertEqual(result[0].function_list[1].raw_return_type, "int3")
self.assertEqual(result[0].function_list[1].simple_return_type, "int4")
self.assertEqual(result[0].function_list[1].definition_line, 34)
@ -138,7 +138,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "Name",
"name": "Name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -150,7 +150,7 @@ class TestSuite(unittest.TestCase):
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].struct_list[0].struct_name, "Name")
self.assertEqual(result[0].struct_list[0].name, "Name")
self.assertEqual(result[0].struct_list[0].var_names, ["a", "b",])
self.assertEqual(result[0].struct_list[0].raw_var_types, ["c", "d",])
self.assertEqual(result[0].struct_list[0].simple_var_types, ["e", "f",])
@ -167,7 +167,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "Name",
"name": "Name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -187,7 +187,7 @@ class TestSuite(unittest.TestCase):
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].struct_list[0].struct_name, "Name")
self.assertEqual(result[0].struct_list[0].name, "Name")
self.assertEqual(result[0].struct_list[0].var_names, ["a", "b",])
self.assertEqual(result[0].struct_list[0].raw_var_types, ["c", "d",])
self.assertEqual(result[0].struct_list[0].simple_var_types, ["e", "f",])
@ -201,14 +201,14 @@ class TestSuite(unittest.TestCase):
self.assertTrue(not hasattr(result[0], "function_list"))
self.assertTrue(not hasattr(result[0], "include_list"))
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
def test_WithMultipleConstructors(self):
result = Deserialize(
[
{
"struct_list": [
{
"struct_name": "Name",
"name": "Name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -234,7 +234,7 @@ class TestSuite(unittest.TestCase):
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].struct_list[0].struct_name, "Name")
self.assertEqual(result[0].struct_list[0].name, "Name")
self.assertEqual(result[0].struct_list[0].var_names, ["a", "b",])
self.assertEqual(result[0].struct_list[0].raw_var_types, ["c", "d",])
self.assertEqual(result[0].struct_list[0].simple_var_types, ["e", "f",])
@ -253,6 +253,67 @@ class TestSuite(unittest.TestCase):
self.assertTrue(not hasattr(result[0], "function_list"))
self.assertTrue(not hasattr(result[0], "include_list"))
# ----------------------------------------------------------------------
def test_WithBaseStruct(self):
result = Deserialize(
[
{
"struct_list": [
{
"name": "Name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
"definition_line": 7,
"base_structs": ["struct1"],
}
]
},
],
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].struct_list[0].name, "Name")
self.assertEqual(result[0].struct_list[0].var_names, ["a", "b",])
self.assertEqual(result[0].struct_list[0].raw_var_types, ["c", "d",])
self.assertEqual(result[0].struct_list[0].simple_var_types, ["e", "f",])
self.assertEqual(result[0].struct_list[0].definition_line, 7)
self.assertTrue(not hasattr(result[0].struct_list[0], "constructor_list"))
self.assertEqual(result[0].struct_list[0].base_structs, ["struct1"])
self.assertTrue(not hasattr(result[0], "function_list"))
self.assertTrue(not hasattr(result[0], "include_list"))
# ----------------------------------------------------------------------
def test_WithMultipleBaseStruct(self):
result = Deserialize(
[
{
"struct_list": [
{
"name": "Name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
"definition_line": 7,
"base_structs": ["struct1", "struct2", "struct3"],
}
]
},
],
)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].struct_list[0].name, "Name")
self.assertEqual(result[0].struct_list[0].var_names, ["a", "b",])
self.assertEqual(result[0].struct_list[0].raw_var_types, ["c", "d",])
self.assertEqual(result[0].struct_list[0].simple_var_types, ["e", "f",])
self.assertEqual(result[0].struct_list[0].definition_line, 7)
self.assertTrue(not hasattr(result[0].struct_list[0], "constructor_list"))
self.assertEqual(result[0].struct_list[0].base_structs, ["struct1", "struct2", "struct3"])
self.assertTrue(not hasattr(result[0], "function_list"))
self.assertTrue(not hasattr(result[0], "include_list"))
# ----------------------------------------------------------------------
def test_include(self):
@ -269,8 +330,8 @@ class TestSuite(unittest.TestCase):
self.assertTrue(not hasattr(result[0], "function_list"))
self.assertTrue(not hasattr(result[0], "struct_list"))
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
def test_multiple_includes(self):
result = Deserialize(
[
@ -287,8 +348,6 @@ class TestSuite(unittest.TestCase):
self.assertTrue(not hasattr(result[0], "struct_list"))
# ----------------------------------------------------------------------
def test_InvalidName(self):
self.assertRaisesRegex(
Exception,
@ -298,7 +357,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": None,
"name": None,
"raw_return_type": "int1",
"simple_return_type": "int2",
},
@ -316,7 +375,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "",
"name": "",
"raw_return_type": "int1",
"simple_return_type": "int2",
},
@ -336,7 +395,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": None,
"simple_return_type": "int2",
},
@ -354,7 +413,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "",
"simple_return_type": "int2",
},
@ -374,7 +433,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": None,
},
@ -392,7 +451,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "",
},
@ -412,7 +471,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": [None, "b",],
@ -433,7 +492,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["", "b",],
@ -456,7 +515,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["a", "b",],
@ -477,7 +536,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["a", "b",],
@ -500,7 +559,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["a", "b",],
@ -521,7 +580,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"var_names": ["", "b",],
@ -533,6 +592,7 @@ class TestSuite(unittest.TestCase):
],
)
)
# ----------------------------------------------------------------------
def test_InvalidDeclarationLine(self):
self.assertRaisesRegex(
@ -543,7 +603,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int1",
"declaration_line": 0,
@ -561,7 +621,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int1",
"declaration_line": "String",
@ -571,6 +631,7 @@ class TestSuite(unittest.TestCase):
],
)
)
# ----------------------------------------------------------------------
def test_InvalidDefinitionLine(self):
self.assertRaisesRegex(
@ -581,7 +642,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int1",
"definition_line": 0,
@ -599,7 +660,7 @@ class TestSuite(unittest.TestCase):
{
"function_list": [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int1",
"definition_line": "String",
@ -611,7 +672,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidNameStruct(self):
self.assertRaisesRegex(
Exception,
@ -621,7 +681,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": None,
"name": None,
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -641,7 +701,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "",
"name": "",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -654,7 +714,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidVarNameStruct(self):
self.assertRaisesRegex(
Exception,
@ -664,7 +723,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": [None, "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -684,7 +743,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -697,7 +756,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidRawVarTypeStruct(self):
self.assertRaisesRegex(
Exception,
@ -707,7 +765,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": [None, "d",],
"simple_var_types": ["e", "f",],
@ -727,7 +785,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["", "d",],
"simple_var_types": ["e", "f",],
@ -740,8 +798,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidSimpleVarTypeStruct(self):
self.assertRaisesRegex(
Exception,
@ -751,7 +807,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": [None, "f",],
@ -771,7 +827,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["", "f",],
@ -784,7 +840,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidDefinitionLineStruct(self):
self.assertRaisesRegex(
Exception,
@ -794,7 +849,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -814,7 +869,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -827,7 +882,50 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidBaseStructs(self):
self.assertRaisesRegex(
Exception,
"expected string or bytes-like object",
lambda: Deserialize(
[
{
"struct_list": [
{
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
"definition_line": 7,
"base_structs": [None, "struct2"],
}
]
},
],
)
)
self.assertRaisesRegex(
Exception,
"'' is not a valid 'String' string - Value must have at least 1 character",
lambda: Deserialize(
[
{
"struct_list": [
{
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
"definition_line": 7,
"base_structs": ["", "struct2"],
}
]
},
],
)
)
# ----------------------------------------------------------------------
def test_InvalidArgNamesConstructor(self):
self.assertRaisesRegex(
Exception,
@ -837,7 +935,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -865,7 +963,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -886,7 +984,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidRawArgTypesConstructor(self):
self.assertRaisesRegex(
Exception,
@ -896,7 +993,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -924,7 +1021,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -945,7 +1042,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidSimpleArgTypesConstructor(self):
self.assertRaisesRegex(
Exception,
@ -955,7 +1051,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -983,7 +1079,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -1004,7 +1100,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidDefinitionLineConstructor(self):
self.assertRaisesRegex(
Exception,
@ -1014,7 +1109,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -1042,7 +1137,7 @@ class TestSuite(unittest.TestCase):
{
"struct_list": [
{
"struct_name": "name",
"name": "name",
"var_names": ["a", "b",],
"raw_var_types": ["c", "d",],
"simple_var_types": ["e", "f",],
@ -1063,7 +1158,6 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_InvalidIncludeList(self):
self.assertRaisesRegex(
Exception,
@ -1090,12 +1184,10 @@ class TestSuite(unittest.TestCase):
)
# ----------------------------------------------------------------------
def test_ProcessAdditionalData(self):
input = [
{
"func_name": "Name",
"name": "Name",
"raw_return_type": "int1",
"simple_return_type": "int2",
"another_value": {"hello": "world",},

Просмотреть файл

@ -9,6 +9,7 @@ import textwrap
import CommonEnvironment
from DataPipelines import CppToJson
from DataPipelines.GeneratedCode.CppToJson_PythonJsonSerialization import *
# ----------------------------------------------------------------------
@ -184,7 +185,7 @@ class FileTest(unittest.TestCase):
self.assertEqual(func_list[0], {'name': 'go', 'raw_return_type': 'x *', 'simple_return_type': 'x', 'var_names': ['y'], 'raw_var_types': ['int'], 'simple_var_types': ['int'], 'declaration_line': 12, 'definition_line': 12})
self.assertEqual(func_list[1], {'name': 'main', 'raw_return_type': 'int', 'simple_return_type': 'int', 'var_names': [], 'raw_var_types': [], 'simple_var_types': [], 'declaration_line': 17, 'definition_line': 17})
self.assertEqual(obj_type_list[0], {'name': 'x', 'var_names': ['a', 'b'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 3, 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['x &&'], 'simple_var_types': ['x'], 'definition_line': 5}, {'var_names': ['xa', 'xb'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 6}]})
self.assertEqual(obj_type_list[0], {'name': 'x', 'var_names': ['a', 'b'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 3, 'base_structs': [], 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['x &&'], 'simple_var_types': ['x'], 'definition_line': 5}, {'var_names': ['xa', 'xb'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 6}]})
self.assertEqual(len(include_list), 2)
@ -208,21 +209,21 @@ class FileTest(unittest.TestCase):
self.assertEqual(filename, list(all_results.keys())[0])
self.assertEqual(all_results[filename]["function_list"][0], {'name': 'gox', 'raw_return_type': 'go *', 'simple_return_type': 'go', 'var_names': ['y'], 'raw_var_types': ['int'], 'simple_var_types': ['int'], 'declaration_line': 4, 'definition_line': 4})
self.assertEqual(all_results[filename]["function_list"][1], {'name': 'main', 'raw_return_type': 'int', 'simple_return_type': 'int', 'var_names': [], 'raw_var_types': [], 'simple_var_types': [], 'declaration_line': 9, 'definition_line': 9})
self.assertEqual(all_results[filename]["object_type_list"], [])
self.assertEqual(all_results[filename]["struct_list"], [])
self.assertEqual(len(all_results[filename]["include_list"]), 1)
header2 = os.path.realpath(os.path.join(_script_dir, "header2.hpp"))
self.assertEqual(header2, list(all_results.keys())[1])
self.assertEqual(all_results[header2]["function_list"], [])
self.assertEqual(len(all_results[header2]["object_type_list"]), 1)
self.assertEqual(all_results[header2]["object_type_list"][0], {'name': 'go2', 'var_names': ['a', 'b'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 5, 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['go2 &&'], 'simple_var_types': ['go2'], 'definition_line': 7}]})
self.assertEqual(len(all_results[header2]["struct_list"]), 1)
self.assertEqual(all_results[header2]["struct_list"][0], {'name': 'go2', 'var_names': ['a', 'b'], 'raw_var_types': ['int', 'int'], 'simple_var_types': ['int', 'int'], 'definition_line': 5, 'base_structs': [], 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['go2 &&'], 'simple_var_types': ['go2'], 'definition_line': 7}]})
self.assertEqual(len(all_results[header2]["include_list"]), 1)
header1 = os.path.realpath(os.path.join(_script_dir, "header1.hpp"))
self.assertEqual(header1, list(all_results.keys())[2])
self.assertEqual(all_results[header1]["function_list"], [])
self.assertEqual(len(all_results[header2]["object_type_list"]), 1)
self.assertEqual(all_results[header1]["object_type_list"][0], {'name': 'go', 'var_names': ['a', 'b', 'x'], 'raw_var_types': ['int', 'int', 'go2'], 'simple_var_types': ['int', 'int', 'go2'], 'definition_line': 5, 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['go &&'], 'simple_var_types': ['go'], 'definition_line': 8}]})
self.assertEqual(len(all_results[header2]["struct_list"]), 1)
self.assertEqual(all_results[header1]["struct_list"][0], {'name': 'go', 'var_names': ['a', 'b', 'x'], 'raw_var_types': ['int', 'int', 'go2'], 'simple_var_types': ['int', 'int', 'go2'], 'definition_line': 5, 'base_structs': [], 'constructor_list': [{'var_names': ['other'], 'raw_var_types': ['go &&'], 'simple_var_types': ['go'], 'definition_line': 8}]})
self.assertEqual(len(all_results[header1]["include_list"]), 1)
def _GetFuncList(self, filename, results):
@ -235,7 +236,7 @@ class FileTest(unittest.TestCase):
self.assertEqual(len(results), 1)
self.assertEqual(filename, list(results.keys())[0])
return results[filename]['object_type_list']
return results[filename]['struct_list']
def _GetIncludeList(self, filename, results):
self.assertEqual(len(results), 1)
@ -243,5 +244,87 @@ class FileTest(unittest.TestCase):
return results[filename]['include_list']
class Deserialization(unittest.TestCase):
"""
This test will make sure that the output from my function matches the SimpleSchema format.
"""
def test_deserialization(self):
filename = os.path.join(_script_dir, "deserialization.cpp")
results = CppToJson.ObtainFunctions(filename, None, lambda type: True)
deserialized_result = Deserialize([results[filename]])
self.assertEqual(len(deserialized_result), 1)
self.assertEqual(deserialized_result[0].function_list[0].name, "goooo")
self.assertEqual(deserialized_result[0].function_list[0].raw_return_type, "oth")
self.assertEqual(deserialized_result[0].function_list[0].simple_return_type, "oth")
self.assertEqual(deserialized_result[0].function_list[0].var_names, ["a", "b"])
self.assertEqual(deserialized_result[0].function_list[0].raw_var_types, ["int", "float"])
self.assertEqual(deserialized_result[0].function_list[0].simple_var_types, ["int", "float"])
self.assertEqual(deserialized_result[0].function_list[0].declaration_line, 30)
self.assertEqual(deserialized_result[0].function_list[0].definition_line, 30)
self.assertEqual(deserialized_result[0].struct_list[0].name, "go")
self.assertEqual(deserialized_result[0].struct_list[0].var_names, ["a", "b"])
self.assertEqual(deserialized_result[0].struct_list[0].raw_var_types, ["int", "bool"])
self.assertEqual(deserialized_result[0].struct_list[0].simple_var_types, ["int", "bool"])
self.assertEqual(deserialized_result[0].struct_list[0].definition_line, 3)
"""
TODO: The following commented code is here because there is a problem on Deserialize, that
it does not export fields that only have an empty list. Once that is fixed, the
code should be uncommented.
"""
# self.assertEqual(deserialized_result[0].struct_list[0].base_structs, [])
self.assertEqual(len(deserialized_result[0].struct_list[0].constructor_list), 2)
# self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[0].var_names, [])
# self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[0].raw_var_types, [])
# self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[0].simple_var_types, [])
self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[0].definition_line, 6)
self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[1].var_names, ["other"])
self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[1].raw_var_types, ["go &&"])
self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[1].simple_var_types, ["go"])
self.assertEqual(deserialized_result[0].struct_list[0].constructor_list[1].definition_line, 9)
self.assertEqual(deserialized_result[0].struct_list[1].name, "go2")
self.assertEqual(deserialized_result[0].struct_list[1].var_names, ["a", "b"])
self.assertEqual(deserialized_result[0].struct_list[1].raw_var_types, ["int", "float"])
self.assertEqual(deserialized_result[0].struct_list[1].simple_var_types, ["int", "float"])
self.assertEqual(deserialized_result[0].struct_list[1].definition_line, 12)
# self.assertEqual(deserialized_result[0].struct_list[1].base_structs, [])
self.assertEqual(len(deserialized_result[0].struct_list[1].constructor_list), 2)
# self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[0].var_names, [])
# self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[0].raw_var_types, [])
# self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[0].simple_var_types, [])
self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[0].definition_line, 15)
self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[1].var_names, ["other"])
self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[1].raw_var_types, ["go2 &&"])
self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[1].simple_var_types, ["go2"])
self.assertEqual(deserialized_result[0].struct_list[1].constructor_list[1].definition_line, 18)
self.assertEqual(deserialized_result[0].struct_list[2].name, "oth")
self.assertEqual(deserialized_result[0].struct_list[2].var_names, ["x"])
self.assertEqual(deserialized_result[0].struct_list[2].raw_var_types, ["int"])
self.assertEqual(deserialized_result[0].struct_list[2].simple_var_types, ["int"])
self.assertEqual(deserialized_result[0].struct_list[2].definition_line, 21)
self.assertEqual(deserialized_result[0].struct_list[2].base_structs, ["go", "go2"])
self.assertEqual(len(deserialized_result[0].struct_list[2].constructor_list), 2)
# self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[0].var_names, [])
# self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[0].raw_var_types, [])
# self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[0].simple_var_types, [])
self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[0].definition_line, 23)
self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[1].var_names, ["other"])
self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[1].raw_var_types, ["oth &&"])
self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[1].simple_var_types, ["oth"])
self.assertEqual(deserialized_result[0].struct_list[2].constructor_list[1].definition_line, 26)
if __name__ == '__main__':
unittest.main()

Просмотреть файл

@ -0,0 +1,34 @@
#include <utility>
struct go{
int a;
bool b;
go(){
}
go(struct go &&other): a(std::move(other.a)), b(std::move(other.b)){}
};
struct go2{
int a;
float b;
go2(){
}
go2(struct go2 &&other): a(std::move(other.a)), b(std::move(other.b)){}
};
struct oth: public go, go2{
int x;
oth(){
go();
}
oth(struct oth &&other)=default;
};
oth goooo(int a, float b){
oth x;
x.x = 3;
return x;
}

Просмотреть файл

@ -839,7 +839,7 @@ class FuncTest(unittest.TestCase):
self.assertEqual(len(results), 1)
self.assertEqual(None, list(results.keys())[0])
return results[None]['object_type_list']
return results[None]['struct_list']
def _GetIncludeList(self, results):
self.assertEqual(len(results), 1)