CORE/tests/unit/storage.gd

68 lines
1.9 KiB
GDScript3
Raw Normal View History

extends 'res://tests/unitbase.gd'
var path: String = "user://testconfig.json"
func before_each() -> void:
remove_storagefile()
super()
func test_basic() -> void:
await load_framework()
if !core.storage.open_storage(path):
rerror("open_storage(location='" + path + "') returned 'false'")
return
if !core.storage.set_key("is_test", "yes it is"):
rerror("set_key(key='is_test' value='yes it is') returned 'false'")
return
if core.storage.get_key("is_test") != "yes it is":
rerror("get_key(key='is_test') did not return 'yes it is' (got '" + str(core.storage.get_key("is_test")) + "')")
return
if !core.storage.del_key("is_test"):
rerror("del_key(key='is_test') did not return 'true'")
return
if !core.storage.close_storage():
rerror("close_storage() did not return 'true'")
return
rok()
func test_advanced() -> void:
await load_framework()
if !core.storage.open_storage(path):
rerror("open_storage(location='" + path + "') returned 'false'")
return
if !core.storage.set_key("is_test", "yes it is", false, false):
rerror("set_key(key='is_test' value='yes it is') returned 'false'")
return
if core.storage.get_key("is_test") != "yes it is":
rerror("get_key(key='is_test') did not return 'yes it is' (got '" + str(core.storage.get_key("is_test")) + "')")
return
if !core.storage.save_storage():
rerror("save_storage() did not return 'true'")
return
if core.storage.get_dict() != { "is_test": "yes it is" }:
rerror("get_dict() did not return '{ \"is_test\": \"yes it is\" }' (got '" + str(core.storage.get_dict()) + "')")
return
if !core.storage.nuke_storage():
rerror("nuke_storage() did not return 'true'")
return
if !core.storage.close_storage():
rerror("close_storage() did not return 'true'")
return
rok()
func remove_storagefile() -> void:
if FileAccess.file_exists(path):
lverb("Removing '" + path + "'")
DirAccess.remove_absolute(path)