File: ownworld.rs

package info (click to toggle)
rust-notify-rust 4.11.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 604 kB
  • sloc: sh: 18; makefile: 4
file content (117 lines) | stat: -rw-r--r-- 3,736 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#![cfg(feature = "server")]
#![allow(unused_must_use)]
#![cfg(all(unix, not(target_os = "macos")))]
extern crate notify_rust;

#[cfg(test)]
mod ownworld {

    use notify_rust::server::*;
    use notify_rust::*;
    use std::thread;

    #[test]
    #[ignore]
    fn server_can_be_stopped() {
        let thread_handle = thread::spawn(move || {
            let server = NotificationServer::create();
            NotificationServer::start(&server, |_| {})
        });

        stop_server();
        assert!(thread_handle.join().is_ok());
    }

    #[test]
    #[ignore]
    fn actions_vec() {
        let thread_handle = thread::spawn(move || {
            let server = NotificationServer::create();
            NotificationServer::start(&server, |notification| {
                assert_eq!(notification.actions[0], "actions_vec0");
                assert_eq!(notification.actions[1], "actions_vec1");
                assert_eq!(notification.actions[2], "actions_vec2");
                assert_eq!(notification.actions[3], "actions_vec3");
            })
        });

        #[allow(deprecated)]
        Notification::new()
            .summary("Notification with actions")
            .body("action1=\"Action One\", something_else=\"Something Else\"")
            .icon("dialog-information")
            .actions(vec![
                "actions_vec0".into(),
                "actions_vec1".into(),
                "actions_vec2".into(),
                "actions_vec3".into(),
            ])
            .show();

        stop_server();
        assert!(thread_handle.join().is_ok());
    }

    #[test]
    #[ignore]
    fn actions_automatic() {
        let server = NotificationServer::create();
        let thread_handle = thread::spawn(move || {
            NotificationServer::start(&server, |notification| {
                assert_eq!(notification.actions[0], "actions_built0");
                assert_eq!(notification.actions[1], "actions_built1");
                assert_eq!(notification.actions[2], "actions_built2");
                assert_eq!(notification.actions[3], "actions_built3");
                assert_eq!(notification.timeout, Timeout::Milliseconds(6000));
            })
        });

        Notification::new()
            .summary("Another notification with actions")
            .body("action0=\"Press me please\", action1=\"firefox\"")
            .icon("dialog-information")
            .timeout(6000) //miliseconds
            .action("actions_built0", "actions_built1")
            .action("actions_built2", "actions_built3")
            .show();

        stop_server();
        assert!(thread_handle.join().is_ok());
    }

    #[test]
    #[ignore]
    #[should_panic]
    fn no_server() {
        let server = NotificationServer::create();
        thread::spawn(move || {
            NotificationServer::start(&server, |notification| println!("{:#?}", notification))
        });

        stop_server();
        Notification::new()
            .summary("Another notification with actions")
            .body("action0=\"Press me please\", action1=\"firefox\"")
            .show()
            .unwrap();
    }

    #[test]
    #[ignore]
    #[should_panic]
    fn join_failed() {
        let thread_handle = thread::spawn(|| {
            let server = NotificationServer::create();
            NotificationServer::start(&server, |notification| {
                assert_eq!(notification.timeout, Timeout::Milliseconds(6000));
                assert_eq!(notification.actions[0], "this is no action");
            })
        });

        Notification::new()
            .summary("Notification without timeout")
            .show();
        stop_server();
        assert!(thread_handle.join().is_ok());
    }
}