def test_value_obj(self): data = uter.char(5) data_char = uter.char(data) data = uter.uchar(5) data_uchar = uter.uchar(data) data = uter.short(5) data_short = uter.short(data) data = uter.ushort(5) data_ushort = uter.ushort(data) data = uter.int(5) data_int = uter.int(data) data = uter.uint(5) data_uint = uter.uint(data) data = uter.long(5) data_long = uter.long(data) data = uter.ulong(5) data_ulong = uter.ulong(data) data = uter.longlong(5) data_longlong = uter.longlong(data) data = uter.ulonglong(5) data_ulonglong = uter.ulonglong(data) self.assertEqual(True, data_char._GetValue() == 5, "") self.assertEqual(True, data_uchar._GetValue() == 5, "") self.assertEqual(True, data_short._GetValue() == 5, "") self.assertEqual(True, data_ushort._GetValue() == 5, "") self.assertEqual(True, data_int._GetValue() == 5, "") self.assertEqual(True, data_uint._GetValue() == 5, "") self.assertEqual(True, data_long._GetValue() == 5, "") self.assertEqual(True, data_ulong._GetValue() == 5, "") self.assertEqual(True, data_longlong._GetValue() == 5, "") self.assertEqual(True, data_ulonglong._GetValue() == 5, "")
def test_new_02(self): datatype = uter.export.struct("stinst_1_out_1") data1 = uter.char(1) data2 = uter.int(2) data3 = uter.int(3) data4 = uter.char(4) data5 = uter.int(5) data = datatype((data1, data2), (data3, data4), data5) print data self.assertEqual(True, data.m_1.m_1._GetValue() == 1, "") self.assertEqual(True, data.m_1.m_2._GetValue() == 2, "") self.assertEqual(True, data.m_2.m_1._GetValue() == 3, "") self.assertEqual(True, data.m_2.m_2._GetValue() == 4, "") self.assertEqual(True, data.m_3._GetValue() == 5, "")
def test_error_init_2(self): exception_happend = False z = uter.char(10) try: data = uter.int(z) except uter.error.ArgError, e: exception_happend = True
def test_setnum(self): data_char = uter.char() data_uchar = uter.uchar() data_short = uter.short() data_ushort = uter.ushort() data_int = uter.int() data_uint = uter.uint() data_long = uter.long() data_ulong = uter.ulong() data_longlong = uter.longlong() data_ulonglong = uter.ulonglong() data_char._SetValue(5) data_uchar._SetValue(5) data_short._SetValue(5) data_ushort._SetValue(5) data_int._SetValue(5) data_uint._SetValue(5) data_long._SetValue(5) data_ulong._SetValue(5) data_longlong._SetValue(5) data_ulonglong._SetValue(5) self.assertEqual(True, data_char._GetValue() == 5, "") self.assertEqual(True, data_uchar._GetValue() == 5, "") self.assertEqual(True, data_short._GetValue() == 5, "") self.assertEqual(True, data_ushort._GetValue() == 5, "") self.assertEqual(True, data_int._GetValue() == 5, "") self.assertEqual(True, data_uint._GetValue() == 5, "") self.assertEqual(True, data_long._GetValue() == 5, "") self.assertEqual(True, data_ulong._GetValue() == 5, "") self.assertEqual(True, data_longlong._GetValue() == 5, "") self.assertEqual(True, data_ulonglong._GetValue() == 5, "")
def test_new_def_type_obj_val(self): datatype_1 = uter.struct((uter.char, "a"), (uter.int, "b")) dataobj_1 = datatype_1(uter.char(8), uter.int(9)) print dataobj_1 self.assertEqual(True, dataobj_1.a._GetValue() == 8, "") self.assertEqual(True, dataobj_1.b._GetValue() == 9, "") datatype_2 = uter.struct((uter.char, "a"), (uter.short, "b"), (uter.int, "c")) dataobj_2 = datatype_2(uter.char(10), uter.short(11), uter.int(12)) print dataobj_2 self.assertEqual(True, dataobj_2.a._GetValue() == 10, "") self.assertEqual(True, dataobj_2.b._GetValue() == 11, "") self.assertEqual(True, dataobj_2.c._GetValue() == 12, "") datatype_3 = uter.struct((uter.char, "a"), (uter.char, "b")) dataobj_3 = datatype_3(uter.char(13), uter.char(14)) print dataobj_3 self.assertEqual(True, dataobj_3.a._GetValue() == 13, "") self.assertEqual(True, dataobj_3.b._GetValue() == 14, "") datatype_4 = uter.struct((uter.int, "a"), (uter.char, "b"), (uter.char, "c"), (uter.char, "d")) dataobj_4 = datatype_4(uter.int(15), uter.char(16), uter.char(17), uter.char(18)) print dataobj_4 self.assertEqual(True, dataobj_4.a._GetValue() == 15, "") self.assertEqual(True, dataobj_4.b._GetValue() == 16, "") self.assertEqual(True, dataobj_4.c._GetValue() == 17, "") self.assertEqual(True, dataobj_4.d._GetValue() == 18, "")
def test_char(self): data_obj = uter.char() data_obj._SetValue(1) self.assertEqual(True, data_obj._GetValue() == 1, "") data_obj._SetValue(-128) self.assertEqual(True, data_obj._GetValue() == -128, "") data_obj._SetValue(127) self.assertEqual(True, data_obj._GetValue() == 127, "") data_obj._SetValue(-129) self.assertEqual(True, data_obj._GetValue() == 127, "") data_obj._SetValue(128) self.assertEqual(True, data_obj._GetValue() == -128, "")
def test_char_right(self): data_obj = uter.char() data_obj._SetValue(2) data_obj._RightShift(1) self.assertEqual(True, data_obj._GetValue() == 1, "") data_obj._SetValue(4) data_obj._RightShift(2) self.assertEqual(True, data_obj._GetValue() == 1, "") data_obj._SetValue(-(1 << 7)) data_obj._RightShift(1) self.assertEqual(True, data_obj._GetValue() % (1 << 8) == (((-(1 << 7)) % (1 << 8)) >> 1), "")
def test_char_left(self): data_obj = uter.char() data_obj._SetValue(1) data_obj._LeftShift(1) self.assertEqual(True, data_obj._GetValue() == 2, "") data_obj._SetValue(1) data_obj._LeftShift(2) self.assertEqual(True, data_obj._GetValue() == 4, "") data_obj._SetValue((1 << 7) - 1) data_obj._LeftShift(1) self.assertEqual(True, data_obj._GetValue() % (1 << 8) == (((1 << 7) - 1) << 1) & ((1 << 8) - 1), "")
def test_new_export_type_obj_val(self): datatype_1 = uter.export.struct("st_base_1") dataobj_1 = datatype_1(uter.int(8)) print dataobj_1 self.assertEqual(True, dataobj_1.m_1._GetValue() == 8, "") datatype_2 = uter.export.struct("st_base_2") dataobj_2 = datatype_2(uter.int(9), uter.int(10)) print dataobj_2 self.assertEqual(True, dataobj_2.m_1._GetValue() == 9, "") self.assertEqual(True, dataobj_2.m_2._GetValue() == 10, "") datatype_3 = uter.export.struct("st_base_3") dataobj_3 = datatype_3(uter.char(11), uter.char(12)) print dataobj_3 self.assertEqual(True, dataobj_3.m_1._GetValue() == 11, "") self.assertEqual(True, dataobj_3.m_2._GetValue() == 12, "") datatype_4 = uter.export.struct("st_base_4") dataobj_4 = datatype_4(uter.char(13), uter.int(14)) print dataobj_4 self.assertEqual(True, dataobj_4.m_1._GetValue() == 13, "") self.assertEqual(True, dataobj_4.m_2._GetValue() == 14, "")
def test_match(self): data_char = uter.char() data_uchar = uter.uchar() data_short = uter.short() data_ushort = uter.ushort() data_int = uter.int() data_uint = uter.uint() data_long = uter.long() data_ulong = uter.ulong() data_longlong = uter.longlong() data_ulonglong = uter.ulonglong() self.assertEqual(True, uter.char._MatchObj(data_char), "") self.assertEqual(True, uter.uchar._MatchObj(data_uchar), "") self.assertEqual(True, uter.short._MatchObj(data_short), "") self.assertEqual(True, uter.ushort._MatchObj(data_ushort), "") self.assertEqual(True, uter.int._MatchObj(data_int), "") self.assertEqual(True, uter.uint._MatchObj(data_uint), "") self.assertEqual(True, uter.long._MatchObj(data_long), "") self.assertEqual(True, uter.ulong._MatchObj(data_ulong), "") self.assertEqual(True, uter.longlong._MatchObj(data_longlong), "") self.assertEqual(True, uter.ulonglong._MatchObj(data_ulonglong), "") self.assertEqual(True, not uter.char._MatchObj(data_uchar), "") self.assertEqual(True, not uter.uchar._MatchObj(data_char), "") self.assertEqual(True, not uter.short._MatchObj(data_ushort), "") self.assertEqual(True, not uter.ushort._MatchObj(data_short), "") self.assertEqual(True, not uter.int._MatchObj(data_uint), "") self.assertEqual(True, not uter.uint._MatchObj(data_int), "") self.assertEqual(True, not uter.long._MatchObj(data_ulong), "") self.assertEqual(True, not uter.ulong._MatchObj(data_long), "") self.assertEqual(True, not uter.longlong._MatchObj(data_ulonglong), "") self.assertEqual(True, not uter.ulonglong._MatchObj(data_longlong), "") self.assertEqual(True, not uter.char._MatchObj(1), "") self.assertEqual(True, not uter.uchar._MatchObj(1), "") self.assertEqual(True, not uter.short._MatchObj(1), "") self.assertEqual(True, not uter.ushort._MatchObj(1), "") self.assertEqual(True, not uter.int._MatchObj(1), "") self.assertEqual(True, not uter.uint._MatchObj(1), "") self.assertEqual(True, not uter.long._MatchObj(1), "") self.assertEqual(True, not uter.ulong._MatchObj(1), "") self.assertEqual(True, not uter.longlong._MatchObj(1), "") self.assertEqual(True, not uter.ulonglong._MatchObj(1), "")
def test_gettype(self): data_char = uter.char() data_uchar = uter.uchar() data_short = uter.short() data_ushort = uter.ushort() data_int = uter.int() data_uint = uter.uint() data_long = uter.long() data_ulong = uter.ulong() data_longlong = uter.longlong() data_ulonglong = uter.ulonglong() self.assertEqual(True, data_char._GetType() == uter.char, "") self.assertEqual(True, data_uchar._GetType() == uter.uchar, "") self.assertEqual(True, data_short._GetType() == uter.short, "") self.assertEqual(True, data_ushort._GetType() == uter.ushort, "") self.assertEqual(True, data_int._GetType() == uter.int, "") self.assertEqual(True, data_uint._GetType() == uter.uint, "") self.assertEqual(True, data_long._GetType() == uter.long, "") self.assertEqual(True, data_ulong._GetType() == uter.ulong, "") self.assertEqual(True, data_longlong._GetType() == uter.longlong, "") self.assertEqual(True, data_ulonglong._GetType() == uter.ulonglong, "")
def test_getaddress(self): data_char = uter.char() data_uchar = uter.uchar() data_short = uter.short() data_ushort = uter.ushort() data_int = uter.int() data_uint = uter.uint() data_long = uter.long() data_ulong = uter.ulong() data_longlong = uter.longlong() data_ulonglong = uter.ulonglong() self.assertEqual(True, data_char._GetAddress() != 0, "") self.assertEqual(True, data_uchar._GetAddress() != 0, "") self.assertEqual(True, data_short._GetAddress() != 0, "") self.assertEqual(True, data_ushort._GetAddress() != 0, "") self.assertEqual(True, data_int._GetAddress() != 0, "") self.assertEqual(True, data_uint._GetAddress() != 0, "") self.assertEqual(True, data_long._GetAddress() != 0, "") self.assertEqual(True, data_ulong._GetAddress() != 0, "") self.assertEqual(True, data_longlong._GetAddress() != 0, "") self.assertEqual(True, data_ulonglong._GetAddress() != 0, "")
def test_value_default(self): data_char = uter.char() data_uchar = uter.uchar() data_short = uter.short() data_ushort = uter.ushort() data_int = uter.int() data_uint = uter.uint() data_long = uter.long() data_ulong = uter.ulong() data_longlong = uter.longlong() data_ulonglong = uter.ulonglong() self.assertEqual(True, data_char._GetValue() == 0, "") self.assertEqual(True, data_uchar._GetValue() == 0, "") self.assertEqual(True, data_short._GetValue() == 0, "") self.assertEqual(True, data_ushort._GetValue() == 0, "") self.assertEqual(True, data_int._GetValue() == 0, "") self.assertEqual(True, data_uint._GetValue() == 0, "") self.assertEqual(True, data_long._GetValue() == 0, "") self.assertEqual(True, data_ulong._GetValue() == 0, "") self.assertEqual(True, data_longlong._GetValue() == 0, "") self.assertEqual(True, data_ulonglong._GetValue() == 0, "")
def test_print(self): data = uter.char() print data data = uter.uchar() print data data = uter.short() print data data = uter.ushort() print data data = uter.int() print data data = uter.uint() print data data = uter.long() print data data = uter.ulong() print data data = uter.longlong() print data data = uter.ulonglong() print data self.assertEqual(True, True, "")
self.assertEqual(True, except_happen, "") except_happen = False try: datatype = uter.export.struct("st_base_1") data = datatype("") val = data.m_1._GetValue() except uter.error.ArgError, e: except_happen = True print e self.assertEqual(True, except_happen, "") except_happen = False try: datatype = uter.export.struct("st_base_1") arg = uter.char(9) data = datatype(arg) val = data.m_1._GetValue() except uter.error.ArgError, e: except_happen = True print e self.assertEqual(True, except_happen, "") def test_new_def_type_def_val(self): datatype_1 = uter.struct((uter.char, "a"), (uter.int, "b")) dataobj_1 = datatype_1() print dataobj_1 self.assertEqual(True, dataobj_1.a._GetValue() == 0, "") datatype_2 = uter.struct((uter.char, "a"), (uter.short, "b"), (uter.int, "c"))