From 384b06281b6cbb3aff890f9f25a9b6618df8af39 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Mon, 2 Sep 2024 12:57:00 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=85=20zv:=20Testcase=20for=20parsed::?= =?UTF-8?q?Signature=20ser/de?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zvariant/src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/zvariant/src/lib.rs b/zvariant/src/lib.rs index ae364b138..9628f755d 100644 --- a/zvariant/src/lib.rs +++ b/zvariant/src/lib.rs @@ -591,6 +591,37 @@ mod tests { } } + #[test] + fn parsed_signature() { + use crate::parsed; + use std::str::FromStr; + + let sig = parsed::Signature::from_str("yys").unwrap(); + // parsed::Structure will always add () around the signature if it's a struct. + basic_type_test!(LE, DBus, sig, 7, parsed::Signature, 1); + + #[cfg(feature = "gvariant")] + { + let encoded = basic_type_test!(LE, GVariant, sig, 6, parsed::Signature, 1); + decode_with_gvariant::<_, String>(encoded, Some(String::from("yys"))); + } + + // As Value + let v: Value<'_> = sig.into(); + assert_eq!(v.value_signature(), "g"); + let encoded = value_test!(LE, DBus, v, 10); + let v = encoded.deserialize::>().unwrap().0; + assert_eq!(v, Value::Signature(Signature::try_from("yys").unwrap())); + + // GVariant format now + #[cfg(feature = "gvariant")] + { + let encoded = value_test!(LE, GVariant, v, 8); + let v = encoded.deserialize::>().unwrap().0; + assert_eq!(v, Value::Signature(Signature::try_from("yys").unwrap())); + } + } + #[test] fn object_path_value() { let o = ObjectPath::try_from("/hello/world").unwrap(); From 804af6f69257a1e45b6d41272fe55b52dad16954 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Mon, 2 Sep 2024 12:58:21 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20zv:=20impl=20Basic=20for=20pars?= =?UTF-8?q?ed::Signature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zvariant/src/parsed/signature.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zvariant/src/parsed/signature.rs b/zvariant/src/parsed/signature.rs index 4ce9c344a..3d6f24cbf 100644 --- a/zvariant/src/parsed/signature.rs +++ b/zvariant/src/parsed/signature.rs @@ -8,7 +8,7 @@ use std::{ str::FromStr, }; -use crate::{serialized::Format, Type}; +use crate::{serialized::Format, Basic, Type}; /// A D-Bus signature in parsed form. /// @@ -735,3 +735,8 @@ impl<'de> Deserialize<'de> for Signature { }) } } + +impl Basic for Signature { + const SIGNATURE_CHAR: char = 'g'; + const SIGNATURE_STR: &'static str = "g"; +} From 382811618a1b9690bda8b88ec7acf4117efd5d2b Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Mon, 2 Sep 2024 12:59:35 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20impl=20From?= =?UTF-8?q?=20for=20Value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zvariant/src/parsed/signature.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zvariant/src/parsed/signature.rs b/zvariant/src/parsed/signature.rs index 3d6f24cbf..64681b3c7 100644 --- a/zvariant/src/parsed/signature.rs +++ b/zvariant/src/parsed/signature.rs @@ -740,3 +740,9 @@ impl Basic for Signature { const SIGNATURE_CHAR: char = 'g'; const SIGNATURE_STR: &'static str = "g"; } + +impl From for crate::Value<'static> { + fn from(value: Signature) -> Self { + crate::Value::Signature(value.into()) + } +}