| 1 |
#![cfg(feature = "rkyv-serialize")] |
| 2 |
|
| 3 |
use na::{ |
| 4 |
Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix3x4, Point2, Point3, Quaternion, Rotation2, |
| 5 |
Rotation3, Similarity3, SimilarityMatrix2, SimilarityMatrix3, Translation2, Translation3, |
| 6 |
}; |
| 7 |
use rand; |
| 8 |
use rkyv::{Deserialize, Infallible}; |
| 9 |
|
| 10 |
macro_rules! test_rkyv_same_type( |
| 11 |
($($test: ident, $ty: ident);* $(;)*) => {$( |
| 12 |
#[test] |
| 13 |
fn $test() { |
| 14 |
let value: $ty<f32> = rand::random(); |
| 15 |
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap(); |
| 16 |
|
| 17 |
let archived = rkyv::check_archived_root::<$ty<f32>>(&bytes[..]).unwrap(); |
| 18 |
// Compare archived and non-archived |
| 19 |
assert_eq!(archived, &value); |
| 20 |
|
| 21 |
// Make sure Debug implementations are the same for Archived and non-Archived versions. |
| 22 |
assert_eq!(format!("{:?}", value), format!("{:?}", archived)); |
| 23 |
} |
| 24 |
)*} |
| 25 |
); |
| 26 |
macro_rules! test_rkyv_diff_type( |
| 27 |
($($test: ident, $ty: ident);* $(;)*) => {$( |
| 28 |
#[test] |
| 29 |
fn $test() { |
| 30 |
let value: $ty<String> = Default::default(); |
| 31 |
let bytes = rkyv::to_bytes::<_, 256>(&value).unwrap(); |
| 32 |
|
| 33 |
let archived = rkyv::check_archived_root::<$ty<String>>(&bytes[..]).unwrap(); |
| 34 |
let deserialized: $ty<String> = archived.deserialize(&mut Infallible).unwrap(); |
| 35 |
assert_eq!(deserialized, value); |
| 36 |
} |
| 37 |
)*} |
| 38 |
); |
| 39 |
|
| 40 |
// Tests to make sure |
| 41 |
test_rkyv_same_type!( |
| 42 |
rkyv_same_type_matrix3x4, Matrix3x4; |
| 43 |
rkyv_same_type_point3, Point3; |
| 44 |
rkyv_same_type_translation3, Translation3; |
| 45 |
rkyv_same_type_rotation3, Rotation3; |
| 46 |
rkyv_same_type_isometry3, Isometry3; |
| 47 |
rkyv_same_type_isometry_matrix3, IsometryMatrix3; |
| 48 |
rkyv_same_type_similarity3, Similarity3; |
| 49 |
rkyv_same_type_similarity_matrix3, SimilarityMatrix3; |
| 50 |
rkyv_same_type_quaternion, Quaternion; |
| 51 |
rkyv_same_type_point2, Point2; |
| 52 |
rkyv_same_type_translation2, Translation2; |
| 53 |
rkyv_same_type_rotation2, Rotation2; |
| 54 |
// rkyv_same_type_isometry2, Isometry2; |
| 55 |
rkyv_same_type_isometry_matrix2, IsometryMatrix2; |
| 56 |
// rkyv_same_type_similarity2, Similarity2; |
| 57 |
rkyv_same_type_similarity_matrix2, SimilarityMatrix2; |
| 58 |
); |
| 59 |
|
| 60 |
test_rkyv_diff_type! { |
| 61 |
rkyv_diff_type_matrix3x4, Matrix3x4; |
| 62 |
} |