def test_round_trip_from_empty_msg_comparison(): # Instantiate an empty message the_msg = IpcMessage() # Set the message type and value msg_type = "cmd" the_msg.set_msg_type(msg_type) msg_val = "reset" the_msg.set_msg_val(msg_val) # Define and set some parameters paramInt1 = 1234 paramInt2 = 901201 paramInt3 = 4567 paramStr = "paramString" the_msg.set_param('paramInt1', paramInt1) the_msg.set_param('paramInt2', paramInt2) the_msg.set_param('paramInt3', paramInt3) the_msg.set_param('paramStr', paramStr) # Retrieve the encoded version the_msg_encoded = the_msg.encode() # Create another message from the encoded version msg_from_encoded = IpcMessage(from_str=the_msg_encoded) # Test that the comparison operators work correctly assert_true(the_msg == msg_from_encoded) assert_false(the_msg != msg_from_encoded)
def test_round_trip_from_empty_msg_comparison(): # Instantiate an empty message the_msg = IpcMessage() # Set the message type and value msg_type = "cmd" the_msg.set_msg_type(msg_type) msg_val = "reset" the_msg.set_msg_val(msg_val) # Define and set some parameters paramInt1 = 1234; paramInt2 = 901201; paramInt3 = 4567; paramStr = "paramString" the_msg.set_param('paramInt1', paramInt1) the_msg.set_param('paramInt2', paramInt2) the_msg.set_param('paramInt3', paramInt3) the_msg.set_param('paramStr', paramStr) # Retrieve the encoded version the_msg_encoded = the_msg.encode() # Create another message from the encoded version msg_from_encoded = IpcMessage(from_str=the_msg_encoded) # Test that the comparison operators work correctly assert_true(the_msg == msg_from_encoded) assert_false(the_msg != msg_from_encoded)
def test_filled_ipc_msg_valid(): # Instantiate an empty Message the_msg = IpcMessage() # Check that empty message is not valid assert_false(the_msg.is_valid()) # Set the message type and Value msg_type = "cmd" the_msg.set_msg_type(msg_type) msg_val = "reset" the_msg.set_msg_val(msg_val) # Check that the message is now valid assert_true(the_msg.is_valid())
def test_round_trip_from_empty_msg(): # Instantiate an empty message the_msg = IpcMessage() # Set the message type and value msg_type = "cmd" the_msg.set_msg_type(msg_type) msg_val = "reset" the_msg.set_msg_val(msg_val) # Define and set some parameters paramInt1 = 1234 paramInt2 = 901201 paramInt3 = 4567 paramStr = "paramString" the_msg.set_param('paramInt1', paramInt1) the_msg.set_param('paramInt2', paramInt2) the_msg.set_param('paramInt3', paramInt3) the_msg.set_param('paramStr', paramStr) # Retrieve the encoded version the_msg_encoded = the_msg.encode() # Create another message from the encoded version msg_from_encoded = IpcMessage(from_str=the_msg_encoded) # Validate the contents of all attributes and parameters of the new message assert_equal(msg_from_encoded.get_msg_type(), msg_type) assert_equal(msg_from_encoded.get_msg_val(), msg_val) assert_equal(msg_from_encoded.get_msg_timestamp(), the_msg.get_msg_timestamp()) assert_equal(msg_from_encoded.get_param('paramInt1'), paramInt1) assert_equal(msg_from_encoded.get_param('paramInt2'), paramInt2) assert_equal(msg_from_encoded.get_param('paramInt3'), paramInt3) assert_equal(msg_from_encoded.get_param('paramStr'), paramStr)
def test_round_trip_from_empty_msg(): # Instantiate an empty message the_msg = IpcMessage() # Set the message type and value msg_type = "cmd" the_msg.set_msg_type(msg_type) msg_val = "reset" the_msg.set_msg_val(msg_val) # Define and set some parameters paramInt1 = 1234; paramInt2 = 901201; paramInt3 = 4567; paramStr = "paramString" the_msg.set_param('paramInt1', paramInt1) the_msg.set_param('paramInt2', paramInt2) the_msg.set_param('paramInt3', paramInt3) the_msg.set_param('paramStr', paramStr) # Retrieve the encoded version the_msg_encoded = the_msg.encode() # Create another message from the encoded version msg_from_encoded = IpcMessage(from_str=the_msg_encoded) # Validate the contents of all attributes and parameters of the new message assert_equal(msg_from_encoded.get_msg_type(), msg_type) assert_equal(msg_from_encoded.get_msg_val(), msg_val) assert_equal(msg_from_encoded.get_msg_timestamp(), the_msg.get_msg_timestamp()) assert_equal(msg_from_encoded.get_param('paramInt1'), paramInt1) assert_equal(msg_from_encoded.get_param('paramInt2'), paramInt2) assert_equal(msg_from_encoded.get_param('paramInt3'), paramInt3) assert_equal(msg_from_encoded.get_param('paramStr'), paramStr)