2019-11-23 12:24:25 +01:00
|
|
|
import (
|
|
|
|
eventbus
|
|
|
|
)
|
|
|
|
|
2020-01-22 17:41:08 +01:00
|
|
|
struct EventData {
|
|
|
|
data string
|
|
|
|
}
|
|
|
|
|
2019-11-23 12:24:25 +01:00
|
|
|
fn test_eventbus(){
|
2020-01-22 17:41:08 +01:00
|
|
|
ev_data := &EventData{'hello'}
|
2019-11-23 12:24:25 +01:00
|
|
|
mut eb := eventbus.new()
|
|
|
|
eb.subscriber.subscribe_once("on_test", on_test)
|
2019-12-18 06:16:33 +01:00
|
|
|
|
|
|
|
assert eb.has_subscriber("on_test")
|
|
|
|
assert eb.subscriber.is_subscribed("on_test")
|
|
|
|
|
2020-01-22 17:41:08 +01:00
|
|
|
eb.publish("on_test", eb, ev_data)
|
2019-12-18 06:16:33 +01:00
|
|
|
|
|
|
|
assert !eb.has_subscriber("on_test")
|
|
|
|
assert !eb.subscriber.is_subscribed("on_test")
|
|
|
|
|
|
|
|
eb.subscriber.subscribe("on_test", on_test)
|
|
|
|
|
|
|
|
assert eb.has_subscriber("on_test")
|
|
|
|
assert eb.subscriber.is_subscribed("on_test")
|
|
|
|
|
2019-11-23 12:24:25 +01:00
|
|
|
eb.clear_all()
|
2019-12-18 06:16:33 +01:00
|
|
|
|
|
|
|
assert !eb.has_subscriber("on_test")
|
|
|
|
assert !eb.subscriber.is_subscribed("on_test")
|
2019-11-23 12:24:25 +01:00
|
|
|
}
|
|
|
|
|
2020-01-22 17:41:08 +01:00
|
|
|
fn on_test(sender voidptr, ev &EventData) {
|
|
|
|
assert ev.data == "hello"
|
|
|
|
}
|