2017-06-26 22:07:12 +00:00
|
|
|
// Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net>
|
2017-07-20 19:36:13 +00:00
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
2017-06-26 22:07:12 +00:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2018-05-28 14:45:13 +00:00
|
|
|
generate_element!(
|
2018-05-28 14:29:51 +00:00
|
|
|
Muc, "x", MUC, children: [
|
|
|
|
password: Option<String> = ("password", MUC) => String
|
|
|
|
]
|
|
|
|
);
|
2017-06-26 22:07:12 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2018-05-28 14:29:51 +00:00
|
|
|
use try_from::TryFrom;
|
|
|
|
use minidom::Element;
|
|
|
|
use error::Error;
|
2018-05-28 14:24:17 +00:00
|
|
|
use compare_elements::NamespaceAwareCompare;
|
2017-06-26 22:07:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_muc_simple() {
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'/>".parse().unwrap();
|
|
|
|
Muc::try_from(elem).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_muc_invalid_child() {
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'><coucou/></x>".parse().unwrap();
|
|
|
|
let error = Muc::try_from(elem).unwrap_err();
|
|
|
|
let message = match error {
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
_ => panic!(),
|
|
|
|
};
|
|
|
|
assert_eq!(message, "Unknown child in x element.");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_muc_serialise() {
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'/>".parse().unwrap();
|
|
|
|
let muc = Muc {
|
|
|
|
password: None,
|
|
|
|
};
|
|
|
|
let elem2 = muc.into();
|
|
|
|
assert_eq!(elem, elem2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_muc_invalid_attribute() {
|
|
|
|
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc' coucou=''/>".parse().unwrap();
|
|
|
|
let error = Muc::try_from(elem).unwrap_err();
|
|
|
|
let message = match error {
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
_ => panic!(),
|
|
|
|
};
|
|
|
|
assert_eq!(message, "Unknown attribute in x element.");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_muc_simple_password() {
|
|
|
|
let elem: Element = "
|
|
|
|
<x xmlns='http://jabber.org/protocol/muc'>
|
|
|
|
<password>coucou</password>
|
|
|
|
</x>"
|
|
|
|
.parse().unwrap();
|
2018-05-28 14:24:17 +00:00
|
|
|
let elem1 = elem.clone();
|
2017-06-26 22:07:12 +00:00
|
|
|
let muc = Muc::try_from(elem).unwrap();
|
|
|
|
assert_eq!(muc.password, Some("coucou".to_owned()));
|
2018-05-28 14:24:17 +00:00
|
|
|
|
|
|
|
let elem2 = Element::from(muc);
|
|
|
|
assert!(elem1.compare_to(&elem2));
|
2017-06-26 22:07:12 +00:00
|
|
|
}
|
|
|
|
}
|