diff --git a/src/lib.rs b/src/lib.rs index 56d17f47..d8a3f8cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,3 +8,4 @@ pub mod data_forms; pub mod media_element; pub mod ecaps2; pub mod jingle; +pub mod ping; diff --git a/src/ns.rs b/src/ns.rs index 55da2eb8..7c0903aa 100644 --- a/src/ns.rs +++ b/src/ns.rs @@ -2,3 +2,4 @@ pub const DISCO_INFO_NS: &'static str = "http://jabber.org/protocol/disco#info"; pub const DATA_FORMS_NS: &'static str = "jabber:x:data"; pub const MEDIA_ELEMENT_NS: &'static str = "urn:xmpp:media-element"; pub const JINGLE_NS: &'static str = "urn:xmpp:jingle:1"; +pub const PING_NS: &'static str = "urn:xmpp:ping"; diff --git a/src/ping.rs b/src/ping.rs new file mode 100644 index 00000000..7176fa42 --- /dev/null +++ b/src/ping.rs @@ -0,0 +1,53 @@ +use minidom::Element; + +use error::Error; + +use ns::PING_NS; + +#[derive(Debug)] +pub struct Ping { +} + +pub fn parse_ping(root: &Element) -> Result { + assert!(root.is("ping", PING_NS)); + for _ in root.children() { + return Err(Error::ParseError("Unknown child in ping element.")); + } + Ok(Ping { }) +} + +#[cfg(test)] +mod tests { + use minidom::Element; + use error::Error; + use ping; + + #[test] + fn test_simple() { + let elem: Element = "".parse().unwrap(); + ping::parse_ping(&elem).unwrap(); + } + + #[test] + fn test_invalid() { + let elem: Element = "".parse().unwrap(); + let error = ping::parse_ping(&elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown child in ping element."); + } + + #[test] + #[ignore] + fn test_invalid_attribute() { + let elem: Element = "".parse().unwrap(); + let error = ping::parse_ping(&elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in ping element."); + } +}