Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3cf92cf authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Fix PropMap conversion from RefArg

A PropMap is a D-Bus dictionary so it's expected that the data already
contains Variant wrapping each value in the key/value pairs. The bug was
that we tried to wrongly wrap that Variant with another Variant wrapper.

Bug: 217273154
Tag: #floss
Test: Manual - unit test and chrome vs floss test

Change-Id: I536d0c90b8b8800a0b0cae4d0ea3471ef0f6f765
parent 7bb4b030
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -962,7 +962,16 @@ pub fn generate_dbus_arg(_item: TokenStream) -> TokenStream {
                let mut val = iter.next();
                while !key.is_none() && !val.is_none() {
                    let k = key.unwrap().as_str().unwrap().to_string();
                    let v = dbus::arg::Variant(val.unwrap().box_clone());
                    let val_clone = val.unwrap().box_clone();
                    let v = dbus::arg::Variant(
                        val_clone
                            .as_static_inner(0)
                            .ok_or(Box::new(DBusArgError::new(String::from(format!(
                                "{}.{} is not a variant",
                                name, k
                            )))))?
                            .box_clone(),
                    );
                    map.insert(k, v);
                    key = iter.next();
                    val = iter.next();
+20 −16
Original line number Diff line number Diff line
@@ -99,32 +99,36 @@ mod tests {
        assert_eq!("Some Variable is not iterable", result.unwrap_err().to_string());
    }

    fn wrap_variant<T: 'static + dbus::arg::RefArg>(data: T) -> Box<dyn RefArg> {
        Box::new(dbus::arg::Variant(data))
    }

    #[test]
    fn test_dbus_propmap_success() {
        let data_dbus = FakeDictionary {
            items: vec![
                (String::from("name"), Box::new(String::from("foo"))),
                (String::from("number"), Box::new(100)),
                (String::from("name"), wrap_variant(String::from("foo"))),
                (String::from("number"), wrap_variant(100)),
                (
                    String::from("other_struct"),
                    Box::new(FakeDictionary {
                    wrap_variant(FakeDictionary {
                        items: vec![(
                            String::from("address"),
                            Box::new(String::from("aa:bb:cc:dd:ee:ff")),
                            wrap_variant(String::from("aa:bb:cc:dd:ee:ff")),
                        )],
                    }),
                ),
                (String::from("bytes"), Box::new(vec![1 as u8, 2, 3])),
                (String::from("bytes"), wrap_variant(vec![1 as u8, 2, 3])),
                (
                    String::from("dict"),
                    Box::new(HashMap::from([
                    wrap_variant(HashMap::from([
                        (String::from("key-0"), Box::new(vec![5, 6, 7, 8])),
                        (String::from("key-1"), Box::new(vec![-5, -6, -7, -8])),
                    ])),
                ),
                (
                    String::from("nested"),
                    Box::new(vec![
                    wrap_variant(vec![
                        vec![
                            String::from("string a"),
                            String::from("string b"),
@@ -135,29 +139,29 @@ mod tests {
                ),
                (
                    String::from("recursive"),
                    Box::new(vec![FakeDictionary {
                    wrap_variant(vec![FakeDictionary {
                        items: vec![
                            (String::from("name"), Box::new(String::from("bar"))),
                            (String::from("number"), Box::new(200)),
                            (String::from("name"), wrap_variant(String::from("bar"))),
                            (String::from("number"), wrap_variant(200)),
                            (
                                String::from("other_struct"),
                                Box::new(FakeDictionary {
                                wrap_variant(FakeDictionary {
                                    items: vec![(
                                        String::from("address"),
                                        Box::new(String::from("xx")),
                                        wrap_variant(String::from("xx")),
                                    )],
                                }),
                            ),
                            (String::from("bytes"), Box::new(Vec::<u8>::new())),
                            (String::from("bytes"), wrap_variant(Vec::<u8>::new())),
                            (
                                String::from("dict"),
                                Box::new(HashMap::from([
                                wrap_variant(HashMap::from([
                                    (String::from("key-2"), Box::new(vec![5, 5, 6, 8, 8])),
                                    (String::from("key-3"), Box::new(vec![])),
                                ])),
                            ),
                            (String::from("nested"), Box::new(Vec::<Vec<u8>>::new())),
                            (String::from("recursive"), Box::new(Vec::<FakeDictionary>::new())),
                            (String::from("nested"), wrap_variant(Vec::<Vec<u8>>::new())),
                            (String::from("recursive"), wrap_variant(Vec::<FakeDictionary>::new())),
                        ],
                    }]),
                ),