Add test for rkyv

This commit is contained in:
Peng Guanwen 2022-09-15 09:35:21 +00:00
parent 2cbb27c6f8
commit bc566d91bf
4 changed files with 48 additions and 1 deletions

View File

@ -61,7 +61,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: test
run: cargo test --features arbitrary,rand,serde-serialize,sparse,debug,io,compare,libm,proptest-support,slow-tests;
run: cargo test --features arbitrary,rand,serde-serialize,sparse,debug,io,compare,libm,proptest-support,slow-tests,rkyv-safe-deser;
test-nalgebra-glm:
runs-on: ubuntu-latest
steps:

View File

@ -66,6 +66,7 @@ rand = [ "rand-no-std", "rand-package/std", "rand-package/std_rng", "rand
arbitrary = [ "quickcheck" ]
proptest-support = [ "proptest" ]
slow-tests = []
rkyv-safe-deser = [ "rkyv-serialize", "rkyv/validation" ]
[dependencies]
nalgebra-macros = { version = "0.1", path = "nalgebra-macros", optional = true }

View File

@ -8,6 +8,8 @@ mod matrix_slice;
#[cfg(feature = "mint")]
mod mint;
mod serde;
#[cfg(feature = "rkyv-serialize-no-std")]
mod rkyv;
#[cfg(feature = "compare")]
mod matrixcompare;

44
tests/core/rkyv.rs Normal file
View File

@ -0,0 +1,44 @@
use na::{
Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix3x4, Point2, Point3, Quaternion, Rotation2,
Rotation3, Similarity3, SimilarityMatrix2, SimilarityMatrix3, Translation2, Translation3,
};
use rkyv::ser::{serializers::AllocSerializer, Serializer};
macro_rules! test_rkyv(
($($test: ident, $ty: ident);* $(;)*) => {$(
#[test]
fn $test() {
let v: $ty<f32> = rand::random();
// serialize
let mut serializer = AllocSerializer::<0>::default();
serializer.serialize_value(&v).unwrap();
let serialized = serializer.into_serializer().into_inner();
let deserialized: $ty<f32> = unsafe { rkyv::from_bytes_unchecked(&serialized).unwrap() };
assert_eq!(v, deserialized);
#[cfg(feature = "rkyv-safe-deser")]
{
let deserialized: $ty<f32> = rkyv::from_bytes(&serialized).unwrap();
assert_eq!(v, deserialized);
}
}
)*}
);
test_rkyv!(
rkyv_matrix3x4, Matrix3x4;
rkyv_point3, Point3;
rkyv_translation3, Translation3;
rkyv_rotation3, Rotation3;
rkyv_isometry3, Isometry3;
rkyv_isometry_matrix3, IsometryMatrix3;
rkyv_similarity3, Similarity3;
rkyv_similarity_matrix3, SimilarityMatrix3;
rkyv_quaternion, Quaternion;
rkyv_point2, Point2;
rkyv_translation2, Translation2;
rkyv_rotation2, Rotation2;
rkyv_isometry_matrix2, IsometryMatrix2;
rkyv_similarity_matrix2, SimilarityMatrix2;
);