def test_bit_field_conversions(self): ibl = [] cv = ConvertValue() for i in range(0,32): ib = rand.randrange(0, 2) cv.convert_bits(ib) ibl.append(ib) cr = ConvertBitField(_buffer(cv.collapsed_buffer())) for i in range(0,32): j = cr.status(i) if ibl[i] != j: raise 'BIT conversion failed'
def test_bit_field_conversions(self): ibl = [] cv = ConvertValue() for i in range(0, 32): ib = rand.randrange(0, 2) cv.convert_bits(ib) ibl.append(ib) cr = ConvertBitField(_buffer(cv.collapsed_buffer())) for i in range(0, 32): j = cr.status(i) if ibl[i] != j: raise 'BIT conversion failed'
def convert_value_to_buffer(self): value = self.value if value is None: value = 0 cv = ConvertValue() self.read_conversion(cv, value, self.orders) self.buffer = cv.buffer if self.debug: print '_Register: convert value to buffer: ', self.value, self.buffer
def _test_register_conversions(self, orders, limit=6500): for i in range(0,limit): ir = rand.randrange(0, 65535) cv = ConvertValue() cv.convert_ushort(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_word(0, 0, orders) if ir != j: raise 'WORD conversion failed' ir = rand.randrange(-32767, 32767) cv = ConvertValue() cv.convert_short(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_int(0,0, orders) if ir != j: raise 'INT conversions failed' irh = rand.randrange(-127,127) cvh = ConvertValue() cvh.convert_hiint(irh, orders) irl = rand.randrange(-127,127) cvl = ConvertValue() cvl.convert_loint(irl, orders) for k in [0,1]: cvh.buffer[k] |= cvl.buffer[k] cr = ConvertRegister(cvh.buffer) j = cr.register_as_loint(0,0, orders) if irl != j: raise 'LO INT conversion failed' j = cr.register_as_hiint(0,0, orders) if irh != j: raise 'HI INT conversion failed' irh = chr(rand.randrange(0,255)) cvh = ConvertValue() cvh.convert_hichar(irh, orders) irl = chr(rand.randrange(0,255)) cvl = ConvertValue() cvl.convert_lochar(irl, orders) for k in [0,1]: cvh.buffer[k] |= cvl.buffer[k] cr = ConvertRegister(cvh.buffer) j = cr.register_as_lochar(0,0, orders) if irl != j: raise 'LO CHR conversion failed' j = cr.register_as_hichar(0,0, orders) if irh != j: raise 'HI CHR conversion failed' fr = rand.random() cv = ConvertValue() cv.convert_float(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_float(0,0, orders) if abs(fr - j) > 0.0001: raise 'FLOAT conversions failed' fr = rand.random() cv = ConvertValue() cv.convert_float8(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_float8(0,0, orders) if abs(fr - j) > 0.0000001: raise 'FLOAT8 conversions failed' ir = long(fr * float(4294967296)) cv = ConvertValue() cv.convert_ulong(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_ulong(0, 0, orders) if ir != j: raise 'ULONG conversion failed' ir = ir - 2147483648 cv = ConvertValue() cv.convert_long(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_long(0,0, orders) if ir != j: raise 'LONG conversions failed ' + str(ir) + ' ' + str(j) fr = rand.random() cv = ConvertValue() cv.convert_encorp_real_2(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_encorp_real_2(0, 0, orders) if abs(fr - j) > 0.0001: raise 'ENCORP REAL conversions failed (v1=%r,v2=%r)' % (fr,j) fr = rand.random() cv = ConvertValue() t = time.time() t = t + (1000000 * fr) cv.convert_time_6(t, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_time_6(0, 0, orders) if abs(int(t) - j) > 1: raise 'TIME 6 conversions failed (v1=%r,v2=%r)' % (t,j)
def _test_register_conversions(self, orders, limit=6500): for i in range(0, limit): ir = rand.randrange(0, 65535) cv = ConvertValue() cv.convert_ushort(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_word(0, 0, orders) if ir != j: raise 'WORD conversion failed' ir = rand.randrange(-32767, 32767) cv = ConvertValue() cv.convert_short(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_int(0, 0, orders) if ir != j: raise 'INT conversions failed' irh = rand.randrange(-127, 127) cvh = ConvertValue() cvh.convert_hiint(irh, orders) irl = rand.randrange(-127, 127) cvl = ConvertValue() cvl.convert_loint(irl, orders) for k in [0, 1]: cvh.buffer[k] |= cvl.buffer[k] cr = ConvertRegister(cvh.buffer) j = cr.register_as_loint(0, 0, orders) if irl != j: raise 'LO INT conversion failed' j = cr.register_as_hiint(0, 0, orders) if irh != j: raise 'HI INT conversion failed' irh = chr(rand.randrange(0, 255)) cvh = ConvertValue() cvh.convert_hichar(irh, orders) irl = chr(rand.randrange(0, 255)) cvl = ConvertValue() cvl.convert_lochar(irl, orders) for k in [0, 1]: cvh.buffer[k] |= cvl.buffer[k] cr = ConvertRegister(cvh.buffer) j = cr.register_as_lochar(0, 0, orders) if irl != j: raise 'LO CHR conversion failed' j = cr.register_as_hichar(0, 0, orders) if irh != j: raise 'HI CHR conversion failed' fr = rand.random() cv = ConvertValue() cv.convert_float(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_float(0, 0, orders) if abs(fr - j) > 0.0001: raise 'FLOAT conversions failed' fr = rand.random() cv = ConvertValue() cv.convert_float8(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_float8(0, 0, orders) if abs(fr - j) > 0.0000001: raise 'FLOAT8 conversions failed' ir = long(fr * float(4294967296)) cv = ConvertValue() cv.convert_ulong(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_ulong(0, 0, orders) if ir != j: raise 'ULONG conversion failed' ir = ir - 2147483648 cv = ConvertValue() cv.convert_long(ir, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_long(0, 0, orders) if ir != j: raise 'LONG conversions failed ' + str(ir) + ' ' + str(j) fr = rand.random() cv = ConvertValue() cv.convert_encorp_real_2(fr, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_encorp_real_2(0, 0, orders) if abs(fr - j) > 0.0001: raise 'ENCORP REAL conversions failed (v1=%r,v2=%r)' % (fr, j) fr = rand.random() cv = ConvertValue() t = time.time() t = t + (1000000 * fr) cv.convert_time_6(t, orders) cr = ConvertRegister(cv.buffer) j = cr.register_as_time_6(0, 0, orders) if abs(int(t) - j) > 1: raise 'TIME 6 conversions failed (v1=%r,v2=%r)' % (t, j)