Debian Codegraph @

tests/realworld.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #![allow(unused_must_use)]
2 extern crate notify_rust;
3
4 #[cfg(test)]
5 mod realworld {
6
7 use std::time::Duration;
8
9 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
10 use notify_rust::Image;
11 use notify_rust::*;
12
13 #[test]
14 fn burst() {
15 for msg in &[
16 "These should each",
17 "come in their own pop up.",
18 "If they don't than",
19 "I will have to complain about it.",
20 ] {
21 Notification::new()
22 .summary("burst")
23 .appname(msg)
24 .body(msg)
25 .icon("media-floppy")
26 .show()
27 .unwrap();
28 }
29
30 for msg in &[
31 "These may be grouped",
32 "together by the server.",
33 "that is because the all have the same",
34 "appname.",
35 ] {
36 Notification::new()
37 .summary("merged burst")
38 .body(msg)
39 .icon("applications-toys")
40 .show()
41 .unwrap();
42 }
43 }
44
45 #[test]
46 #[cfg(all(unix, not(target_os = "macos")))]
47 fn closing() {
48 Notification::new()
49 .summary("You see me")
50 .body("you don't see me!")
51 .show()
52 .unwrap()
53 .close();
54 }
55
56 #[test]
57 #[cfg(all(unix, not(target_os = "macos")))]
58 fn capabilities() {
59 let capabilities: Vec<String> = get_capabilities().unwrap();
60 for capability in capabilities {
61 Notification::new()
62 .summary("capability")
63 .body(&capability)
64 .show()
65 .unwrap();
66 }
67 }
68
69 #[test]
70 fn build_pattern() {
71 let notification = Notification::new().summary("foo").finalize();
72 assert_eq!(notification.summary, "foo");
73
74 let mut notification = Notification::new();
75 notification.body = "foo".to_string();
76 assert_eq!(notification.body, "foo");
77
78 let mut notification = Notification::new();
79 notification.icon = "foo".to_string();
80 assert_eq!(notification.icon, "foo");
81
82 let mut notification = Notification::new();
83 notification.summary = "foo".to_string();
84 assert_eq!(notification.summary, "foo");
85
86 let mut notification = Notification::new();
87 notification.timeout = Timeout::Milliseconds(42);
88 assert_eq!(notification.timeout, Timeout::Milliseconds(21 * 2));
89
90 let mut notification = Notification::new();
91 notification.summary = "foo".to_string();
92 assert_eq!(notification.summary, "foo");
93 }
94
95 #[test]
96 fn init() {
97 let mut message = Notification::new();
98 message.summary("invocation type 2");
99 message.body("your <b>body</b> is a <u>wonderland</u>");
100 message.show().unwrap();
101
102 Notification::new()
103 .summary("this is the summary")
104 .summary("invocation type 3")
105 .body("this is the body\nnewline<br/>linebreak")
106 .show()
107 .unwrap();
108 }
109
110 #[test]
111 fn should_allow_timeout_with_duration() {
112 let mut notification = Notification::new();
113 notification.timeout(Duration::from_secs(15));
114 assert!(matches!(
115 notification.timeout,
116 Timeout::Milliseconds(15_000)
117 ));
118 }
119
120 #[test]
121 #[cfg(all(unix, not(target_os = "macos")))]
122 fn urgency() {
123 // use it this way
124 use Urgency::*;
125 for urgency in &[
126 Hint::Urgency(Low),
127 Hint::Urgency(Normal),
128 Hint::Urgency(Critical),
129 ] {
130 Notification::new()
131 .summary(&format!("Urgency {:?}", urgency))
132 .hint(urgency.clone())
133 .show()
134 .unwrap();
135 }
136 }
137
138 #[test]
139 #[cfg(all(unix, not(target_os = "macos")))]
140 fn category() {
141 Notification::new()
142 .appname("thunderbird")
143 .summary("Category:email")
144 .icon("thunderbird")
145 .hint(Hint::Category("email".to_string()))
146 .show()
147 .unwrap();
148 }
149
150 #[test]
151 #[cfg(all(unix, not(target_os = "macos")))]
152 fn persistent() {
153 Notification::new()
154 .summary("Incoming Call: Your Mom!")
155 .body("Resident:True")
156 .icon("call-start")
157 .hint(Hint::Resident(true))
158 .show()
159 .unwrap();
160
161 Notification::new()
162 .summary("Incoming Call: Your Mom!")
163 .body("Resident:False, but Timeout=0")
164 .icon("call-start")
165 .hint(Hint::Resident(false))
166 .timeout(0)
167 .show()
168 .unwrap();
169 }
170
171 #[test]
172 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
173 fn imagedata() {
174 let mut data: Vec<u8> = vec![0 as u8; 64 * 64 * 3];
175 for x in 0..64 {
176 for y in 0..64 {
177 let offset = (y * 64 + x) * 3;
178 data[offset] = (x + y) as u8;
179 data[offset + 1] = x as u8;
180 data[offset + 2] = y as u8;
181 }
182 }
183
184 Notification::new()
185 .summary("I can haz image data!")
186 .hint(Hint::ImageData(Image::from_rgb(64, 64, data).unwrap()))
187 .show()
188 .unwrap();
189 }
190 }