minidom, tokio-xmpp: switch xml parsing to rxml
This commit is contained in:
parent
3901068717
commit
d4a5a8247b
33 changed files with 465 additions and 811 deletions
|
|
@ -163,8 +163,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn history() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'>
|
||||
<history maxstanzas='0'/>
|
||||
</x>"
|
||||
.parse()
|
||||
|
|
@ -179,8 +178,7 @@ mod tests {
|
|||
assert_eq!(history.seconds, None);
|
||||
assert_eq!(history.since, None);
|
||||
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'>
|
||||
<history since='1970-01-01T00:00:00Z'/>
|
||||
</x>"
|
||||
.parse()
|
||||
|
|
|
|||
|
|
@ -239,25 +239,21 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
MucUser::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn statuses_and_items() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<status code='101'/>
|
||||
<status code='102'/>
|
||||
<item affiliation='member' role='moderator'/>
|
||||
</x>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</x>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let muc_user = MucUser::try_from(elem).unwrap();
|
||||
assert_eq!(muc_user.status.len(), 2);
|
||||
assert_eq!(muc_user.status[0], Status::AffiliationChange);
|
||||
|
|
@ -269,13 +265,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_invalid_child() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<coucou/>
|
||||
</x>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</x>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = MucUser::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -286,11 +280,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_serialise() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let muc = MucUser {
|
||||
status: vec![],
|
||||
items: vec![],
|
||||
|
|
@ -302,11 +294,9 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_invalid_attribute() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user' coucou=''/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user' coucou=''/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = MucUser::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -317,21 +307,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_simple() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Status::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_invalid() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -343,13 +329,11 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_status_invalid_child() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='110'>
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'>
|
||||
<foo/>
|
||||
</status>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</status>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -360,22 +344,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_simple_code() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='307'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='307'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let status = Status::try_from(elem).unwrap();
|
||||
assert_eq!(status, Status::Kicked);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_invalid_code() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='666'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='666'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -386,11 +366,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_invalid_code2() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='coucou'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='coucou'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let error = match error {
|
||||
Error::ParseIntError(error) => error,
|
||||
|
|
@ -401,11 +379,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_required_attributes() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Actor::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -416,13 +392,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_required_attributes2() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'
|
||||
nick='baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
nick='baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Actor::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -433,12 +407,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_jid() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let actor = Actor::try_from(elem).unwrap();
|
||||
let jid = match actor {
|
||||
Actor::Jid(jid) => jid,
|
||||
|
|
@ -449,11 +421,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_nick() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user' nick='baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user' nick='baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let actor = Actor::try_from(elem).unwrap();
|
||||
let nick = match actor {
|
||||
Actor::Nick(nick) => nick,
|
||||
|
|
@ -464,35 +434,29 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_continue_simple() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Continue::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continue_thread_attribute() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'
|
||||
thread='foo'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'
|
||||
thread='foo'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let continue_ = Continue::try_from(elem).unwrap();
|
||||
assert_eq!(continue_.thread, Some("foo".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continue_invalid() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<foobar/>
|
||||
</continue>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</continue>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let continue_ = Continue::try_from(elem).unwrap_err();
|
||||
let message = match continue_ {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -503,8 +467,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reason_simple() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user'>Reason</reason>"
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>Reason</reason>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2 = elem.clone();
|
||||
|
|
@ -518,11 +481,9 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_reason_invalid_attribute() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user' foo='bar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user' foo='bar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Reason::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -534,13 +495,11 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_reason_invalid() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<foobar/>
|
||||
</reason>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</reason>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Reason::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -552,12 +511,10 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_item_invalid_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
foo='bar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
foo='bar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -568,24 +525,20 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
role='moderator'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Item::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_invalid_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -596,14 +549,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_nick_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'
|
||||
nick='foobar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
nick='foobar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { nick, .. } => assert_eq!(nick, Some("foobar".to_owned())),
|
||||
|
|
@ -612,12 +563,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_invalid_attr2() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
role='moderator'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
role='moderator'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -631,15 +580,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_actor_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<actor nick='foobar'/>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { actor, .. } => assert_eq!(actor, Some(Actor::Nick("foobar".to_owned()))),
|
||||
|
|
@ -648,15 +595,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_continue_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<continue thread='foobar'/>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
let continue_1 = Continue {
|
||||
thread: Some("foobar".to_owned()),
|
||||
|
|
@ -672,15 +617,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_reason_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<reason>foobar</reason>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { reason, .. } => assert_eq!(reason, Some(Reason("foobar".to_owned()))),
|
||||
|
|
|
|||
Loading…
Reference in a new issue