1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#![deny(unused)] extern crate notice_core; use notice_core::{Notify, Wait}; use std::thread; pub trait Pair { type Notify: 'static + Notify + Send; type Wait: 'static + Wait + Send; fn pair(&self) -> (Self::Notify, Self::Wait); } pub fn all_tests<P: Pair>(p: P) { test_notify_wait_one(&p); test_notify_wait_two(&p); test_wait_notify(&p); } fn test_notify_wait_one<P: Pair>(p: &P) { let (notify, wait) = p.pair(); notify.notify().unwrap(); let actual = wait.wait().unwrap(); assert_eq!(1, actual); } fn test_notify_wait_two<P: Pair>(p: &P) { let (notify, wait) = p.pair(); notify.notify().unwrap(); notify.notify().unwrap(); let actual = wait.wait().unwrap(); assert_eq!(2, actual); } fn test_wait_notify<P: Pair>(p: &P) { let (notify, wait) = p.pair(); let handle = thread::spawn(move || { wait.wait().unwrap() }); notify.notify().unwrap(); assert_eq!(1, handle.join().unwrap()); }