From 1c528da96f4765e08aa9defec2989ddc05aec1c4 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 6 Apr 2024 14:00:44 +0200 Subject: [PATCH] Add erm module test --- tests/unit/erm.gd | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/unit/erm.gd diff --git a/tests/unit/erm.gd b/tests/unit/erm.gd new file mode 100644 index 0000000..f5866d2 --- /dev/null +++ b/tests/unit/erm.gd @@ -0,0 +1,103 @@ +extends 'res://tests/unitbase.gd' + +var url_base: String = "https://fs.staropensource.de/test/core/erm-" +var url_text: String = url_base + "text" +var url_binary: String = url_base + "binary" + +var correct_text: String = "Hi! This file is used in tests verifying that CORE's built-in 'erm' module works.\n" +var correct_text_binary: PackedByteArray = [] +var correct_binary: PackedByteArray = [31, 139, 8, 8, 41, 47, 17, 102, 0, 3, 101, 114, 109, 45, 98, 105, 110, 97, 114, 121, 0, 83, 14, 41, 74, 204, 43, 14, 202, 76, 207, 40, 41, 118, 44, 74, 245, 40, 205, 77, 204, 131, 240, 184, 0, 158, 102, 174, 206, 27, 0, 0, 0] + +func test_awaited_request_text() -> void: + await load_framework() + + # Get download data + var dldata: Dictionary = await core.erm.awaited_request(url_text, true) + + # Skip test if request failed + if dldata["result"] != 0: + rskip("Godot returned '" + error_string(dldata["result"]) + "'") + return + if dldata["http_code"] != 200: + rskip("Server returned '" + str(dldata["http_code"]) + "'") + return + + # Check content + if dldata["body_utf8"] != correct_text: + lerror("Got this INVALID UTF-8 body data: " + str(dldata["body_utf8"]).replace("\n", "\\n")) + rerror("Got invalid UTF-8 body data (check logs)") + return + + rok() + +func test_awaited_request_binary() -> void: + await load_framework() + + # Get download data + var dldata: Dictionary = await core.erm.awaited_request(url_binary, false) + + # Skip test if request failed + if dldata["result"] != 0: + rskip("Godot returned '" + error_string(dldata["result"]) + "'") + return + if dldata["http_code"] != 200: + rskip("Server returned '" + str(dldata["http_code"]) + "'") + return + + # Check content + if dldata["body"] != correct_binary: + lerror("Got this INVALID binary body data: " + str(dldata["body"])) + rerror("Got invalid binary body data (check logs)") + return + + rok() + +func test_oneline_awaited_request_text() -> void: + await load_framework() + + # Get download data + var dldata: Variant = await core.erm.oneline_awaited_request(url_text, true) + + # Check failure + if dldata == null: + rskip("dldata is 'null', request probably failed") + return + + # Check type + if typeof(dldata) != TYPE_STRING: + rerror("dldata is not of type String") + return + + # Check content + if dldata != correct_text: + lerror("Got this INVALID UTF-8 body data: " + str(dldata).replace("\n", "\\n")) + rerror("Got invalid UTF-8 body data (check logs)") + return + + rok() + +func test_oneline_awaited_request_binary() -> void: + await load_framework() + + # Get download data + var dldata: Variant = await core.erm.oneline_awaited_request(url_binary, false) + + # Check failure + if dldata == null: + rskip("dldata is 'null', request probably failed") + return + + # Check type + if typeof(dldata) != TYPE_PACKED_BYTE_ARRAY: + rerror("dldata is not of type PackedByteArray") + return + + # Check content + if dldata != correct_binary: + lerror("Got this INVALID binary body data: " + str(dldata)) + rerror("Got invalid binary body data (check logs)") + return + + rok() + +func test_batch_awaited_request() -> void: rskip("TODO")