ping.rs

 1use minidom::Element;
 2
 3use error::Error;
 4
 5use ns::PING_NS;
 6
 7#[derive(Debug)]
 8pub struct Ping {
 9}
10
11pub fn parse_ping(root: &Element) -> Result<Ping, Error> {
12    assert!(root.is("ping", PING_NS));
13    for _ in root.children() {
14        return Err(Error::ParseError("Unknown child in ping element."));
15    }
16    Ok(Ping {  })
17}
18
19#[cfg(test)]
20mod tests {
21    use minidom::Element;
22    use error::Error;
23    use ping;
24
25    #[test]
26    fn test_simple() {
27        let elem: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
28        ping::parse_ping(&elem).unwrap();
29    }
30
31    #[test]
32    fn test_invalid() {
33        let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".parse().unwrap();
34        let error = ping::parse_ping(&elem).unwrap_err();
35        let message = match error {
36            Error::ParseError(string) => string,
37            _ => panic!(),
38        };
39        assert_eq!(message, "Unknown child in ping element.");
40    }
41
42    #[test]
43    #[ignore]
44    fn test_invalid_attribute() {
45        let elem: Element = "<ping xmlns='urn:xmpp:ping' coucou=''/>".parse().unwrap();
46        let error = ping::parse_ping(&elem).unwrap_err();
47        let message = match error {
48            Error::ParseError(string) => string,
49            _ => panic!(),
50        };
51        assert_eq!(message, "Unknown attribute in ping element.");
52    }
53}