Skip to content

Commit

Permalink
glib: Add signal accumulator to object test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjungkamp committed Nov 27, 2024
1 parent 62a1b82 commit 8ffa149
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions glib/src/subclass/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,19 @@ mod test {
.build(),
super::Signal::builder("create-string")
.return_type::<String>()
.accumulator(|_hint, acc, val| {
// join all strings from signal handlers by newline
let mut acc = acc
.get_owned::<Option<String>>()
.unwrap()
.map(|mut acc| {
acc.push('\n');
acc
})
.unwrap_or_default();
acc.push_str(val.get::<&str>().unwrap());
std::ops::ControlFlow::Continue(acc.to_value())
})
.build(),
super::Signal::builder("create-child-object")
.return_type::<super::ChildObject>()
Expand Down Expand Up @@ -891,13 +904,17 @@ mod test {
let obj = Object::with_type(SimpleObject::static_type());

obj.connect("create-string", false, move |_args| {
Some("return value".to_value())
Some("return value 1".to_value())
});

obj.connect("create-string", false, move |_args| {
Some("return value 2".to_value())
});

let signal_id = imp::SimpleObject::signals()[2].signal_id();

let value = obj.emit::<String>(signal_id, &[]);
assert_eq!(value, "return value");
assert_eq!(value, "return value 1\nreturn value 2");
}

#[test]
Expand Down

0 comments on commit 8ffa149

Please sign in to comment.