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_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_uint(self): data_obj = uter.uint() data_obj._SetValue(1) self.assertEqual(True, data_obj._GetValue() == 1, "") data_obj._SetValue(0) self.assertEqual(True, data_obj._GetValue() == 0, "") data_obj._SetValue((2 ** 32) - 1) self.assertEqual(True, data_obj._GetValue() == (2 ** 32) - 1, "") data_obj._SetValue(-1) self.assertEqual(True, data_obj._GetValue() == (2 ** 32) - 1, "") data_obj._SetValue(2 ** 32) self.assertEqual(True, data_obj._GetValue() == 0, "")
def test_def_type_new_mem_obj(self): datatype = uter.union((uter.uint, "a"), (uter.uchar, "b")) arg = uter.uint(4) data_a = datatype("a", (arg, )) arg = uter.uchar(4) data_b = datatype("b", (arg, )) print data_a print data_b self.assertEqual(True, data_a.a._GetValue() == 4, "") self.assertEqual(True, data_a.b._GetValue() == 4, "") self.assertEqual(True, data_b.a._GetValue() == 4, "") self.assertEqual(True, data_b.b._GetValue() == 4, "")
def test_astype(self): uintdata = uter.uint(0x12345678) print uintdata dt = uter.struct((uter.uchar, "a"), (uter.uchar, "b"), (uter.uchar, "c"), (uter.uchar, "d")) print dt stdata = uintdata._AsType(dt) print stdata self.assertEqual(True, stdata.a._GetValue() == 0x78, "") self.assertEqual(True, stdata.b._GetValue() == 0x56, "") self.assertEqual(True, stdata.c._GetValue() == 0x34, "") self.assertEqual(True, stdata.d._GetValue() == 0x12, "")
def test_uint_right(self): data_obj = uter.uint() 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(0) data_obj._RightShift(1) self.assertEqual(True, data_obj._GetValue() == 0, "")
def test_uint_left(self): data_obj = uter.uint() 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 << 32) - 1) data_obj._LeftShift(1) self.assertEqual(True, data_obj._GetValue() == ((((1 << 32) - 1) << 1) & ((1 << 32) - 1)), "")
def test_export_type_new_mem_obj(self): datatype_1 = uter.export.union("un_base_1") datatype_2 = uter.export.union("un_base_2") arg = uter.uint(9) dataobj_1 = datatype_1("m_1", (arg, )) dataobj_21 = datatype_2("m_1", (arg, )) arg = uter.uchar(9) dataobj_22 = datatype_2("m_2", (arg, )) print dataobj_1 print dataobj_21 print dataobj_22 self.assertEqual(True, dataobj_1.m_1._GetValue() == 9, "") self.assertEqual(True, dataobj_21.m_1._GetValue() == 9, "") self.assertEqual(True, dataobj_21.m_2._GetValue() == 9, "") self.assertEqual(True, dataobj_22.m_1._GetValue() == 9, "") self.assertEqual(True, dataobj_22.m_2._GetValue() == 9, "")
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, "")
def test_new(self): datatype = uter.export.union("someinun_1_out_1") data11 = datatype("m_1", (2, 3)) print data11 self.assertEqual(True, data11.m_1.m_1._GetValue() == 2, "") self.assertEqual(True, data11.m_1.m_2._GetValue() == 3, "") data12 = datatype("m_1", (uter.uchar(2), uter.uint(3))) print data12 self.assertEqual(True, data12.m_1.m_1._GetValue() == 2, "") self.assertEqual(True, data12.m_1.m_2._GetValue() == 3, "") data20 = datatype("m_2", ("m_1", (10, ))) print data20 self.assertEqual(True, data20.m_2.m_1._GetValue() == 10, "") data30 = datatype("m_3", (1, 2, 3, 4, 5, 6, 7, 8)) print data30 self.assertEqual(True, data30.m_3.m_1._GetValue() == 1, "") self.assertEqual(True, data30.m_3.m_2._GetValue() == 2, "") self.assertEqual(True, data30.m_3.m_3._GetValue() == 3, "") self.assertEqual(True, data30.m_3.m_4._GetValue() == 4, "") self.assertEqual(True, data30.m_3.m_5._GetValue() == 5, "") self.assertEqual(True, data30.m_3.m_6._GetValue() == 6, "") self.assertEqual(True, data30.m_3.m_7._GetValue() == 7, "") self.assertEqual(True, data30.m_3.m_8._GetValue() == 8, "")