-
Notifications
You must be signed in to change notification settings - Fork 68
/
realworld.rs
197 lines (173 loc) · 5.35 KB
/
realworld.rs
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#![allow(unused_must_use)]
extern crate notify_rust;
#[cfg(test)]
mod realworld {
use std::time::Duration;
#[cfg(all(feature = "images", unix, not(target_os = "macos")))]
use notify_rust::Image;
use notify_rust::*;
use ctor::ctor;
#[ctor]
fn init_color_backtrace() {
color_backtrace::install();
}
#[test]
fn burst() {
for msg in &[
"These should each",
"come in their own pop up.",
"If they don't than",
"I will have to complain about it.",
] {
Notification::new()
.summary("burst")
.appname(msg)
.body(msg)
.icon("media-floppy")
.show()
.unwrap();
}
for msg in &[
"These may be grouped",
"together by the server.",
"that is because the all have the same",
"appname.",
] {
Notification::new()
.summary("merged burst")
.body(msg)
.icon("applications-toys")
.show()
.unwrap();
}
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn closing() {
Notification::new()
.summary("You see me")
.body("you don't see me!")
.show()
.unwrap()
.close();
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn capabilities() {
let capabilities: Vec<String> = get_capabilities().unwrap();
for capability in capabilities {
Notification::new()
.summary("capability")
.body(&capability)
.show()
.unwrap();
}
}
#[test]
fn build_pattern() {
let notification = Notification::new().summary("foo").finalize();
assert_eq!(notification.summary, "foo");
let mut notification = Notification::new();
notification.body = "foo".to_string();
assert_eq!(notification.body, "foo");
let mut notification = Notification::new();
notification.icon = "foo".to_string();
assert_eq!(notification.icon, "foo");
let mut notification = Notification::new();
notification.summary = "foo".to_string();
assert_eq!(notification.summary, "foo");
let mut notification = Notification::new();
notification.timeout = Timeout::Milliseconds(42);
assert_eq!(notification.timeout, Timeout::Milliseconds(21 * 2));
let mut notification = Notification::new();
notification.summary = "foo".to_string();
assert_eq!(notification.summary, "foo");
}
#[test]
fn init() {
let mut message = Notification::new();
message.summary("invocation type 2");
message.body("your <b>body</b> is a <u>wonderland</u>");
message.show().unwrap();
Notification::new()
.summary("this is the summary")
.summary("invocation type 3")
.body("this is the body\nnewline<br/>linebreak")
.show()
.unwrap();
}
#[test]
fn should_allow_timeout_with_duration() {
let mut notification = Notification::new();
notification.timeout(Duration::from_secs(15));
assert!(matches!(
notification.timeout,
Timeout::Milliseconds(15_000)
));
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn urgency() {
// use it this way
use Urgency::*;
for urgency in &[
Hint::Urgency(Low),
Hint::Urgency(Normal),
Hint::Urgency(Critical),
] {
Notification::new()
.summary(&format!("Urgency {:?}", urgency))
.hint(urgency.clone())
.show()
.unwrap();
}
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn category() {
Notification::new()
.appname("thunderbird")
.summary("Category:email")
.icon("thunderbird")
.hint(Hint::Category("email".to_string()))
.show()
.unwrap();
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn persistent() {
Notification::new()
.summary("Incoming Call: Your Mom!")
.body("Resident:True")
.icon("call-start")
.hint(Hint::Resident(true))
.show()
.unwrap();
Notification::new()
.summary("Incoming Call: Your Mom!")
.body("Resident:False, but Timeout=0")
.icon("call-start")
.hint(Hint::Resident(false))
.timeout(0)
.show()
.unwrap();
}
#[test]
#[cfg(all(feature = "images", unix, not(target_os = "macos")))]
fn imagedata() {
let mut data: Vec<u8> = vec![0 as u8; 64 * 64 * 3];
for x in 0..64 {
for y in 0..64 {
let offset = (y * 64 + x) * 3;
data[offset] = (x + y) as u8;
data[offset + 1] = x as u8;
data[offset + 2] = y as u8;
}
}
Notification::new()
.summary("I can haz image data!")
.hint(Hint::ImageData(Image::from_rgb(64, 64, data).unwrap()))
.show()
.unwrap();
}
}