def test_type_enum(self): type = uter.enum(("M_A", 1), ("M_B"), ("M_C")) sym = uter.export.symbol("g_noname_en_in_release_so", section = ".data") var = uter.export.dataobject(type, sym.address()) self.assertEqual(True, var._GetValue() == type.M_B, "") type = uter.enum(("M_1", 1), ("M_2"), ("M_3")) sym = uter.export.symbol("g_en_in_release_so", section = ".data") var = uter.export.dataobject(type, sym.address()) self.assertEqual(True, var._GetValue() == type.M_2, "")
def test_match(self): datatype_1 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) datatype_2 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -8)) datatype_3 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) self.assertEqual(True, datatype_1 != datatype_2, "") self.assertEqual(True, datatype_2 != datatype_1, "") self.assertEqual(True, datatype_2 != datatype_3, "") self.assertEqual(True, datatype_3 != datatype_2, "") self.assertEqual(True, datatype_1 == datatype_3, "") self.assertEqual(True, datatype_3 == datatype_1, "")
def test_atrr(self): datatype = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) print datatype self.assertEqual(True, datatype._GetSize() == 4, "") self.assertEqual(True, datatype._GetAlign() == 4, "") self.assertEqual(True, datatype._DefDesc() == "enum (no name) ", "")
def test_wrong(self): except_happen = False try: datatype = uter.enum(3) print datatype except uter.error.ArgError, e: except_happen = True print e
def test_def(self): deftype_1 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) deftype_2 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -8)) deftype_3 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -8)) dataen_1 = deftype_1(deftype_1.E2) dataen_2 = deftype_2(deftype_2.E2) dataen_3 = deftype_3(deftype_3.E2) self.assertEqual(True, deftype_1._MatchObj(dataen_1), "") self.assertEqual(True, deftype_2._MatchObj(dataen_2), "") self.assertEqual(True, not deftype_1._MatchObj(dataen_2), "") self.assertEqual(True, not deftype_2._MatchObj(dataen_1), "") self.assertEqual(True, not deftype_1._MatchObj(1), "") self.assertEqual(True, not deftype_2._MatchObj(1), "") self.assertEqual(True, deftype_2._MatchObj(dataen_3), "")
def test_def_type_new(self): datatype_1 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) dataobj_1 = datatype_1() print dataobj_1 dataobj_2 = datatype_1(datatype_1.E2) self.assertEqual(True, dataobj_1._GetValue() == 0, "") self.assertEqual(True, dataobj_2._GetValue() == datatype_1.E2, "")
def test_create(self): datatype = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) print datatype self.assertEqual(True, datatype.E1 == 4, "") self.assertEqual(True, datatype.E2 == 4, "") self.assertEqual(True, datatype.E3 == 5, "") self.assertEqual(True, datatype.E4 == 6, "") self.assertEqual(True, datatype.E5 == -5, "") datatype = uter.enum(("E1", 4), ("E2", 4), "E3", "E4", ("E5", -5)) print datatype self.assertEqual(True, datatype.E1 == 4, "") self.assertEqual(True, datatype.E2 == 4, "") self.assertEqual(True, datatype.E3 == 5, "") self.assertEqual(True, datatype.E4 == 6, "") self.assertEqual(True, datatype.E5 == -5, "") datatype = uter.enum(("E1", 4), ("E2", 4), ("E3"), ("E4"), ("E5", -5)) print datatype self.assertEqual(True, datatype.E1 == 4, "") self.assertEqual(True, datatype.E2 == 4, "") self.assertEqual(True, datatype.E3 == 5, "") self.assertEqual(True, datatype.E4 == 6, "") self.assertEqual(True, datatype.E5 == -5, "") datatype = uter.enum(["E1", 4], ["E2", 4], ["E3"], ["E4"], ["E5", -5]) print datatype self.assertEqual(True, datatype.E1 == 4, "") self.assertEqual(True, datatype.E2 == 4, "") self.assertEqual(True, datatype.E3 == 5, "") self.assertEqual(True, datatype.E4 == 6, "") self.assertEqual(True, datatype.E5 == -5, "") datatype = uter.enum(["E1", 4], ["E2", 4], [ "E3", ], [ "E4", ], ["E5", -5]) print datatype self.assertEqual(True, datatype.E1 == 4, "") self.assertEqual(True, datatype.E2 == 4, "") self.assertEqual(True, datatype.E3 == 5, "") self.assertEqual(True, datatype.E4 == 6, "") self.assertEqual(True, datatype.E5 == -5, "")
def test_new_args(self): datatype_1 = uter.enum(("E1", 4), ("E2", 4), ("E3", ), ("E4", ), ("E5", -5)) dataobj_1 = datatype_1() dataobj_2 = datatype_1(datatype_1.E2) dataobj_3 = datatype_1(dataobj_2) self.assertEqual(True, dataobj_1._GetValue() == 0, "") self.assertEqual(True, dataobj_2._GetValue() == 4, "") self.assertEqual(True, dataobj_3._GetValue() == 4, "")
def test_all(self): self.assertEqual(True, type(uter.char) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.uchar) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.short) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.ushort) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.int) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.uint) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.long) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.ulong) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.longlong) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.ulonglong) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.float) is uter._UterMetaClass, "") self.assertEqual(True, type(uter.double) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(uter.char, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.uchar, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.short, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.ushort, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.int, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.uint, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.long, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.ulong, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.longlong, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.ulonglong, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.float, uter._UterMetaClass), "") self.assertEqual(True, isinstance(uter.double, uter._UterMetaClass), "") datatype = uter.struct((uter.char, "a"), (uter.char, "b")) self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "") datatype = uter.union((uter.char, "a"), (uter.char, "b")) self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "") datatype = uter.enum(("a", 1), ("b", 3)) self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "") datatype = uter.point(uter.int) self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "") datatype = uter.array(uter.int, 8) self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "") datatype = uter.typedef(uter.int, "xxx") self.assertEqual(True, type(datatype) is uter._UterMetaClass, "") self.assertEqual(True, isinstance(datatype, uter._UterMetaClass), "")
class test_case_def(unittest.TestCase): def test_wrong(self): except_happen = False try: datatype = uter.enum(3) print datatype except uter.error.ArgError, e: except_happen = True print e self.assertEqual(True, except_happen, "") except_happen = False try: datatype = uter.enum(("E1", 4), ("E1", 4), ("E3", ), ("E4", ), ("E5", -5)) print datatype except uter.error.ArgError, e: except_happen = True print e