diff --git a/dist/submodules/besseretests b/dist/submodules/besseretests index a58bfb2..7b9c84b 160000 --- a/dist/submodules/besseretests +++ b/dist/submodules/besseretests @@ -1 +1 @@ -Subproject commit a58bfb23dc389ec60e3f45fbb0433e107755c4ea +Subproject commit 7b9c84b805e286b7989534bcba6e5b45badc0e52 diff --git a/tests/unit/storage.gd b/tests/unit/storage.gd new file mode 100644 index 0000000..428f290 --- /dev/null +++ b/tests/unit/storage.gd @@ -0,0 +1,67 @@ +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)