2017-07-29 10:45:45 +00:00
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
//
|
|
|
|
// 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-16 13:08:17 +00:00
|
|
|
use iq::{IqGetPayload, IqResultPayload};
|
2017-07-29 10:45:45 +00:00
|
|
|
|
2018-07-31 21:06:49 +00:00
|
|
|
generate_empty_element!(
|
|
|
|
/// Represents a query for the software version a remote entity is using.
|
|
|
|
///
|
|
|
|
/// It should only be used in an `<iq type='get'/>`, as it can only
|
|
|
|
/// represent the request, and not a result.
|
|
|
|
VersionQuery, "query", VERSION
|
|
|
|
);
|
|
|
|
|
|
|
|
impl IqGetPayload for VersionQuery {}
|
|
|
|
|
2018-05-28 14:45:13 +00:00
|
|
|
generate_element!(
|
2018-07-31 21:06:49 +00:00
|
|
|
/// Represents the answer about the software version we are using.
|
|
|
|
///
|
|
|
|
/// It should only be used in an `<iq type='result'/>`, as it can only
|
|
|
|
/// represent the result, and not a request.
|
|
|
|
VersionResult, "query", VERSION,
|
2018-05-28 14:29:51 +00:00
|
|
|
children: [
|
2018-07-31 21:06:49 +00:00
|
|
|
/// The name of this client.
|
2018-05-28 14:29:51 +00:00
|
|
|
name: Required<String> = ("name", VERSION) => String,
|
2018-07-31 21:06:49 +00:00
|
|
|
|
|
|
|
/// The version of this client.
|
2018-05-28 14:29:51 +00:00
|
|
|
version: Required<String> = ("version", VERSION) => String,
|
2018-07-31 21:06:49 +00:00
|
|
|
|
|
|
|
/// The OS this client is running on.
|
2018-05-28 14:29:51 +00:00
|
|
|
os: Option<String> = ("os", VERSION) => String
|
|
|
|
]
|
|
|
|
);
|
2017-07-29 10:45:45 +00:00
|
|
|
|
2018-07-31 21:06:49 +00:00
|
|
|
impl IqResultPayload for VersionResult {}
|
2018-05-16 13:08:17 +00:00
|
|
|
|
2017-07-29 10:45:45 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2018-05-28 14:29:51 +00:00
|
|
|
use try_from::TryFrom;
|
|
|
|
use minidom::Element;
|
2018-05-28 14:23:23 +00:00
|
|
|
use compare_elements::NamespaceAwareCompare;
|
2017-07-29 10:45:45 +00:00
|
|
|
|
|
|
|
#[test]
|
2018-07-31 22:44:27 +00:00
|
|
|
fn simple() {
|
2017-07-29 10:45:45 +00:00
|
|
|
let elem: Element = "<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>".parse().unwrap();
|
2018-07-31 22:44:27 +00:00
|
|
|
let version = VersionResult::try_from(elem).unwrap();
|
2017-07-29 10:45:45 +00:00
|
|
|
assert_eq!(version.name, String::from("xmpp-rs"));
|
|
|
|
assert_eq!(version.version, String::from("0.3.0"));
|
|
|
|
assert_eq!(version.os, None);
|
|
|
|
}
|
2018-05-28 14:23:23 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn serialisation() {
|
2018-07-31 22:44:27 +00:00
|
|
|
let version = VersionResult {
|
2018-05-28 14:23:23 +00:00
|
|
|
name: String::from("xmpp-rs"),
|
|
|
|
version: String::from("0.3.0"),
|
|
|
|
os: None,
|
|
|
|
};
|
|
|
|
let elem1 = Element::from(version);
|
|
|
|
let elem2: Element = "<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>".parse().unwrap();
|
|
|
|
println!("{:?}", elem1);
|
|
|
|
assert!(elem1.compare_to(&elem2));
|
|
|
|
}
|
2017-07-29 10:45:45 +00:00
|
|
|
}
|