diff options
Diffstat (limited to 'openpgp/src/packet/userid.rs')
-rw-r--r-- | openpgp/src/packet/userid.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index 8459fd91..d88b06b2 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -1,4 +1,5 @@ use std::fmt; +use quickcheck::{Arbitrary, Gen}; use packet; use Packet; @@ -94,3 +95,26 @@ impl From<UserID> for Packet { s.to_packet() } } + +impl Arbitrary for UserID { + fn arbitrary<G: Gen>(g: &mut G) -> Self { + let mut u = UserID::new(); + u.set_userid_from_bytes(&Vec::<u8>::arbitrary(g)); + u + } +} + +#[cfg(test)] +mod tests { + use super::*; + use parse::Parse; + use serialize::Serialize; + + quickcheck! { + fn roundtrip(p: UserID) -> bool { + let q = UserID::from_bytes(&p.to_vec().unwrap()).unwrap(); + assert_eq!(p, q); + true + } + } +} |