@@ -384,6 +384,7 @@ pub mod custom_callable {
384
384
use super :: * ;
385
385
use crate :: framework:: { assert_eq_self, quick_thread, ThreadCrosser } ;
386
386
use godot:: builtin:: { Dictionary , RustCallable } ;
387
+ use godot:: prelude:: Signal ;
387
388
use godot:: sys;
388
389
use godot:: sys:: GdextBuild ;
389
390
use std:: fmt;
@@ -613,6 +614,41 @@ pub mod custom_callable {
613
614
assert_eq ! ( 1 , received. load( Ordering :: SeqCst ) ) ;
614
615
}
615
616
617
+ #[ itest]
618
+ fn callable_is_connected ( ) {
619
+ let tracker = Tracker :: new ( ) ;
620
+ let tracker2 = Tracker :: new ( ) ;
621
+
622
+ // Adder hash depends on its sum.
623
+ let some_callable = Callable :: from_custom ( Adder :: new_tracked ( 3 , tracker) ) ;
624
+ let identical_callable = Callable :: from_custom ( Adder :: new_tracked ( 3 , tracker2) ) ;
625
+
626
+ let obj = RefCounted :: new_gd ( ) ;
627
+ let signal = Signal :: from_object_signal ( & obj, "script_changed" ) ;
628
+ signal. connect ( & some_callable, 0 ) ;
629
+
630
+ // Given Custom Callable is connected to signal
631
+ // if callable with the very same hash is already connected.
632
+ assert ! ( signal. is_connected( & some_callable) ) ;
633
+ assert ! ( signal. is_connected( & identical_callable) ) ;
634
+
635
+ let change = [ 2 . to_variant ( ) ] ;
636
+
637
+ // Change the hash.
638
+ signal. emit ( & change) ;
639
+
640
+ // The hash, dependent on `Adder.sum` has been changed.
641
+ // `identical_callable` is considered NOT connected.
642
+ assert ! ( signal. is_connected( & some_callable) ) ;
643
+ assert ! ( !signal. is_connected( & identical_callable) ) ;
644
+
645
+ identical_callable. call ( & change) ;
646
+
647
+ // The hashes are, once again, identical.
648
+ assert ! ( signal. is_connected( & some_callable) ) ;
649
+ assert ! ( signal. is_connected( & identical_callable) ) ;
650
+ }
651
+
616
652
// ------------------------------------------------------------------------------------------------------------------------------------------
617
653
// Helper structs and functions for custom callables
618
654
0 commit comments