nalgebra/tests/core/rkyv.rs

59 lines
1.9 KiB
Rust
Raw Normal View History

2022-07-13 21:22:55 +08:00
#![cfg(feature = "rkyv-serialize")]
use na::{
DMatrix, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix2x3, Matrix3x4, Point2,
Point3, Quaternion, Rotation2, Rotation3, Similarity2, Similarity3, SimilarityMatrix2,
SimilarityMatrix3, Translation2, Translation3, Unit, Vector2,
};
use rand;
2022-07-14 11:02:17 +08:00
use rkyv::{Archive, Serialize, Deserialize, Infallible};
2022-07-13 21:22:55 +08:00
2022-07-14 11:02:17 +08:00
macro_rules! test_rkyv_archived_impls(
2022-07-13 21:22:55 +08:00
($($test: ident, $ty: ident);* $(;)*) => {$(
#[test]
fn $test() {
2022-07-14 02:32:46 +08:00
let value: $ty<f32> = rand::random();
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap();
2022-07-13 21:22:55 +08:00
let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap();
assert_eq!(archived, &value);
2022-07-14 02:32:46 +08:00
assert_eq!(format!("{:?}", value), format!("{:?}", archived));
2022-07-13 21:22:55 +08:00
}
)*}
);
2022-07-14 11:02:17 +08:00
macro_rules! test_rkyv(
($($test: ident, $ty: ident);* $(;)*) => {$(
#[test]
fn $test() {
let value: $ty<f32> = rand::random();
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap();
let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap();
let deserialized: $ty<f32> = archived.deserialize(&mut Infallible).unwrap();
assert_eq!(deserialized, value);
}
)*}
);
test_rkyv_archived_impls!(
rkyv_matrix3x4, Matrix3x4;
);
2022-07-13 21:22:55 +08:00
test_rkyv!(
2022-07-14 02:32:46 +08:00
// rkyv_point3, Point3;
2022-07-14 11:02:17 +08:00
rkyv_translation3, Translation3;
/* rkyv_rotation3, Rotation3;
2022-07-13 21:22:55 +08:00
rkyv_isometry3, Isometry3;
rkyv_isometry_matrix3, IsometryMatrix3;
rkyv_similarity3, Similarity3;
rkyv_similarity_matrix3, SimilarityMatrix3;
2022-07-14 11:02:17 +08:00
rkyv_quaternion, Quaternion; */
// rkyv_point2, Point2;
2022-07-13 21:22:55 +08:00
rkyv_translation2, Translation2;
2022-07-14 11:02:17 +08:00
/* rkyv_rotation2, Rotation2;
2022-07-13 21:22:55 +08:00
rkyv_isometry2, Isometry2;
rkyv_isometry_matrix2, IsometryMatrix2;
rkyv_similarity2, Similarity2;
2022-07-14 02:32:46 +08:00
rkyv_similarity_matrix2, SimilarityMatrix2; */
2022-07-13 21:22:55 +08:00
);