-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ae81cf
commit 113991c
Showing
7 changed files
with
197 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ jobs: | |
arch: x86_64 | ||
float-precision: 'single' | ||
build-target-type: ${{ matrix.target }} | ||
scons-flags: ${{ env.SCONSFLAGS }} ${{ matrix.cpp_compiler == 'llvm' && 'use_llvm=yes' || ''}} | ||
scons-flags: ${{ env.SCONSFLAGS }} ${{ matrix.cpp_compiler == 'llvm' && 'use_llvm=yes' || '' }} ${{ matrix.target == 'editor' && 'dev_build=yes' || '' }} | ||
|
||
- name: Save build cache | ||
uses: ./.github/actions/cache-save | ||
|
@@ -57,3 +57,13 @@ jobs: | |
arch: x86_64 | ||
float-precision: 'single' | ||
build-target-type: ${{ matrix.target }} | ||
|
||
- name: Test with GdUnit4 | ||
if: ${{ matrix.target == 'editor' }} | ||
uses: MikeSchulze/[email protected] | ||
with: | ||
godot-version: '4.3' | ||
version: 'v4.4.0' | ||
project_dir: '${{ github.workspace }}/demo/' | ||
paths: 'res://test' | ||
upload-report: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,8 @@ build | |
*.exp | ||
*.pdb | ||
*.ilk | ||
|
||
# TODO: DELETE | ||
# GdUnit4 | ||
/demo/addons/gdUnit4/ | ||
GdUnitRunner.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
class_name TestFSM | ||
extends GdUnitTestSuite | ||
|
||
var _fsm : FSM | ||
|
||
func before_test(): | ||
_fsm = FSM.new() | ||
|
||
func test_fsm_initialization(): | ||
# Check initial state of the FSM. | ||
assert_bool(_fsm.is_locked()).is_false() | ||
assert_bool(_fsm.is_running()).is_false() | ||
|
||
# Register a state. | ||
var state := FSMState.new() | ||
var state_name := "Start" | ||
_fsm.register_state(state_name, state) | ||
|
||
# Check if the state was registered. | ||
var registered_state = _fsm.get_state(state_name) | ||
assert_object(registered_state).is_equal(state) | ||
|
||
# Set the starting state. | ||
_fsm.set_starting_state(state_name) | ||
assert_str(_fsm.get_starting_state_name()).is_equal(state_name) | ||
assert_object(_fsm.get_starting_state()).is_equal(state) | ||
|
||
func test_fsm_cannot_lock(): | ||
_fsm.lock() | ||
# FSM cannot be locked if a starting state has not been set. | ||
assert_bool(_fsm.is_locked()).is_false() | ||
|
||
func test_fsm_cannot_start(): | ||
_fsm.start() | ||
# FSM cannot be started if it is not locked. | ||
assert_bool(_fsm.is_running()).is_false() | ||
|
||
func test_fsm_locked_behaviour(): | ||
var start_state := FSMState.new() | ||
var start_state_name := "Start" | ||
_fsm.register_state(start_state_name, start_state) | ||
_fsm.set_starting_state(start_state_name) | ||
|
||
var new_state := FSMState.new() | ||
var new_state_name := "New state" | ||
_fsm.register_state(new_state_name, new_state) | ||
|
||
var start_to_new_event := "Start to New" | ||
_fsm.add_transition(start_state_name, start_to_new_event, new_state_name) | ||
|
||
_fsm.lock() | ||
assert_bool(_fsm.is_locked()).is_true() | ||
|
||
# States cannot be registered while the FSM is locked. | ||
var another_state := FSMState.new() | ||
var another_state_name := "Another State" | ||
_fsm.register_state(another_state_name, another_state) | ||
assert_object(_fsm.get_state(another_state_name)).is_null() | ||
|
||
# Running behaviour. | ||
|
||
_fsm.start() | ||
assert_bool(_fsm.is_running()).is_true() | ||
assert_str(_fsm.get_current_state_name()).is_equal(start_state_name) | ||
assert_object(_fsm.get_current_state()).is_equal(start_state) | ||
|
||
# Change state through an event. | ||
_fsm.process_event(start_to_new_event) | ||
assert_str(_fsm.get_current_state_name()).is_equal(new_state_name) | ||
assert_object(_fsm.get_current_state()).is_equal(new_state) | ||
|
||
# Change state manually. | ||
_fsm.change_state(start_state_name) | ||
assert_str(_fsm.get_current_state_name()).is_equal(start_state_name) | ||
assert_object(_fsm.get_current_state()).is_equal(start_state) | ||
|
||
_fsm.pause() | ||
assert_bool(_fsm.is_running()).is_false() | ||
|
||
_fsm.play() | ||
assert_bool(_fsm.is_running()).is_true() | ||
|
||
_fsm.stop() | ||
assert_bool(_fsm.is_running()).is_false() | ||
assert_str(_fsm.get_current_state_name()).is_empty() | ||
assert_object(_fsm.get_current_state()).is_null() | ||
|
||
_fsm.start() | ||
assert_bool(_fsm.is_running()).is_true() | ||
|
||
_fsm.reset() | ||
assert_bool(_fsm.is_running()).is_false() | ||
assert_str(_fsm.get_current_state_name()).is_empty() | ||
assert_object(_fsm.get_current_state()).is_null() | ||
|
||
_fsm.unlock() | ||
assert_bool(_fsm.is_locked()).is_false() | ||
|
||
func after_test(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class_name TestState | ||
extends GdUnitTestSuite | ||
|
||
var _state : FSMState | ||
|
||
var _entered := false | ||
var _processed := false | ||
var _exited := false | ||
|
||
func before_test(): | ||
_state = FSMState.new() | ||
|
||
func test_state_construction(): | ||
assert_int(_state.on_enter.get_connections().size()).is_equal(0) | ||
assert_int(_state.on_process.get_connections().size()).is_equal(0) | ||
assert_int(_state.on_exit.get_connections().size()).is_equal(0) | ||
|
||
# Add callbacks. | ||
_state.on_enter.connect(_set_entered_true) | ||
_state.on_process.connect(_set_processed_true) | ||
_state.on_exit.connect(_set_exited_true) | ||
|
||
assert_int(_state.on_enter.get_connections().size()).is_equal(1) | ||
assert_int(_state.on_process.get_connections().size()).is_equal(1) | ||
assert_int(_state.on_exit.get_connections().size()).is_equal(1) | ||
|
||
# Call callbacks. | ||
_state.on_enter.emit() | ||
_state.on_process.emit() | ||
_state.on_exit.emit() | ||
|
||
assert_bool(_entered).is_true() | ||
assert_bool(_processed).is_true() | ||
assert_bool(_exited).is_true() | ||
|
||
# Remove callbacks. | ||
_state.on_enter.disconnect(_set_entered_true) | ||
_state.on_process.disconnect(_set_processed_true) | ||
_state.on_exit.disconnect(_set_exited_true) | ||
|
||
assert_int(_state.on_enter.get_connections().size()).is_equal(0) | ||
assert_int(_state.on_process.get_connections().size()).is_equal(0) | ||
assert_int(_state.on_exit.get_connections().size()).is_equal(0) | ||
|
||
func after_test(): | ||
pass | ||
|
||
func _set_entered_true(): | ||
_entered = true | ||
|
||
func _set_processed_true(): | ||
_processed = true | ||
|
||
func _set_exited_true(): | ||
_exited = true |