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 minidom::Element;
8
9use error::Error;
10
11use ns;
12
13generate_empty_element!(Request, "request", ns::RECEIPTS);
14
15generate_element_with_only_attributes!(Received, "received", ns::RECEIPTS, [
16 id: Option<String> = "id" => optional,
17]);
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22 use try_from::TryFrom;
23
24 #[test]
25 fn test_simple() {
26 let elem: Element = "<request xmlns='urn:xmpp:receipts'/>".parse().unwrap();
27 Request::try_from(elem).unwrap();
28
29 let elem: Element = "<received xmlns='urn:xmpp:receipts'/>".parse().unwrap();
30 Received::try_from(elem).unwrap();
31
32 let elem: Element = "<received xmlns='urn:xmpp:receipts' id='coucou'/>".parse().unwrap();
33 Received::try_from(elem).unwrap();
34 }
35
36 #[test]
37 fn test_serialise() {
38 let receipt = Request;
39 let elem: Element = receipt.into();
40 assert!(elem.is("request", ns::RECEIPTS));
41 assert_eq!(elem.attrs().count(), 0);
42
43 let receipt = Received {
44 id: Some(String::from("coucou")),
45 };
46 let elem: Element = receipt.into();
47 assert!(elem.is("received", ns::RECEIPTS));
48 assert_eq!(elem.attr("id"), Some("coucou"));
49 }
50}