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 message::MessagePayload;
8
9generate_empty_element!(
10 /// Requests that this message is acked by the final recipient once
11 /// received.
12 Request, "request", RECEIPTS
13);
14
15impl MessagePayload for Request {}
16
17generate_element!(
18 /// Notes that a previous message has correctly been received, it is
19 /// referenced by its 'id' attribute.
20 Received, "received", RECEIPTS,
21 attributes: [
22 /// The 'id' attribute of the received message.
23 id: Option<String> = "id" => optional,
24 ]
25);
26
27impl MessagePayload for Received {}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32 use try_from::TryFrom;
33 use minidom::Element;
34 use ns;
35
36 #[test]
37 fn test_size() {
38 assert_size!(Request, 0);
39 assert_size!(Received, 24);
40 }
41
42 #[test]
43 fn test_simple() {
44 let elem: Element = "<request xmlns='urn:xmpp:receipts'/>".parse().unwrap();
45 Request::try_from(elem).unwrap();
46
47 let elem: Element = "<received xmlns='urn:xmpp:receipts'/>".parse().unwrap();
48 Received::try_from(elem).unwrap();
49
50 let elem: Element = "<received xmlns='urn:xmpp:receipts' id='coucou'/>".parse().unwrap();
51 Received::try_from(elem).unwrap();
52 }
53
54 #[test]
55 fn test_serialise() {
56 let receipt = Request;
57 let elem: Element = receipt.into();
58 assert!(elem.is("request", ns::RECEIPTS));
59 assert_eq!(elem.attrs().count(), 0);
60
61 let receipt = Received {
62 id: Some(String::from("coucou")),
63 };
64 let elem: Element = receipt.into();
65 assert!(elem.is("received", ns::RECEIPTS));
66 assert_eq!(elem.attr("id"), Some("coucou"));
67 }
68}