Skip to content

Commit 459ec69

Browse files
authored
Merge pull request #9911 from Geometror/unit-testing-signalwatcher-section
Document testing signals
2 parents ea97a4d + fccf532 commit 459ec69

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

contributing/development/core_and_modules/unit_testing.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,48 @@ These tags can be added to the test case name to modify or extend the test envir
285285

286286
You can use them together to combine multiple test environment extensions.
287287

288+
Testing signals
289+
~~~~~~~~~~~~~~~
290+
291+
The following macros can be use to test signals:
292+
293+
.. list-table::
294+
:header-rows: 1
295+
:widths: auto
296+
297+
* - Macro
298+
- Description
299+
* - ``SIGNAL_WATCH(object, "signal_name")``
300+
- Starts watching the specified signal on the given object.
301+
* - ``SIGNAL_UNWATCH(object, "signal_name")``
302+
- Stops watching the specified signal on the given object.
303+
* - ``SIGNAL_CHECK("signal_name", Vector<Vector<Variant>>)``
304+
- Checks the arguments of all fired signals. The outer vector contains each fired signal, while the inner vector contains the list of arguments for that signal. The order of signals is significant.
305+
* - ``SIGNAL_CHECK_FALSE("signal_name")``
306+
- Checks if the specified signal was not fired.
307+
* - ``SIGNAL_DISCARD("signal_name")``
308+
- Discards all records of the specified signal.
309+
310+
Below is an example demonstrating the use of these macros:
311+
312+
.. code-block:: cpp
313+
314+
//...
315+
SUBCASE("[Timer] Timer process timeout signal must be emitted") {
316+
SIGNAL_WATCH(test_timer, SNAME("timeout"));
317+
test_timer->start(0.1);
318+
319+
SceneTree::get_singleton()->process(0.2);
320+
321+
Array signal_args;
322+
signal_args.push_back(Array());
323+
324+
SIGNAL_CHECK(SNAME("timeout"), signal_args);
325+
326+
SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
327+
}
328+
//...
329+
288330
Test tools
289331
----------
290332

0 commit comments

Comments
 (0)