Skip to content

Commit 8ffa149

Browse files
committed
glib: Add signal accumulator to object test
1 parent 62a1b82 commit 8ffa149

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

glib/src/subclass/object.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,19 @@ mod test {
422422
.build(),
423423
super::Signal::builder("create-string")
424424
.return_type::<String>()
425+
.accumulator(|_hint, acc, val| {
426+
// join all strings from signal handlers by newline
427+
let mut acc = acc
428+
.get_owned::<Option<String>>()
429+
.unwrap()
430+
.map(|mut acc| {
431+
acc.push('\n');
432+
acc
433+
})
434+
.unwrap_or_default();
435+
acc.push_str(val.get::<&str>().unwrap());
436+
std::ops::ControlFlow::Continue(acc.to_value())
437+
})
425438
.build(),
426439
super::Signal::builder("create-child-object")
427440
.return_type::<super::ChildObject>()
@@ -891,13 +904,17 @@ mod test {
891904
let obj = Object::with_type(SimpleObject::static_type());
892905

893906
obj.connect("create-string", false, move |_args| {
894-
Some("return value".to_value())
907+
Some("return value 1".to_value())
908+
});
909+
910+
obj.connect("create-string", false, move |_args| {
911+
Some("return value 2".to_value())
895912
});
896913

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

899916
let value = obj.emit::<String>(signal_id, &[]);
900-
assert_eq!(value, "return value");
917+
assert_eq!(value, "return value 1\nreturn value 2");
901918
}
902919

903920
#[test]

0 commit comments

Comments
 (0)