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-12-18 14:27:30 +00:00
|
|
|
use crate::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.
|
2018-12-18 14:32:05 +00:00
|
|
|
VersionQuery,
|
|
|
|
"query",
|
|
|
|
VERSION
|
2018-07-31 21:06:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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::*;
|
2019-09-25 08:28:44 +00:00
|
|
|
use crate::Element;
|
2019-04-12 08:58:42 +00:00
|
|
|
use std::convert::TryFrom;
|
2017-07-29 10:45:45 +00:00
|
|
|
|
2018-10-28 12:10:48 +00:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
#[test]
|
|
|
|
fn test_size() {
|
|
|
|
assert_size!(VersionQuery, 0);
|
|
|
|
assert_size!(VersionResult, 36);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2018-10-26 12:26:16 +00:00
|
|
|
#[test]
|
|
|
|
fn test_size() {
|
|
|
|
assert_size!(VersionQuery, 0);
|
|
|
|
assert_size!(VersionResult, 72);
|
|
|
|
}
|
|
|
|
|
2017-07-29 10:45:45 +00:00
|
|
|
#[test]
|
2018-07-31 22:44:27 +00:00
|
|
|
fn simple() {
|
2018-12-18 14:32:05 +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);
|
2018-12-18 14:32:05 +00:00
|
|
|
let elem2: Element =
|
|
|
|
"<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>"
|
|
|
|
.parse()
|
|
|
|
.unwrap();
|
2018-05-28 14:23:23 +00:00
|
|
|
println!("{:?}", elem1);
|
2019-11-29 13:33:17 +00:00
|
|
|
assert_eq!(elem1, elem2);
|
2018-05-28 14:23:23 +00:00
|
|
|
}
|
2017-07-29 10:45:45 +00:00
|
|
|
}
|