File: print.rs

package info (click to toggle)
rust-glib 0.20.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,308 kB
  • sloc: makefile: 18
file content (57 lines) | stat: -rw-r--r-- 1,797 bytes parent folder | download | duplicates (3)
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
54
55
56
57
use std::sync::{Arc, Mutex};

use glib::*;

// Funny thing: we can't put those two tests in two different functions, otherwise they might
// conflict with the results of the other one (or it would be mandatory to run the tests on only
// one thread).
#[test]
fn check_print_handler() {
    //
    // g_print check part
    //
    let count = Arc::new(Mutex::new(0));
    set_print_handler(clone!(
        #[weak]
        count,
        move |_| {
            // we don't care about the message in here!
            *count.lock().expect("failed to lock 1") += 1;
        }
    ));
    g_print!("test");
    assert_eq!(*count.lock().expect("failed to lock 2"), 1);
    g_printerr!("one");
    assert_eq!(*count.lock().expect("failed to lock 3"), 1);
    g_print!("another");
    assert_eq!(*count.lock().expect("failed to lock 4"), 2);
    unset_print_handler();
    g_print!("tadam");
    assert_eq!(*count.lock().expect("failed to lock 5"), 2);
    g_printerr!("toudoum");
    assert_eq!(*count.lock().expect("failed to lock 6"), 2);

    //
    // g_printerr check part
    //
    let count = Arc::new(Mutex::new(0));
    set_printerr_handler(clone!(
        #[weak]
        count,
        move |_| {
            // we don't care about the message in here!
            *count.lock().expect("failed to lock a") += 1;
        }
    ));
    g_printerr!("test");
    assert_eq!(*count.lock().expect("failed to lock b"), 1);
    g_print!("one");
    assert_eq!(*count.lock().expect("failed to lock c"), 1);
    g_printerr!("another");
    assert_eq!(*count.lock().expect("failed to lock d"), 2);
    unset_printerr_handler();
    g_printerr!("tadam");
    assert_eq!(*count.lock().expect("failed to lock e"), 2);
    g_print!("toudoum");
    assert_eq!(*count.lock().expect("failed to lock f"), 2);
}