src/lib.rs 🔗
@@ -8,3 +8,4 @@ pub mod data_forms;
pub mod media_element;
pub mod ecaps2;
pub mod jingle;
+pub mod ping;
Emmanuel Gil Peyrot created
src/lib.rs | 1 +
src/ns.rs | 1 +
src/ping.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+)
@@ -8,3 +8,4 @@ pub mod data_forms;
pub mod media_element;
pub mod ecaps2;
pub mod jingle;
+pub mod ping;
@@ -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";
@@ -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<Ping, Error> {
+ 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 = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
+ ping::parse_ping(&elem).unwrap();
+ }
+
+ #[test]
+ fn test_invalid() {
+ let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".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 = "<ping xmlns='urn:xmpp:ping' coucou=''/>".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.");
+ }
+}