Debian Codegraph @

tests/ownworld.rs

raw symbols SCIP
1 #![cfg(feature = "server")]
2 #![allow(unused_must_use)]
3 #![cfg(all(unix, not(target_os = "macos")))]
4 extern crate notify_rust;
5
6 #[cfg(test)]
7 mod ownworld {
8
9 use notify_rust::server::*;
10 use notify_rust::*;
11 use std::thread;
12
13 #[test]
14 #[ignore]
15 fn server_can_be_stopped() {
16 let thread_handle = thread::spawn(move || {
17 let server = NotificationServer::create();
18 NotificationServer::start(&server, |_| {})
19 });
20
21 stop_server();
22 assert!(thread_handle.join().is_ok());
23 }
24
25 #[test]
26 #[ignore]
27 fn actions_vec() {
28 let thread_handle = thread::spawn(move || {
29 let server = NotificationServer::create();
30 NotificationServer::start(&server, |notification| {
31 assert_eq!(notification.actions[0], "actions_vec0");
32 assert_eq!(notification.actions[1], "actions_vec1");
33 assert_eq!(notification.actions[2], "actions_vec2");
34 assert_eq!(notification.actions[3], "actions_vec3");
35 })
36 });
37
38 #[allow(deprecated)]
39 Notification::new()
40 .summary("Notification with actions")
41 .body("action1=\"Action One\", something_else=\"Something Else\"")
42 .icon("dialog-information")
43 .actions(vec![
44 "actions_vec0".into(),
45 "actions_vec1".into(),
46 "actions_vec2".into(),
47 "actions_vec3".into(),
48 ])
49 .show();
50
51 stop_server();
52 assert!(thread_handle.join().is_ok());
53 }
54
55 #[test]
56 #[ignore]
57 fn actions_automatic() {
58 let server = NotificationServer::create();
59 let thread_handle = thread::spawn(move || {
60 NotificationServer::start(&server, |notification| {
61 assert_eq!(notification.actions[0], "actions_built0");
62 assert_eq!(notification.actions[1], "actions_built1");
63 assert_eq!(notification.actions[2], "actions_built2");
64 assert_eq!(notification.actions[3], "actions_built3");
65 assert_eq!(notification.timeout, Timeout::Milliseconds(6000));
66 })
67 });
68
69 Notification::new()
70 .summary("Another notification with actions")
71 .body("action0=\"Press me please\", action1=\"firefox\"")
72 .icon("dialog-information")
73 .timeout(6000) //miliseconds
74 .action("actions_built0", "actions_built1")
75 .action("actions_built2", "actions_built3")
76 .show();
77
78 stop_server();
79 assert!(thread_handle.join().is_ok());
80 }
81
82 #[test]
83 #[ignore]
84 #[should_panic]
85 fn no_server() {
86 let server = NotificationServer::create();
87 thread::spawn(move || {
88 NotificationServer::start(&server, |notification| println!("{:#?}", notification))
89 });
90
91 stop_server();
92 Notification::new()
93 .summary("Another notification with actions")
94 .body("action0=\"Press me please\", action1=\"firefox\"")
95 .show()
96 .unwrap();
97 }
98
99 #[test]
100 #[ignore]
101 #[should_panic]
102 fn join_failed() {
103 let thread_handle = thread::spawn(|| {
104 let server = NotificationServer::create();
105 NotificationServer::start(&server, |notification| {
106 assert_eq!(notification.timeout, Timeout::Milliseconds(6000));
107 assert_eq!(notification.actions[0], "this is no action");
108 })
109 });
110
111 Notification::new()
112 .summary("Notification without timeout")
113 .show();
114 stop_server();
115 assert!(thread_handle.join().is_ok());
116 }
117 }