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