1// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use crate::message::MessagePayload;
8
9generate_empty_element!(
10 /// Requests that this message is acked by the final recipient once
11 /// received.
12 Request,
13 "request",
14 RECEIPTS
15);
16
17impl MessagePayload for Request {}
18
19generate_element!(
20 /// Notes that a previous message has correctly been received, it is
21 /// referenced by its 'id' attribute.
22 Received, "received", RECEIPTS,
23 attributes: [
24 /// The 'id' attribute of the received message.
25 id: Option<String> = "id",
26 ]
27);
28
29impl MessagePayload for Received {}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34 use crate::ns;
35 use minidom::Element;
36 use std::convert::TryFrom;
37
38 #[cfg(target_pointer_width = "32")]
39 #[test]
40 fn test_size() {
41 assert_size!(Request, 0);
42 assert_size!(Received, 12);
43 }
44
45 #[cfg(target_pointer_width = "64")]
46 #[test]
47 fn test_size() {
48 assert_size!(Request, 0);
49 assert_size!(Received, 24);
50 }
51
52 #[test]
53 fn test_simple() {
54 let elem: Element = "<request xmlns='urn:xmpp:receipts'/>".parse().unwrap();
55 Request::try_from(elem).unwrap();
56
57 let elem: Element = "<received xmlns='urn:xmpp:receipts'/>".parse().unwrap();
58 Received::try_from(elem).unwrap();
59
60 let elem: Element = "<received xmlns='urn:xmpp:receipts' id='coucou'/>"
61 .parse()
62 .unwrap();
63 Received::try_from(elem).unwrap();
64 }
65
66 #[test]
67 fn test_serialise() {
68 let receipt = Request;
69 let elem: Element = receipt.into();
70 assert!(elem.is("request", ns::RECEIPTS));
71 assert_eq!(elem.attrs().count(), 0);
72
73 let receipt = Received {
74 id: Some(String::from("coucou")),
75 };
76 let elem: Element = receipt.into();
77 assert!(elem.is("received", ns::RECEIPTS));
78 assert_eq!(elem.attr("id"), Some("coucou"));
79 }
80}