Debian Codegraph @

src/hints/tests.rs

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