Debian Codegraph @

src/hints/tests.rs

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #![cfg(all(test, unix, not(target_os = "macos")))]
2
3 use dbus::arg::messageitem::MessageItem as Item;
4
5 use self::Hint;
6 use super::{Urgency::*, *};
7
8 static _INIT: std::sync::LazyLock<()> = std::sync::LazyLock::new(|| {
9 color_backtrace::install();
10 });
11
12 #[test]
13 fn hint_to_item() {
14 let category = &Hint::Category("test-me".to_owned());
15 let (k, v) = category.into();
16
17 let test_k = Item::Str("category".into());
18 let test_v = Item::Variant(Box::new(Item::Str("test-me".into())));
19
20 assert_eq!(k, test_k);
21 assert_eq!(v, test_v);
22 }
23
24 #[test]
25 fn urgency() {
26 let low = &Hint::Urgency(Low);
27 let (k, v) = low.into();
28
29 let test_k = Item::Str("urgency".into());
30 let test_v = Item::Variant(Box::new(Item::Byte(0)));
31
32 assert_eq!(k, test_k);
33 assert_eq!(v, test_v);
34 }
35
36 #[test]
37 fn simple_hint_to_item() {
38 let old_hint = &Hint::Custom("foo".into(), "bar".into());
39
40 let (k, v) = old_hint.into();
41 let hint: Hint = (&k, &v).into();
42
43 assert_eq!(old_hint, &hint);
44 }
45
46 #[test]
47 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
48 fn imagedata_hint_to_item() {
49 let hint = &Hint::ImageData(Image::from_rgb(1, 1, vec![0, 0, 0]).unwrap());
50 let item: MessageItem = hint.into();
51 let test_item = Item::DictEntry(
52 Box::new(Item::Str(image_spec(*::SPEC_VERSION))),
53 Box::new(Item::Variant(Box::new(Item::Struct(vec![
54 Item::Int32(1),
55 Item::Int32(1),
56 Item::Int32(3),
57 Item::Bool(false),
58 Item::Int32(8),
59 Item::Int32(3),
60 Item::Array(
61 dbus::MessageItemArray::new(
62 vec![Item::Byte(0), Item::Byte(0), Item::Byte(0)],
63 "ay".into(),
64 )
65 .unwrap(),
66 ),
67 ])))),
68 );
69 assert_eq!(item, test_item);
70 }
71
72 #[test]
73 #[cfg(all(feature = "images_no_default_features", unix, not(target_os = "macos")))]
74 fn imagedata_hint_to_item_with_spec() {
75 let key = image_spec(Version::new(1, 0));
76 assert_eq!(key, String::from("icon_data"));
77
78 let key = image_spec(Version::new(1, 1));
79 assert_eq!(key, String::from("image_data"));
80
81 let key = image_spec(Version::new(1, 2));
82 assert_eq!(key, String::from("image-data"));
83 }