extern crate rand; extern crate nalgebra; extern crate abomonation; use rand::random; use abomonation::{Abomonation, encode, decode}; use nalgebra::{ DMatrix, Matrix3x4, Point3, Translation3, Rotation3, Isometry3, Quaternion, IsometryMatrix3, Similarity3, SimilarityMatrix3 }; #[test] fn abomonate_dmatrix() { assert_encode_and_decode(&DMatrix::::new_random(3, 5)); } macro_rules! test_abomonation( ($($test: ident, $ty: ty);* $(;)*) => {$( #[test] fn $test() { assert_encode_and_decode(&random::<$ty>()); } )*} ); test_abomonation! { abomonate_matrix3x4, Matrix3x4; abomonate_point3, Point3; abomonate_translation3, Translation3; abomonate_rotation3, Rotation3; abomonate_isometry3, Isometry3; abomonate_isometry_matrix3, IsometryMatrix3; abomonate_similarity3, Similarity3; abomonate_similarity_matrix3, SimilarityMatrix3; abomonate_quaternion, Quaternion; } fn assert_encode_and_decode(data: &T) { let mut bytes = Vec::new(); unsafe { encode(data, &mut bytes); } if let Some((result, rest)) = unsafe { decode::(&mut bytes) } { assert!(result == data); assert!(rest.len() == 0, "binary data was not decoded completely"); } }