mam: Add tests.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-29 06:41:55 +01:00
parent 0b2d46aa3a
commit eecb47f4ed

View file

@ -239,45 +239,126 @@ pub fn serialise_prefs(prefs: &Prefs) -> Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
/*
use minidom::Element; use minidom::Element;
use error::Error; use error::Error;
use mam; use mam;
#[test] #[test]
fn test_simple() { fn test_query() {
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0' id='coucou'/>".parse().unwrap(); let elem: Element = "<query xmlns='urn:xmpp:mam:2'/>".parse().unwrap();
mam::parse_query(&elem).unwrap(); mam::parse_query(&elem).unwrap();
} }
#[test] #[test]
fn test_invalid_child() { fn test_result() {
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'><coucou/></replace>".parse().unwrap(); let elem: Element = r#"
let error = mam::parse_query(&elem).unwrap_err(); <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
let message = match error { <forwarded xmlns='urn:xmpp:forward:0'>
Error::ParseError(string) => string, <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
_ => panic!(), <message xmlns='jabber:client' from="witch@shakespeare.lit" to="macbeth@shakespeare.lit">
}; <body>Hail to thee</body>
assert_eq!(message, "Unknown child in replace element."); </message>
</forwarded>
</result>
"#.parse().unwrap();
mam::parse_result(&elem).unwrap();
} }
#[test] #[test]
fn test_invalid_id() { fn test_fin() {
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'/>".parse().unwrap(); let elem: Element = r#"
<fin xmlns='urn:xmpp:mam:2'>
<set xmlns='http://jabber.org/protocol/rsm'>
<first index='0'>28482-98726-73623</first>
<last>09af3-cc343-b409f</last>
</set>
</fin>
"#.parse().unwrap();
mam::parse_fin(&elem).unwrap();
}
#[test]
fn test_query_x() {
let elem: Element = r#"
<query xmlns='urn:xmpp:mam:2'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:2</value>
</field>
<field var='with'>
<value>juliet@capulet.lit</value>
</field>
</x>
</query>
"#.parse().unwrap();
mam::parse_query(&elem).unwrap();
}
#[test]
fn test_query_x_set() {
let elem: Element = r#"
<query xmlns='urn:xmpp:mam:2'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:2</value>
</field>
<field var='start'>
<value>2010-08-07T00:00:00Z</value>
</field>
</x>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>10</max>
</set>
</query>
"#.parse().unwrap();
mam::parse_query(&elem).unwrap();
}
#[test]
fn test_prefs_get() {
let elem: Element = "<prefs xmlns='urn:xmpp:mam:2'/>".parse().unwrap();
mam::parse_prefs(&elem).unwrap();
let elem: Element = r#"
<prefs xmlns='urn:xmpp:mam:2' default='roster'>
<always/>
<never/>
</prefs>
"#.parse().unwrap();
mam::parse_prefs(&elem).unwrap();
}
#[test]
fn test_prefs_result() {
let elem: Element = r#"
<prefs xmlns='urn:xmpp:mam:2' default='roster'>
<always>
<jid>romeo@montague.lit</jid>
</always>
<never>
<jid>montague@montague.lit</jid>
</never>
</prefs>
"#.parse().unwrap();
mam::parse_prefs(&elem).unwrap();
}
#[test]
fn test_invalid_child() {
let elem: Element = "<query xmlns='urn:xmpp:mam:2'><coucou/></query>".parse().unwrap();
let error = mam::parse_query(&elem).unwrap_err(); let error = mam::parse_query(&elem).unwrap_err();
let message = match error { let message = match error {
Error::ParseError(string) => string, Error::ParseError(string) => string,
_ => panic!(), _ => panic!(),
}; };
assert_eq!(message, "No 'id' attribute present in replace."); assert_eq!(message, "Unknown child in query element.");
} }
#[test] #[test]
fn test_serialise() { fn test_serialise() {
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0' id='coucou'/>".parse().unwrap(); let elem: Element = "<query xmlns='urn:xmpp:mam:2'/>".parse().unwrap();
let replace = mam::Query { id: String::from("coucou") }; let replace = mam::Query { queryid: None, node: None, form: None, set: None };
let elem2 = mam::serialise(&replace); let elem2 = mam::serialise_query(&replace);
assert_eq!(elem, elem2); assert_eq!(elem, elem2);
} }
*/
} }