]> git.proxmox.com Git - cargo.git/blob - vendor/proptest/src/arbitrary/_alloc/sync.rs
New upstream version 0.37.0
[cargo.git] / vendor / proptest / src / arbitrary / _alloc / sync.rs
1 //-
2 // Copyright 2017, 2018 The proptest developers
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 //! Arbitrary implementations for `std::sync`.
11
12 use crate::std_facade::Arc;
13 use core::sync::atomic::*;
14
15 use crate::arbitrary::*;
16 use crate::strategy::statics::static_map;
17 use crate::strategy::*;
18
19 wrap_from!(Arc);
20
21 macro_rules! atomic {
22 ($($type: ident, $base: ty);+) => {
23 $(arbitrary!($type, SMapped<$base, Self>;
24 static_map(any::<$base>(), $type::new)
25 );)+
26 };
27 }
28
29 // impl_wrap_gen!(AtomicPtr); // We don't have impl Arbitrary for *mut T yet.
30 atomic!(AtomicBool, bool; AtomicIsize, isize; AtomicUsize, usize);
31
32 #[cfg(feature = "unstable")]
33 atomic!(AtomicI8, i8; AtomicI16, i16; AtomicI32, i32;
34 AtomicU8, u8; AtomicU16, u16; AtomicU32, u32);
35
36 #[cfg(all(feature = "unstable", feature = "atomic64bit"))]
37 atomic!(AtomicI64, i64; AtomicU64, u64);
38
39 arbitrary!(Ordering,
40 LazyTupleUnion<(WA<Just<Self>>, WA<Just<Self>>, WA<Just<Self>>,
41 WA<Just<Self>>, WA<Just<Self>>)>;
42 prop_oneof![
43 Just(Ordering::Relaxed),
44 Just(Ordering::Release),
45 Just(Ordering::Acquire),
46 Just(Ordering::AcqRel),
47 Just(Ordering::SeqCst)
48 ]
49 );
50
51 #[cfg(test)]
52 mod test {
53 no_panic_test!(
54 arc => Arc<u8>,
55 atomic_bool => AtomicBool,
56 atomic_isize => AtomicIsize,
57 atomic_usize => AtomicUsize,
58 ordering => Ordering
59 );
60
61 #[cfg(feature = "unstable")]
62 no_panic_test!(
63 atomic_i8 => AtomicI8,
64 atomic_i16 => AtomicI16,
65 atomic_i32 => AtomicI32,
66 atomic_u8 => AtomicU8,
67 atomic_u16 => AtomicU16,
68 atomic_u32 => AtomicU32
69 );
70
71 #[cfg(all(feature = "unstable", feature = "atomic64bit"))]
72 no_panic_test!(
73 atomic_i64 => AtomicI64,
74 atomic_u64 => AtomicU64
75 );
76 }