Debian Codegraph @

debian/missing-sources/glam/src/features/impl_zerocopy.rs

raw
1 #[cfg(test)]
2 mod test {
3 use crate::{
4 Affine2, Affine3A, DAffine2, DAffine3, DMat2, DMat3, DMat4, DQuat, DVec2, DVec3, DVec4,
5 I16Vec2, I16Vec3, I16Vec4, I64Vec2, I64Vec3, I64Vec4, I8Vec2, I8Vec3, I8Vec4, IVec2, IVec3,
6 IVec4, Mat2, Mat3, Mat3A, Mat4, Quat, U16Vec2, U16Vec3, U16Vec4, U64Vec2, U64Vec3, U64Vec4,
7 U8Vec2, U8Vec3, U8Vec4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4,
8 };
9 use core::mem;
10
11 macro_rules! test_into_bytes_t {
12 ($name:ident, $t:ty) => {
13 #[test]
14 fn $name() {
15 let t = <$t>::default();
16 let b = zerocopy::IntoBytes::as_bytes(&t);
17 // the below loop will fail in miri if we're doing something bad here.
18 for bi in b {
19 assert_eq!(bi, bi);
20 }
21 // should be the same address
22 assert_eq!(&t as *const $t as usize, b.as_ptr() as usize);
23 // should be the same size
24 assert_eq!(b.len(), mem::size_of_val(&t));
25 }
26 };
27 }
28
29 macro_rules! test_from_bytes_t {
30 ($name:ident, $t:ident) => {
31 #[test]
32 fn $name() {
33 let b = [0_u8; mem::size_of::<$t>()];
34 let t = zerocopy::FromBytes::read_from_bytes(&b);
35 // should be the same size
36 let t: $t = t.unwrap();
37 // should be zero
38 assert_eq!(t, <$t as zerocopy::FromZeros>::new_zeroed());
39 }
40 };
41 }
42
43 test_from_bytes_t!(affine2, Affine2);
44 test_from_bytes_t!(affine3a_from, Affine3A);
45 #[cfg(all(
46 any(
47 target_arch = "aarch64",
48 target_feature = "sse2",
49 target_feature = "simd128"
50 ),
51 not(feature = "scalar-math")
52 ))]
53 test_into_bytes_t!(affine3a_into, Affine3A);
54 test_from_bytes_t!(mat2_from, Mat2);
55 test_into_bytes_t!(mat2_into, Mat2);
56 test_from_bytes_t!(mat3_from, Mat3);
57 test_into_bytes_t!(mat3_into, Mat3);
58 test_from_bytes_t!(mat3a_from, Mat3A);
59 #[cfg(all(
60 any(
61 feature = "core-simd",
62 target_arch = "aarch64",
63 target_feature = "sse2",
64 target_feature = "simd128"
65 ),
66 not(feature = "scalar-math")
67 ))]
68 test_into_bytes_t!(mat3a_into, Mat3A);
69 test_from_bytes_t!(mat4_from, Mat4);
70 test_into_bytes_t!(mat4_into, Mat4);
71 test_from_bytes_t!(quat_from, Quat);
72 test_into_bytes_t!(quat_into, Quat);
73 test_from_bytes_t!(vec2_from, Vec2);
74 test_into_bytes_t!(vec2_into, Vec2);
75 test_from_bytes_t!(vec3_from, Vec3);
76 test_into_bytes_t!(vec3_into, Vec3);
77 test_from_bytes_t!(vec3a_from, Vec3A);
78 #[cfg(all(
79 any(
80 feature = "core-simd",
81 target_arch = "aarch64",
82 target_feature = "sse2",
83 target_feature = "simd128"
84 ),
85 not(feature = "scalar-math")
86 ))]
87 test_into_bytes_t!(vec3a_into, Vec3A);
88 test_from_bytes_t!(vec4_from, Vec4);
89 test_into_bytes_t!(vec4_into, Vec4);
90
91 test_into_bytes_t!(daffine2, DAffine2);
92 test_from_bytes_t!(daffine3_from, DAffine3);
93 test_into_bytes_t!(daffine3_into, DAffine3);
94 test_from_bytes_t!(dmat2_from, DMat2);
95 test_into_bytes_t!(dmat2_into, DMat2);
96 test_from_bytes_t!(dmat3_from, DMat3);
97 test_into_bytes_t!(dmat3_into, DMat3);
98 test_from_bytes_t!(dmat4_from, DMat4);
99 test_into_bytes_t!(dmat4_into, DMat4);
100 test_from_bytes_t!(dquat_from, DQuat);
101 test_into_bytes_t!(dquat_into, DQuat);
102 test_from_bytes_t!(dvec2_from, DVec2);
103 test_into_bytes_t!(dvec2_into, DVec2);
104 test_from_bytes_t!(dvec3_from, DVec3);
105 test_into_bytes_t!(dvec3_into, DVec3);
106 test_from_bytes_t!(dvec4_from, DVec4);
107 test_into_bytes_t!(dvec4_into, DVec4);
108
109 test_from_bytes_t!(i8vec2_from, I8Vec2);
110 test_into_bytes_t!(i8vec2_into, I8Vec2);
111 test_from_bytes_t!(i8vec3_from, I8Vec3);
112 test_into_bytes_t!(i8vec3_into, I8Vec3);
113 test_from_bytes_t!(i8vec4_from, I8Vec4);
114 test_into_bytes_t!(i8vec4_into, I8Vec4);
115
116 test_from_bytes_t!(u8vec2_from, U8Vec2);
117 test_into_bytes_t!(u8vec2_into, U8Vec2);
118 test_from_bytes_t!(u8vec3_from, U8Vec3);
119 test_into_bytes_t!(u8vec3_into, U8Vec3);
120 test_from_bytes_t!(u8vec4_from, U8Vec4);
121 test_into_bytes_t!(u8vec4_into, U8Vec4);
122
123 test_from_bytes_t!(i16vec2_from, I16Vec2);
124 test_into_bytes_t!(i16vec2_into, I16Vec2);
125 test_from_bytes_t!(i16vec3_from, I16Vec3);
126 test_into_bytes_t!(i16vec3_into, I16Vec3);
127 test_from_bytes_t!(i16vec4_from, I16Vec4);
128 test_into_bytes_t!(i16vec4_into, I16Vec4);
129
130 test_from_bytes_t!(u16vec2_from, U16Vec2);
131 test_into_bytes_t!(u16vec2_into, U16Vec2);
132 test_from_bytes_t!(u16vec3_from, U16Vec3);
133 test_into_bytes_t!(u16vec3_into, U16Vec3);
134 test_from_bytes_t!(u16vec4_from, U16Vec4);
135 test_into_bytes_t!(u16vec4_into, U16Vec4);
136
137 test_from_bytes_t!(ivec2_from, IVec2);
138 test_into_bytes_t!(ivec2_into, IVec2);
139 test_from_bytes_t!(ivec3_from, IVec3);
140 test_into_bytes_t!(ivec3_into, IVec3);
141 test_from_bytes_t!(ivec4_from, IVec4);
142 test_into_bytes_t!(ivec4_into, IVec4);
143
144 test_from_bytes_t!(uvec2_from, UVec2);
145 test_into_bytes_t!(uvec2_into, UVec2);
146 test_from_bytes_t!(uvec3_from, UVec3);
147 test_into_bytes_t!(uvec3_into, UVec3);
148 test_from_bytes_t!(uvec4_from, UVec4);
149 test_into_bytes_t!(uvec4_into, UVec4);
150
151 test_from_bytes_t!(i64vec2_from, I64Vec2);
152 test_into_bytes_t!(i64vec2_into, I64Vec2);
153 test_from_bytes_t!(i64vec3_from, I64Vec3);
154 test_into_bytes_t!(i64vec3_into, I64Vec3);
155 test_from_bytes_t!(i64vec4_from, I64Vec4);
156 test_into_bytes_t!(i64vec4_into, I64Vec4);
157
158 test_from_bytes_t!(u64vec2_from, U64Vec2);
159 test_into_bytes_t!(u64vec2_into, U64Vec2);
160 test_from_bytes_t!(u64vec3_from, U64Vec3);
161 test_into_bytes_t!(u64vec3_into, U64Vec3);
162 test_from_bytes_t!(u64vec4_from, U64Vec4);
163 test_into_bytes_t!(u64vec4_into, U64Vec4);
164 }