TinyAdventure/tests/scenes/game_tests.gd

34 lines
1.2 KiB
GDScript
Raw Permalink Normal View History

# GdUnit generated TestSuite
class_name GameTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://scenes/game.gd'
var game_scene:PackedScene = preload("res://scenes/game.tscn")
2024-12-01 21:57:39 +01:00
var _unittest_game_profile_path:String = "user://unittest/game_tests/"
func test_save_game() -> void:
2024-12-01 21:57:39 +01:00
# Output folder must exist
DirAccess.make_dir_recursive_absolute(_unittest_game_profile_path)
# Create game
var game:Game = game_scene.instantiate()
add_child(game)
2024-12-01 21:57:39 +01:00
# Build stuff
var floor_resource = load("res://data/structures/floor.tres")
game.build_system.build_structure(floor_resource, Transform3D.IDENTITY)
game.build_system.build_structure(floor_resource, Transform3D.IDENTITY.translated(Vector3(1, 0, 0)))
2024-12-01 21:57:39 +01:00
# Save
game.save_game(_unittest_game_profile_path)
2024-12-01 21:57:39 +01:00
# Load and check whether the built stuff can be found.
var save_data:SaveGameResource = load(_unittest_game_profile_path + "/savegame.tres") as SaveGameResource
assert_that(len(save_data.built_structures.keys())).is_equal(1)
assert_that(save_data.built_structures.has(floor_resource)).is_equal(true)
assert_that(len(save_data.built_structures[floor_resource])).is_equal(2)