def test_accessors(self): expected = [] expected.append("""\ // m/s, (0 to 4294967295) public long GetFieldA() { return (long)FieldAccess.toUnsignedLong(m_data.getInt(0)); }""") expected.append("""\ // , (0 to 2147483647) public long GetFABitsA() { return (long)((GetFieldA() >> 0) & 0x7fffffff); }""") expected.append("""\ // , (0 to 65535) public int GetFieldB() { return (int)FieldAccess.toUnsignedInt(m_data.getShort(4)); }""") expected.append("""\ // , (0 to 255) public short GetFieldC(int idx) { return (short)FieldAccess.toUnsignedInt(m_data.get(6+idx*1)); }""") expected.append("""\ // , (0 to 255) public short GetFieldD() { return (short)FieldAccess.toUnsignedInt(m_data.get(11)); }""") expected.append("""\ // , (0.0 to 215.355) public float GetBitsA() { return ((float)((GetFieldD() >> 0) & 0xf) * 14.357f); }""") expected.append("""\ // , (0 to 7) public short GetBitsB() { return (short)((GetFieldD() >> 4) & 0x7); }""") expected.append("""\ // , (0 to 1) public short GetBitsC() { return (short)((GetFieldD() >> 7) & 0x1); }""") expected.append("""\ // , (0.0 to 10.0) public float GetFieldE() { return (float)m_data.getFloat(12); }""") expected.append("""\ // , (1.828 to 176946.328) public float GetFieldF() { return (((float)((int)FieldAccess.toUnsignedInt(m_data.getShort(16))) * 2.7f) + 1.828f); }""") expected.append("""\ // m/s, (0 to 4294967295) public void SetFieldA(long value) { m_data.putInt(0, (int)value); }""") expected.append("""\ // , (0 to 2147483647) public void SetFABitsA(long value) { SetFieldA((long)((GetFieldA() & ~(0x7fffffff << 0)) | ((value & 0x7fffffff) << 0))); }""") expected.append("""\ // , (0 to 65535) public void SetFieldB(int value) { m_data.putShort(4, (short)value); }""") expected.append("""\ // , (0 to 255) public void SetFieldC(short value, int idx) { m_data.put(6+idx*1, (byte)value); }""") expected.append("""\ // , (0 to 255) public void SetFieldD(short value) { m_data.put(11, (byte)value); }""") expected.append("""\ // , (0.0 to 215.355) public void SetBitsA(float value) { SetFieldD((short)((GetFieldD() & ~(0xf << 0)) | (((short)(value / 14.357f) & 0xf) << 0))); }""") expected.append("""\ // , (0 to 7) public void SetBitsB(short value) { SetFieldD((short)((GetFieldD() & ~(0x7 << 4)) | ((value & 0x7) << 4))); }""") expected.append("""\ // , (0 to 1) public void SetBitsC(short value) { SetFieldD((short)((GetFieldD() & ~(0x1 << 7)) | ((value & 0x1) << 7))); }""") expected.append("""\ // , (0.0 to 10.0) public void SetFieldE(float value) { m_data.putFloat(12, (float)value); }""") expected.append("""\ // , (1.828 to 176946.328) public void SetFieldF(float value) { m_data.putShort(16, (short)(int)((value - 1.828f) / 2.7f)); }""") expCount = len(expected) observed = language.accessors(MsgParser.Messages(self.msgDict)[0]) obsCount = len(observed) self.assertEqual(expCount, obsCount) for i in range(expCount): self.assertMultiLineEqual(expected[i], observed[i]) with self.assertRaises(IndexError): language.accessors(MsgParser.Messages(self.msgDict)[1])
def test_accessors(self): expected = [] expected.append("""\ /* m/s, (0 to 4294967295)*/ uint32_t GetFieldA() const { return Get_uint32_t(&m_data[0]); }""") expected.append("""\ /* , (0 to 2147483647)*/ uint32_t GetFABitsA() const { return (GetFieldA() >> 0) & 0x7fffffff; }""") expected.append("""\ /* , (0 to 65535)*/ uint16_t GetFieldB() const { return Get_uint16_t(&m_data[4]); }""") expected.append("""\ /* , (0 to 255)*/ uint8_t GetFieldC(int idx) const { return Get_uint8_t(&m_data[6+idx*1]); }""") expected.append("""\ /* , (0 to 255)*/ uint8_t GetFieldD() const { return Get_uint8_t(&m_data[11]); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (0.0 to 215.355)*/ float GetBitsA() const { return (float((GetFieldD() >> 0) & 0xf) * 14.357f); } #endif """) expected.append("""\ /* , (0 to 7)*/ EnumA GetBitsB() const { return EnumA((GetFieldD() >> 4) & 0x7); }""") expected.append("""\ /* , (0 to 1)*/ uint8_t GetBitsC() const { return (GetFieldD() >> 7) & 0x1; }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (0.0 to 10.0)*/ float GetFieldE() const { return Get_float(&m_data[12]); } #endif """) expected.append("""\ /* , (-2147483648 to 2147483647)*/ int32_t GetFieldS1_Member1() const { return Get_int32_t(&m_data[16]); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (DBL_MIN to DBL_MAX)*/ double GetFieldS1_Member2() const { return Get_double(&m_data[20]); } #endif """) expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (1.828 to 176946.328)*/ float GetFieldF() const { return ((float(Get_uint16_t(&m_data[28])) * 2.7f) + 1.828f); } #endif """) expected.append("""\ /* , (-2147483648 to 2147483647)*/ int32_t GetFieldS2_Member1(int idx) const { return Get_int32_t(&m_data[30+idx*12]); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (DBL_MIN to DBL_MAX)*/ double GetFieldS2_Member2(int idx) const { return Get_double(&m_data[34+idx*12]); } #endif """) expected.append("""\ /* m/s, (0 to 4294967295)*/ void SetFieldA(uint32_t value) { Set_uint32_t(&m_data[0], value); }""") expected.append("""\ /* , (0 to 2147483647)*/ void SetFABitsA(uint32_t value) { SetFieldA((GetFieldA() & ~(0x7fffffff << 0)) | ((value & 0x7fffffff) << 0)); }""") expected.append("""\ /* , (0 to 65535)*/ void SetFieldB(uint16_t value) { Set_uint16_t(&m_data[4], value); }""") expected.append("""\ /* , (0 to 255)*/ void SetFieldC(uint8_t value, int idx) { Set_uint8_t(&m_data[6+idx*1], value); }""") expected.append("""\ /* , (0 to 255)*/ void SetFieldD(uint8_t value) { Set_uint8_t(&m_data[11], value); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (0.0 to 215.355)*/ void SetBitsA(float value) { SetFieldD((GetFieldD() & ~(0xf << 0)) | (((uint8_t)(value / 14.357f) & 0xf) << 0)); } #endif """) expected.append("""\ /* , (0 to 7)*/ void SetBitsB(EnumA value) { SetFieldD((GetFieldD() & ~(0x7 << 4)) | (((uint8_t)(value) & 0x7) << 4)); }""") expected.append("""\ /* , (0 to 1)*/ void SetBitsC(uint8_t value) { SetFieldD((GetFieldD() & ~(0x1 << 7)) | ((value & 0x1) << 7)); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (0.0 to 10.0)*/ void SetFieldE(float value) { Set_float(&m_data[12], value); } #endif """) expected.append("""\ /* , (-2147483648 to 2147483647)*/ void SetFieldS1_Member1(int32_t value) { Set_int32_t(&m_data[16], value); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (DBL_MIN to DBL_MAX)*/ void SetFieldS1_Member2(double value) { Set_double(&m_data[20], value); } #endif """) expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (1.828 to 176946.328)*/ void SetFieldF(float value) { Set_uint16_t(&m_data[28], (uint16_t)((value - 1.828f) / 2.7f)); } #endif """) expected.append("""\ /* , (-2147483648 to 2147483647)*/ void SetFieldS2_Member1(int32_t value, int idx) { Set_int32_t(&m_data[30+idx*12], value); }""") expected.append("""\ #ifndef DISABLE_FLOAT_ACCESSORS /* , (DBL_MIN to DBL_MAX)*/ void SetFieldS2_Member2(double value, int idx) { Set_double(&m_data[34+idx*12], value); } #endif """) expected.append("""\ /* , (0 to 255)*/ uint8_t* FieldC() { return (uint8_t*)&m_data[6]; }""") expCount = len(expected) observed = language.accessors(MsgParser.Messages(self.msgDict)[0]) obsCount = len(observed) self.assertEqual(expCount, obsCount) for i in range(expCount): self.assertMultiLineEqual(expected[i], observed[i]) with self.assertRaises(IndexError): language.accessors(MsgParser.Messages(self.msgDict)[1])
def test_accessors(self): expected = [] expected.append("""\ // m/s, (0 to 4294967295) fun getFieldA(): UInt { return data.getUInt(0) }""") expected.append("""\ // , (0 to 2147483647) fun getFABitsA(): UInt { return ((getFieldA().toInt() ushr 0) and 0x7fffffff).toUInt() }""") expected.append("""\ // , (0 to 65535) fun getFieldB(): UShort { return data.getUShort(4) }""") expected.append("""\ // , (0 to 255) fun getFieldC(index: Int): UByte { return data.getUByte(6 + index*1) }""") expected.append("""\ // , (0 to 255) fun getFieldD(): UByte { return data.getUByte(11) }""") expected.append("""\ // , (0.0 to 215.355) fun getBitsA(): Float { val valI = ((getFieldD().toInt() ushr 0) and 0xf).toFloat() val valD = (valI.toInt().toDouble() * 14.357f).toFloat() return valD }""") expected.append("""\ // , (0 to 7) fun getBitsB(): UByte { return ((getFieldD().toInt() ushr 4) and 0x7).toUByte() }""") expected.append("""\ // , (0 to 1) fun getBitsC(): UByte { return ((getFieldD().toInt() ushr 7) and 0x1).toUByte() }""") expected.append("""\ // , (0.0 to 10.0) fun getFieldE(): Float { return data.getFloat(12) }""") expected.append("""\ // , (-2147483648 to 2147483647) fun getFieldS1_Member1(): Int { return data.getInt(16) }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) fun getFieldS1_Member2(): Double { return data.getDouble(20) }""") expected.append("""\ // , (1.828 to 176946.328) fun getFieldF(): Float { val valI : UShort = data.getUShort(28) val valD = ((valI.toInt().toDouble() * 2.7f) + 1.828f).toFloat() return valD }""") expected.append("""\ // , (-2147483648 to 2147483647) fun getFieldS2_Member1(index: Int): Int { return data.getInt(30 + index*12) }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) fun getFieldS2_Member2(index: Int): Double { return data.getDouble(34 + index*12) }""") expected.append("""\ // m/s, (0 to 4294967295) fun setFieldA(value: UInt) { data.putUInt(0, value) }""") expected.append("""\ // , (0 to 2147483647) fun setFABitsA(value: UInt) { var valI = getFieldA().toInt() // read valI = valI and (0x7fffffff shl 0).inv() // clear our bits valI = valI or ((value.toInt() and 0x7fffffff) shl 0) // set our bits setFieldA(valI.toUInt()) // write }""") expected.append("""\ // , (0 to 65535) fun setFieldB(value: UShort) { data.putUShort(4, value) }""") expected.append("""\ // , (0 to 255) fun setFieldC(value: UByte, index: Int) { data.putUByte(6 + index*1, value) }""") expected.append("""\ // , (0 to 255) fun setFieldD(value: UByte) { data.putUByte(11, value) }""") expected.append("""\ // , (0.0 to 215.355) fun setBitsA(value: Float) { var valI = getFieldD().toInt() // read valI = valI and (0xf shl 0).inv() // clear our bits valI = valI or (((value / 14.357f).toInt() and 0xf) shl 0) // set our bits setFieldD(valI.toUByte()) // write }""") expected.append("""\ // , (0 to 7) fun setBitsB(value: UByte) { var valI = getFieldD().toInt() // read valI = valI and (0x7 shl 4).inv() // clear our bits valI = valI or ((value.toInt() and 0x7) shl 4) // set our bits setFieldD(valI.toUByte()) // write }""") expected.append("""\ // , (0 to 1) fun setBitsC(value: UByte) { var valI = getFieldD().toInt() // read valI = valI and (0x1 shl 7).inv() // clear our bits valI = valI or ((value.toInt() and 0x1) shl 7) // set our bits setFieldD(valI.toUByte()) // write }""") expected.append("""\ // , (0.0 to 10.0) fun setFieldE(value: Float) { data.putFloat(12, value) }""") expected.append("""\ // , (-2147483648 to 2147483647) fun setFieldS1_Member1(value: Int) { data.putInt(16, value) }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) fun setFieldS1_Member2(value: Double) { data.putDouble(20, value) }""") expected.append("""\ // , (1.828 to 176946.328) fun setFieldF(value: Float) { data.putUShort(28, ((value - 1.828f) / 2.7f).toUShort()) }""") expected.append("""\ // , (-2147483648 to 2147483647) fun setFieldS2_Member1(value: Int, index: Int) { data.putInt(30 + index*12, value) }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) fun setFieldS2_Member2(value: Double, index: Int) { data.putDouble(34 + index*12, value) }""") expCount = len(expected) observed = language.accessors(MsgParser.Messages(self.msgDict)[0]) obsCount = len(observed) self.assertEqual(expCount, obsCount) for i in range(expCount): self.assertMultiLineEqual(expected[i], observed[i]) with self.assertRaises(IndexError): language.accessors(MsgParser.Messages(self.msgDict)[1])
def test_accessors(self): expected = [] expected.append("""\ @msg.units('m/s') @msg.default('1') @msg.minVal('0') @msg.maxVal('4294967295') @msg.offset('0') @msg.size('4') @msg.count(1) def GetFieldA(self): \"\"\"\"\"\" value = struct.unpack_from('>L', self.rawBuffer(), TestCase1.MSG_OFFSET + 0)[0] return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('2147483647') @msg.offset('0') @msg.size('0') @msg.count(1) def GetFABitsA(self): \"\"\"\"\"\" value = (self.GetFieldA() >> 0) & 0x7fffffff return value """) expected.append("""\ @msg.units('') @msg.default('2') @msg.minVal('0') @msg.maxVal('65535') @msg.offset('4') @msg.size('2') @msg.count(1) def GetFieldB(self): \"\"\"\"\"\" value = struct.unpack_from('>H', self.rawBuffer(), TestCase1.MSG_OFFSET + 4)[0] return value """) expected.append("""\ @msg.units('') @msg.default('3') @msg.minVal('0') @msg.maxVal('255') @msg.offset('6') @msg.size('1') @msg.count(5) def GetFieldC(self, idx): \"\"\"\"\"\" value = struct.unpack_from('B', self.rawBuffer(), TestCase1.MSG_OFFSET + 6+idx*1)[0] return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('255') @msg.offset('11') @msg.size('1') @msg.count(1) def GetFieldD(self): \"\"\"\"\"\" value = struct.unpack_from('B', self.rawBuffer(), TestCase1.MSG_OFFSET + 11)[0] return value """) expected.append("""\ @msg.units('') @msg.default('7.1') @msg.minVal('0.0') @msg.maxVal('215.355') @msg.offset('11') @msg.size('0') @msg.count(1) def GetBitsA(self): \"\"\"\"\"\" value = (float((self.GetFieldD() >> 0) & 0xf) * 14.357) return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('7') @msg.offset('11') @msg.size('0') @msg.count(1) def GetBitsB(self, enumAsInt=0): \"\"\"\"\"\" value = (self.GetFieldD() >> 4) & 0x7 if not enumAsInt: value = TestCase1.ReverseEnumA.get(value, value) return value """) expected.append("""\ @msg.units('') @msg.default('1') @msg.minVal('0') @msg.maxVal('1') @msg.offset('11') @msg.size('0') @msg.count(1) def GetBitsC(self): \"\"\"\"\"\" value = (self.GetFieldD() >> 7) & 0x1 return value """) expected.append("""\ @msg.units('') @msg.default('3.14159') @msg.minVal('0.0') @msg.maxVal('10.0') @msg.offset('12') @msg.size('4') @msg.count(1) def GetFieldE(self): \"\"\"\"\"\" value = struct.unpack_from('>f', self.rawBuffer(), TestCase1.MSG_OFFSET + 12)[0] return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('-2147483648') @msg.maxVal('2147483647') @msg.offset('16') @msg.size('4') @msg.count(1) def GetFieldS1_Member1(self): \"\"\"\"\"\" value = struct.unpack_from('>l', self.rawBuffer(), TestCase1.MSG_OFFSET + 16)[0] return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('DBL_MIN') @msg.maxVal('DBL_MAX') @msg.offset('20') @msg.size('8') @msg.count(1) def GetFieldS1_Member2(self): \"\"\"\"\"\" value = struct.unpack_from('>d', self.rawBuffer(), TestCase1.MSG_OFFSET + 20)[0] return value """) expected.append("""\ @msg.units('') @msg.default('3.14') @msg.minVal('1.828') @msg.maxVal('176946.328') @msg.offset('28') @msg.size('2') @msg.count(1) def GetFieldF(self): \"\"\"\"\"\" value = struct.unpack_from('>H', self.rawBuffer(), TestCase1.MSG_OFFSET + 28)[0] value = ((value * 2.7) + 1.828) return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('-2147483648') @msg.maxVal('2147483647') @msg.offset('30') @msg.size('4') @msg.count(3) def GetFieldS2_Member1(self, idx): \"\"\"\"\"\" value = struct.unpack_from('>l', self.rawBuffer(), TestCase1.MSG_OFFSET + 30+idx*12)[0] return value """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('DBL_MIN') @msg.maxVal('DBL_MAX') @msg.offset('34') @msg.size('8') @msg.count(3) def GetFieldS2_Member2(self, idx): \"\"\"\"\"\" value = struct.unpack_from('>d', self.rawBuffer(), TestCase1.MSG_OFFSET + 34+idx*12)[0] return value """) expected.append("""\ @msg.units('m/s') @msg.default('1') @msg.minVal('0') @msg.maxVal('4294967295') @msg.offset('0') @msg.size('4') @msg.count(1) def SetFieldA(self, value): \"\"\"\"\"\" tmp = min(max(value, 0), 4294967295) struct.pack_into('>L', self.rawBuffer(), TestCase1.MSG_OFFSET + 0, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('2147483647') @msg.offset('0') @msg.size('0') @msg.count(1) def SetFABitsA(self, value): \"\"\"\"\"\" tmp = min(max(value, 0), 2147483647) self.SetFieldA((self.GetFieldA() & ~(0x7fffffff << 0)) | ((tmp & 0x7fffffff) << 0)) """) expected.append("""\ @msg.units('') @msg.default('2') @msg.minVal('0') @msg.maxVal('65535') @msg.offset('4') @msg.size('2') @msg.count(1) def SetFieldB(self, value): \"\"\"\"\"\" tmp = min(max(value, 0), 65535) struct.pack_into('>H', self.rawBuffer(), TestCase1.MSG_OFFSET + 4, tmp) """) expected.append("""\ @msg.units('') @msg.default('3') @msg.minVal('0') @msg.maxVal('255') @msg.offset('6') @msg.size('1') @msg.count(5) def SetFieldC(self, value, idx): \"\"\"\"\"\" tmp = min(max(value, 0), 255) struct.pack_into('B', self.rawBuffer(), TestCase1.MSG_OFFSET + 6+idx*1, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('255') @msg.offset('11') @msg.size('1') @msg.count(1) def SetFieldD(self, value): \"\"\"\"\"\" tmp = min(max(value, 0), 255) struct.pack_into('B', self.rawBuffer(), TestCase1.MSG_OFFSET + 11, tmp) """) expected.append("""\ @msg.units('') @msg.default('7.1') @msg.minVal('0.0') @msg.maxVal('215.355') @msg.offset('11') @msg.size('0') @msg.count(1) def SetBitsA(self, value): \"\"\"\"\"\" tmp = min(max(int(value / 14.357), 0), 15) self.SetFieldD((self.GetFieldD() & ~(0xf << 0)) | ((tmp & 0xf) << 0)) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('0') @msg.maxVal('7') @msg.offset('11') @msg.size('0') @msg.count(1) def SetBitsB(self, value): \"\"\"\"\"\" defaultValue = 0 try: value = int(float(value)) except ValueError: pass if isinstance(value, int) or value.isdigit(): defaultValue = int(value) value = TestCase1.EnumA.get(value, defaultValue) tmp = min(max(value, 0), 7) self.SetFieldD((self.GetFieldD() & ~(0x7 << 4)) | ((tmp & 0x7) << 4)) """) expected.append("""\ @msg.units('') @msg.default('1') @msg.minVal('0') @msg.maxVal('1') @msg.offset('11') @msg.size('0') @msg.count(1) def SetBitsC(self, value): \"\"\"\"\"\" tmp = min(max(value, 0), 1) self.SetFieldD((self.GetFieldD() & ~(0x1 << 7)) | ((tmp & 0x1) << 7)) """) expected.append("""\ @msg.units('') @msg.default('3.14159') @msg.minVal('0.0') @msg.maxVal('10.0') @msg.offset('12') @msg.size('4') @msg.count(1) def SetFieldE(self, value): \"\"\"\"\"\" tmp = value struct.pack_into('>f', self.rawBuffer(), TestCase1.MSG_OFFSET + 12, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('-2147483648') @msg.maxVal('2147483647') @msg.offset('16') @msg.size('4') @msg.count(1) def SetFieldS1_Member1(self, value): \"\"\"\"\"\" tmp = min(max(value, -2147483648), 2147483647) struct.pack_into('>l', self.rawBuffer(), TestCase1.MSG_OFFSET + 16, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('DBL_MIN') @msg.maxVal('DBL_MAX') @msg.offset('20') @msg.size('8') @msg.count(1) def SetFieldS1_Member2(self, value): \"\"\"\"\"\" tmp = value struct.pack_into('>d', self.rawBuffer(), TestCase1.MSG_OFFSET + 20, tmp) """) expected.append("""\ @msg.units('') @msg.default('3.14') @msg.minVal('1.828') @msg.maxVal('176946.328') @msg.offset('28') @msg.size('2') @msg.count(1) def SetFieldF(self, value): \"\"\"\"\"\" tmp = min(max(int((value - 1.828) / 2.7), 0), 65535) struct.pack_into('>H', self.rawBuffer(), TestCase1.MSG_OFFSET + 28, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('-2147483648') @msg.maxVal('2147483647') @msg.offset('30') @msg.size('4') @msg.count(3) def SetFieldS2_Member1(self, value, idx): \"\"\"\"\"\" tmp = min(max(value, -2147483648), 2147483647) struct.pack_into('>l', self.rawBuffer(), TestCase1.MSG_OFFSET + 30+idx*12, tmp) """) expected.append("""\ @msg.units('') @msg.default('') @msg.minVal('DBL_MIN') @msg.maxVal('DBL_MAX') @msg.offset('34') @msg.size('8') @msg.count(3) def SetFieldS2_Member2(self, value, idx): \"\"\"\"\"\" tmp = value struct.pack_into('>d', self.rawBuffer(), TestCase1.MSG_OFFSET + 34+idx*12, tmp) """) expCount = len(expected) observed = language.accessors(MsgParser.Messages(self.msgDict)[0]) obsCount = len(observed) self.assertEqual(expCount, obsCount) for i in range(expCount): self.assertMultiLineEqual(expected[i], observed[i]) with self.assertRaises(IndexError): language.accessors(MsgParser.Messages(self.msgDict)[1])
def test_accessors(self): expected = [] expected.append("""\ // m/s, (0 to 4294967295) public long GetFieldA() { return (long)FieldAccess.toUnsignedLong(m_data.getInt(0)); }""") expected.append("""\ // , (0 to 2147483647) public long GetFABitsA() { return (long)((GetFieldA() >> 0) & 0x7fffffff); }""") expected.append("""\ // , (0 to 65535) public int GetFieldB() { return (int)FieldAccess.toUnsignedInt(m_data.getShort(4)); }""") expected.append("""\ // , (0 to 255) public short GetFieldC(int idx) { return (short)FieldAccess.toUnsignedInt(m_data.get(6+idx*1)); }""") expected.append("""\ // , (0 to 255) public short GetFieldD() { return (short)FieldAccess.toUnsignedInt(m_data.get(11)); }""") expected.append("""\ // , (0.0 to 215.355) public float GetBitsA() { return ((float)((GetFieldD() >> 0) & 0xf) * 14.357f); }""") expected.append("""\ // , (0 to 7) public short GetBitsB() { return (short)((GetFieldD() >> 4) & 0x7); }""") expected.append("""\ // , (0 to 1) public short GetBitsC() { return (short)((GetFieldD() >> 7) & 0x1); }""") expected.append("""\ // , (0.0 to 10.0) public float GetFieldE() { return (float)m_data.getFloat(12); }""") expected.append("""\ // , (-2147483648 to 2147483647) public int GetFieldS1_Member1() { return (int)m_data.getInt(16); }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) public double GetFieldS1_Member2() { return (double)m_data.getDouble(20); }""") expected.append("""\ // , (1.828 to 176946.328) public float GetFieldF() { return (((float)((int)FieldAccess.toUnsignedInt(m_data.getShort(28))) * 2.7f) + 1.828f); }""") expected.append("""\ // , (-2147483648 to 2147483647) public int GetFieldS2_Member1(int idx) { return (int)m_data.getInt(30+idx*12); }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) public double GetFieldS2_Member2(int idx) { return (double)m_data.getDouble(34+idx*12); }""") expected.append("""\ // m/s, (0 to 4294967295) public void SetFieldA(long value) { m_data.putInt(0, (int)value); }""") expected.append("""\ // , (0 to 2147483647) public void SetFABitsA(long value) { SetFieldA((long)((GetFieldA() & ~(0x7fffffff << 0)) | ((value & 0x7fffffff) << 0))); }""") expected.append("""\ // , (0 to 65535) public void SetFieldB(int value) { m_data.putShort(4, (short)value); }""") expected.append("""\ // , (0 to 255) public void SetFieldC(short value, int idx) { m_data.put(6+idx*1, (byte)value); }""") expected.append("""\ // , (0 to 255) public void SetFieldD(short value) { m_data.put(11, (byte)value); }""") expected.append("""\ // , (0.0 to 215.355) public void SetBitsA(float value) { SetFieldD((short)((GetFieldD() & ~(0xf << 0)) | (((short)(value / 14.357f) & 0xf) << 0))); }""") expected.append("""\ // , (0 to 7) public void SetBitsB(short value) { SetFieldD((short)((GetFieldD() & ~(0x7 << 4)) | ((value & 0x7) << 4))); }""") expected.append("""\ // , (0 to 1) public void SetBitsC(short value) { SetFieldD((short)((GetFieldD() & ~(0x1 << 7)) | ((value & 0x1) << 7))); }""") expected.append("""\ // , (0.0 to 10.0) public void SetFieldE(float value) { m_data.putFloat(12, (float)value); }""") expected.append("""\ // , (-2147483648 to 2147483647) public void SetFieldS1_Member1(int value) { m_data.putInt(16, (int)value); }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) public void SetFieldS1_Member2(double value) { m_data.putDouble(20, (double)value); }""") expected.append("""\ // , (1.828 to 176946.328) public void SetFieldF(float value) { m_data.putShort(28, (short)(int)((value - 1.828f) / 2.7f)); }""") expected.append("""\ // , (-2147483648 to 2147483647) public void SetFieldS2_Member1(int value, int idx) { m_data.putInt(30+idx*12, (int)value); }""") expected.append("""\ // , (DBL_MIN to DBL_MAX) public void SetFieldS2_Member2(double value, int idx) { m_data.putDouble(34+idx*12, (double)value); }""") expCount = len(expected) observed = language.accessors(MsgParser.Messages(self.msgDict)[0]) obsCount = len(observed) self.assertEqual(expCount, obsCount) for i in range(expCount): self.assertMultiLineEqual(expected[i], observed[i]) with self.assertRaises(IndexError): language.accessors(MsgParser.Messages(self.msgDict)[1])