@ -373,23 +373,36 @@ impl<V: ?Sized + MessageValue> SerializedMessage<V>
mod tests
mod tests
{
{
use super ::* ;
use super ::* ;
#[ test ]
fn message_serial ( )
/// Generic message test function
fn message_serial_generic < S , D > ( s : S , d : D )
where S : MessageSender ,
D : MessageReceiver
{
{
eprintln! ( "=== Message serialisation with tc, rc: S: {}, D: {}" , std ::any ::type_name ::< S > ( ) , std ::any ::type_name ::< D > ( ) ) ;
let message = MessageBuilder ::new ( )
let message = MessageBuilder ::new ( )
. create ( format! ( "This is a string, and some random data: {:?}" , aes ::AesKey ::generate ( ) . unwrap ( ) ) )
. create ( format! ( "This is a string, and some random data: {:?}" , aes ::AesKey ::generate ( ) . unwrap ( ) ) )
. expect ( "Failed to create message" ) ;
. expect ( "Failed to create message" ) ;
println! ( ">> Created message: {:?}" , message ) ;
println! ( ">> Created message: {:?}" , message ) ;
let serialised = message . serialise ( ( ) ) . expect ( "Failed to serialise message" ) ;
let serialised = message . serialise ( s ) . expect ( "Failed to serialise message" ) ;
println! ( ">> Serialised message: {:?}" , serialised ) ;
println! ( ">> Serialised message: {:?}" , serialised ) ;
let binary = serialised . into_bytes ( ) ;
let binary = serialised . into_bytes ( ) ;
println! ( ">> Written to {} bytes" , binary . len ( ) ) ;
println! ( ">> Written to {} bytes" , binary . len ( ) ) ;
let read = SerializedMessage ::from_bytes ( & binary ) . expect ( "Failed to read serialised message from binary" ) ;
let read = SerializedMessage ::from_bytes ( & binary ) . expect ( "Failed to read serialised message from binary" ) ;
println! ( ">> Read from bytes: {:?}" , read ) ;
println! ( ">> Read from bytes: {:?}" , read ) ;
let deserialised = Message ::deserialize ( & read , ( ) ) . expect ( "Failed to deserialise message" ) ;
let deserialised = Message ::deserialize ( & read , d ) . expect ( "Failed to deserialise message" ) ;
println! ( ">> Deserialised message: {:?}" , deserialised ) ;
println! ( ">> Deserialised message: {:?}" , deserialised ) ;
assert_eq! ( message , deserialised , "Messages not identical" ) ;
assert_eq! ( message , deserialised , "Messages not identical" ) ;
assert_eq! ( message . into_value ( ) , deserialised . into_value ( ) , "Message values not identical" ) ;
assert_eq! ( message . into_value ( ) , deserialised . into_value ( ) , "Message values not identical" ) ;
eprintln! ( "=== Passed (S: {}, D: {}) ===" , std ::any ::type_name ::< S > ( ) , std ::any ::type_name ::< D > ( ) ) ;
}
}
#[ test ]
fn message_serial_basic ( )
{
message_serial_generic ( ( ) , ( ) ) ;
}
//TODO: message_serial_sign(), message_serial_encrypted(), message_serial_encrypted_sign()
}
}