def compare_old_to_current( self, converted_current_message: AbstractBloxrouteMessage, original_current_message: AbstractBloxrouteMessage, ): """ This method is run on every message comparision, when comparing the old version converted to the current version. Override this if a change is made that affects every message. """ self.assertEqual( constants.STARTING_SEQUENCE_BYTES, converted_current_message.rawbytes() [:constants.STARTING_SEQUENCE_BYTES_LEN], ) self.assertEqual( original_current_message.msg_type(), converted_current_message.msg_type(), ) self.assertEqual( original_current_message.payload_len(), converted_current_message.payload_len(), ) self.assertEqual( original_current_message.get_control_flags(), converted_current_message.get_control_flags(), )
def test_asbstract_bloxroute_message(self): total_msg_len = 1000 msg_type = b"dummy_msg" payload_len = total_msg_len - constants.BX_HDR_COMMON_OFF - constants.STARTING_SEQUENCE_BYTES_LEN buffer = bytearray(total_msg_len) message = AbstractBloxrouteMessage(msg_type=msg_type, payload_len=payload_len, buf=buffer) raw_bytes = message.rawbytes() self.assertEqual(total_msg_len, len(raw_bytes)) self.assertEqual(msg_type, message.msg_type()) self.assertEqual(payload_len, message.payload_len()) self.assertEqual(payload_len, len(message.payload())) self.assertTrue(message.get_control_flags() & BloxrouteMessageControlFlags.VALID) message.remove_control_flag(BloxrouteMessageControlFlags.VALID) self.assertFalse(message.get_control_flags() & BloxrouteMessageControlFlags.VALID) message.set_control_flag(BloxrouteMessageControlFlags.VALID) self.assertTrue(message.get_control_flags() & BloxrouteMessageControlFlags.VALID) # Trying set already set flag message.set_control_flag(BloxrouteMessageControlFlags.VALID) self.assertTrue(message.get_control_flags() & BloxrouteMessageControlFlags.VALID)