def test_cast_to_parent_nested(self): """ Testing for a cast with 1 level of recursion """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) double_val = mtypes.MyriadScalar("val", mtypes.MDouble) myriad_class = mtypes.MyriadStructType("MyriadClass", OrderedDict({0: void_ptr})) class_m = myriad_class("_", quals=["const"]) toplevel_struct = mtypes.MyriadStructType( "toplevel", OrderedDict({ 0: class_m, 1: double_val })) self.assertEqual("(struct MyriadClass*)", mtypes.cast_to_parent(toplevel_struct, "self"))
def test_struct_nesting(self): """ Testing basic struct nesting """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) double_val = mtypes.MyriadScalar("val", mtypes.MDouble) myriad_class = mtypes.MyriadStructType("MyriadClass", OrderedDict({0: void_ptr})) class_m = myriad_class("class_m", quals=["const"]) toplevel_struct = mtypes.MyriadStructType( "toplevel", OrderedDict({ 0: class_m, 1: double_val })) expected_result = \ "struct toplevel { const struct MyriadClass class_m; double val; }" str_result = toplevel_struct.stringify_decl().replace('\n', ' ') self.assertEqual(trim_spaces(expected_result), trim_spaces(str_result))
def test_struct_qual(self): """ Testing making a struct having a qualifier """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) myriad_class = mtypes.MyriadStructType("MyriadClass", OrderedDict({0: void_ptr})) class_m = myriad_class("class_m", quals=["const"]) self.assertEqual("const struct MyriadClass class_m", class_m.stringify_decl())
def test_struct_ptr(self): """ Testing having a struct pointer variable """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) myriad_class = mtypes.MyriadStructType("MyriadClass", OrderedDict({0: void_ptr})) class_2 = myriad_class("class_2", ptr=True) self.assertEqual(trim_spaces("struct MyriadClass *class_2"), trim_spaces(class_2.stringify_decl()))
def test_single_member_struct(self): """ Testing having a struct with single member """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) myriad_class = mtypes.MyriadStructType("MyriadClass", OrderedDict({0: void_ptr})) str1 = myriad_class.stringify_decl().replace('\n', ' ') str2 = "struct MyriadClass { const void *self; }" self.assertEqual(trim_spaces(str1), trim_spaces(str2))
def test_cast_to_parent(self): """ Testing for a simple cast where the field is in the struct """ void_ptr = mtypes.MyriadScalar("self", mtypes.MVoid, True, quals=["const"]) double_val = mtypes.MyriadScalar("val", mtypes.MDouble) myriad_class = mtypes.MyriadStructType( "MyriadClass", OrderedDict({ 0: void_ptr, 1: double_val })) self.assertEqual("(struct MyriadClass*)", mtypes.cast_to_parent(myriad_class, "val"))