| 1 |
use std::sync::{Arc, Mutex}; |
| 2 |
|
| 3 |
use glib::*; |
| 4 |
|
| 5 |
// Funny thing: we can't put those two tests in two different functions, otherwise they might |
| 6 |
// conflict with the results of the other one (or it would be mandatory to run the tests on only |
| 7 |
// one thread). |
| 8 |
#[test] |
| 9 |
fn check_print_handler() { |
| 10 |
// |
| 11 |
// g_print check part |
| 12 |
// |
| 13 |
let count = Arc::new(Mutex::new(0)); |
| 14 |
set_print_handler(clone!( |
| 15 |
#[weak] |
| 16 |
count, |
| 17 |
move |_| { |
| 18 |
// we don't care about the message in here! |
| 19 |
*count.lock().expect("failed to lock 1") += 1; |
| 20 |
} |
| 21 |
)); |
| 22 |
g_print!("test"); |
| 23 |
assert_eq!(*count.lock().expect("failed to lock 2"), 1); |
| 24 |
g_printerr!("one"); |
| 25 |
assert_eq!(*count.lock().expect("failed to lock 3"), 1); |
| 26 |
g_print!("another"); |
| 27 |
assert_eq!(*count.lock().expect("failed to lock 4"), 2); |
| 28 |
unset_print_handler(); |
| 29 |
g_print!("tadam"); |
| 30 |
assert_eq!(*count.lock().expect("failed to lock 5"), 2); |
| 31 |
g_printerr!("toudoum"); |
| 32 |
assert_eq!(*count.lock().expect("failed to lock 6"), 2); |
| 33 |
|
| 34 |
// |
| 35 |
// g_printerr check part |
| 36 |
// |
| 37 |
let count = Arc::new(Mutex::new(0)); |
| 38 |
set_printerr_handler(clone!( |
| 39 |
#[weak] |
| 40 |
count, |
| 41 |
move |_| { |
| 42 |
// we don't care about the message in here! |
| 43 |
*count.lock().expect("failed to lock a") += 1; |
| 44 |
} |
| 45 |
)); |
| 46 |
g_printerr!("test"); |
| 47 |
assert_eq!(*count.lock().expect("failed to lock b"), 1); |
| 48 |
g_print!("one"); |
| 49 |
assert_eq!(*count.lock().expect("failed to lock c"), 1); |
| 50 |
g_printerr!("another"); |
| 51 |
assert_eq!(*count.lock().expect("failed to lock d"), 2); |
| 52 |
unset_printerr_handler(); |
| 53 |
g_printerr!("tadam"); |
| 54 |
assert_eq!(*count.lock().expect("failed to lock e"), 2); |
| 55 |
g_print!("toudoum"); |
| 56 |
assert_eq!(*count.lock().expect("failed to lock f"), 2); |
| 57 |
} |