feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_CONFIG_FILE_H
#define TEST_CONFIG_FILE_H
#pragma once
#include "core/io/config_file.h"
#include "core/os/os.h"
@ -160,5 +159,3 @@ antiAliasing=false
"The saved configuration file should match the expected format.");
}
} // namespace TestConfigFile
#endif // TEST_CONFIG_FILE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_FILE_ACCESS_H
#define TEST_FILE_ACCESS_H
#pragma once
#include "core/io/file_access.h"
#include "tests/test_macros.h"
@ -197,8 +196,28 @@ TEST_CASE("[FileAccess] Get/Store floating point half precision values") {
DirAccess::remove_file_or_error(file_path_new);
}
SUBCASE("4096 bytes fastlz compressed") {
const String file_path = TestUtils::get_data_path("exactly_4096_bytes_fastlz.bin");
Ref<FileAccess> f = FileAccess::open_compressed(file_path, FileAccess::READ, FileAccess::COMPRESSION_FASTLZ);
const Vector<uint8_t> full_data = f->get_buffer(4096 * 2);
CHECK(full_data.size() == 4096);
CHECK(f->eof_reached());
// Data should be empty.
PackedByteArray reference;
reference.resize_zeroed(4096);
CHECK(reference == full_data);
f->seek(0);
const Vector<uint8_t> partial_data = f->get_buffer(4095);
CHECK(partial_data.size() == 4095);
CHECK(!f->eof_reached());
reference.resize_zeroed(4095);
CHECK(reference == partial_data);
}
}
} // namespace TestFileAccess
#endif // TEST_FILE_ACCESS_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_HTTP_CLIENT_H
#define TEST_HTTP_CLIENT_H
#pragma once
#include "core/io/http_client.h"
@ -59,10 +58,7 @@ TEST_CASE("[HTTPClient] query_string_from_dict") {
Dictionary dict2;
dict2["key1"] = "value";
dict2["key2"] = 123;
Array values;
values.push_back(1);
values.push_back(2);
values.push_back(3);
Array values = { 1, 2, 3 };
dict2["key3"] = values;
dict2["key4"] = Variant();
String multiple_keys = client->query_string_from_dict(dict2);
@ -106,5 +102,3 @@ TEST_CASE("[HTTPClient] connect_to_host") {
#endif // MODULE_MBEDTLS_ENABLED || WEB_ENABLED
} // namespace TestHTTPClient
#endif // TEST_HTTP_CLIENT_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_IMAGE_H
#define TEST_IMAGE_H
#pragma once
#include "core/io/image.h"
#include "core/os/os.h"
@ -444,5 +443,3 @@ TEST_CASE("[Image] Convert image") {
}
} // namespace TestImage
#endif // TEST_IMAGE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_IP_H
#define TEST_IP_H
#pragma once
#include "core/io/ip.h"
@ -47,5 +46,3 @@ TEST_CASE("[IP] resolve_hostname") {
}
} // namespace TestIP
#endif // TEST_IP_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_JSON_H
#define TEST_JSON_H
#pragma once
#include "core/io/json.h"
@ -153,21 +152,13 @@ TEST_CASE("[JSON] Parsing escape sequences") {
JSON json;
TypedArray<String> valid_escapes;
valid_escapes.push_back("\";\"");
valid_escapes.push_back("\\;\\");
valid_escapes.push_back("/;/");
valid_escapes.push_back("b;\b");
valid_escapes.push_back("f;\f");
valid_escapes.push_back("n;\n");
valid_escapes.push_back("r;\r");
valid_escapes.push_back("t;\t");
TypedArray<String> valid_escapes = { "\";\"", "\\;\\", "/;/", "b;\b", "f;\f", "n;\n", "r;\r", "t;\t" };
SUBCASE("Basic valid escape sequences") {
for (int i = 0; i < valid_escapes.size(); i++) {
String valid_escape = valid_escapes[i];
String valid_escape_string = valid_escape.get_slice(";", 0);
String valid_escape_value = valid_escape.get_slice(";", 1);
String valid_escape_string = valid_escape.get_slicec(';', 0);
String valid_escape_value = valid_escape.get_slicec(';', 1);
String json_string = "\"\\";
json_string += valid_escape_string;
@ -205,7 +196,7 @@ TEST_CASE("[JSON] Parsing escape sequences") {
bool skip = false;
for (int j = 0; j < valid_escapes.size(); j++) {
String valid_escape = valid_escapes[j];
String valid_escape_string = valid_escape.get_slice(";", 0);
String valid_escape_string = valid_escape.get_slicec(';', 0);
if (valid_escape_string[0] == i) {
skip = true;
break;
@ -318,5 +309,3 @@ TEST_CASE("[JSON] Serialization") {
}
}
} // namespace TestJSON
#endif // TEST_JSON_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_JSON_NATIVE_H
#define TEST_JSON_NATIVE_H
#pragma once
#include "core/io/json.h"
@ -162,25 +161,13 @@ TEST_CASE("[JSON][Native] Conversion between native and JSON formats") {
// `Array`.
Array arr;
arr.push_back(true);
arr.push_back(1);
arr.push_back("abc");
Array arr = { true, 1, "abc" };
test(arr, R"([true,"i:1","s:abc"])");
TypedArray<int64_t> int_arr;
int_arr.push_back(1);
int_arr.push_back(2);
int_arr.push_back(3);
TypedArray<int64_t> int_arr = { 1, 2, 3 };
test(int_arr, R"({"type":"Array","elem_type":"int","args":["i:1","i:2","i:3"]})");
Array arr2;
arr2.push_back(1);
arr2.push_back(res);
arr2.push_back(9);
Array arr2 = { 1, res, 9 };
const String arr2_repr = vformat(R"(["i:1",%s,"i:9"])", res_repr);
test(arr2, arr2_repr, true);
@ -189,9 +176,7 @@ TEST_CASE("[JSON][Native] Conversion between native and JSON formats") {
CHECK(decode(arr2_repr).get_construct_string() == "[1, null, 9]");
ERR_PRINT_ON;
TypedArray<Resource> res_arr;
res_arr.push_back(res);
TypedArray<Resource> res_arr = { res };
const String res_arr_repr = vformat(R"({"type":"Array","elem_type":"Resource","args":[%s]})", res_repr);
test(res_arr, res_arr_repr, true);
@ -223,5 +208,3 @@ TEST_CASE("[JSON][Native] Conversion between native and JSON formats") {
}
} // namespace TestJSONNative
#endif // TEST_JSON_NATIVE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_LOGGER_H
#define TEST_LOGGER_H
#pragma once
#include "core/io/dir_access.h"
#include "core/io/logger.h"
@ -166,5 +165,3 @@ TEST_CASE("[Logger][CompositeLogger] Logs the same into multiple loggers") {
}
} // namespace TestLogger
#endif // TEST_LOGGER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_MARSHALLS_H
#define TEST_MARSHALLS_H
#pragma once
#include "core/io/marshalls.h"
@ -491,5 +490,3 @@ TEST_CASE("[Marshalls] Typed dictionary decoding") {
}
} // namespace TestMarshalls
#endif // TEST_MARSHALLS_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_PACKET_PEER_H
#define TEST_PACKET_PEER_H
#pragma once
#include "core/io/packet_peer.h"
#include "tests/test_macros.h"
@ -200,5 +199,3 @@ TEST_CASE("[PacketPeer][PacketPeerStream] Put packet buffer when is empty") {
}
} // namespace TestPacketPeer
#endif // TEST_PACKET_PEER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_PCK_PACKER_H
#define TEST_PCK_PACKER_H
#pragma once
#include "core/io/file_access_pack.h"
#include "core/io/pck_packer.h"
@ -118,5 +117,3 @@ TEST_CASE("[PCKPacker] Pack a PCK file with some files and directories") {
"The generated non-empty PCK file shouldn't be too large.");
}
} // namespace TestPCKPacker
#endif // TEST_PCK_PACKER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_RESOURCE_H
#define TEST_RESOURCE_H
#pragma once
#include "core/io/resource.h"
#include "core/io/resource_loader.h"
@ -167,5 +166,3 @@ TEST_CASE("[Resource] Breaking circular references on save") {
resource_c->remove_meta("next");
}
} // namespace TestResource
#endif // TEST_RESOURCE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_RESOURCE_UID_H
#define TEST_RESOURCE_UID_H
#pragma once
#include "core/io/resource_uid.h"
@ -67,5 +66,3 @@ TEST_CASE("[ResourceUID] Must encode and decode various UIDs correctly") {
}
} // namespace TestResourceUID
#endif // TEST_RESOURCE_UID_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_STREAM_PEER_H
#define TEST_STREAM_PEER_H
#pragma once
#include "core/io/stream_peer.h"
#include "tests/test_macros.h"
@ -307,5 +306,3 @@ TEST_CASE("[StreamPeer] Get UTF8 string when there is no string") {
}
} // namespace TestStreamPeer
#endif // TEST_STREAM_PEER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_STREAM_PEER_BUFFER_H
#define TEST_STREAM_PEER_BUFFER_H
#pragma once
#include "core/io/stream_peer.h"
#include "tests/test_macros.h"
@ -181,5 +180,3 @@ TEST_CASE("[StreamPeerBuffer] Get data with invalid size returns an error") {
}
} // namespace TestStreamPeerBuffer
#endif // TEST_STREAM_PEER_BUFFER_H

View file

@ -0,0 +1,195 @@
/**************************************************************************/
/* test_stream_peer_gzip.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "core/io/stream_peer_gzip.h"
#include "tests/test_macros.h"
namespace TestStreamPeerGZIP {
const String hello = "Hello World!!!";
TEST_CASE("[StreamPeerGZIP] Initialization") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
CHECK_EQ(spgz->get_available_bytes(), 0);
}
TEST_CASE("[StreamPeerGZIP] Compress/Decompress") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
bool is_deflate = false;
SUBCASE("GZIP") {
is_deflate = false;
}
SUBCASE("DEFLATE") {
is_deflate = true;
}
CHECK_EQ(spgz->start_compression(is_deflate), Error::OK);
CHECK_EQ(spgz->put_data(hello.to_ascii_buffer().ptr(), hello.to_ascii_buffer().size()), Error::OK);
CHECK_EQ(spgz->finish(), Error::OK);
Vector<uint8_t> hello_compressed;
int hello_compressed_size = spgz->get_available_bytes();
hello_compressed.resize(hello_compressed_size);
CHECK_EQ(spgz->get_data(hello_compressed.ptrw(), hello_compressed_size), Error::OK);
spgz->clear();
CHECK_EQ(spgz->start_decompression(is_deflate), Error::OK);
CHECK_EQ(spgz->put_data(hello_compressed.ptr(), hello_compressed.size()), Error::OK);
Vector<uint8_t> hello_decompressed;
int hello_decompressed_size = spgz->get_available_bytes();
hello_decompressed.resize(hello_decompressed_size);
CHECK_EQ(spgz->get_data(hello_decompressed.ptrw(), hello_decompressed_size), Error::OK);
CHECK_EQ(hello_decompressed, hello.to_ascii_buffer());
}
TEST_CASE("[StreamPeerGZIP] Compress/Decompress big chunks of data") { // GH-97201
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
CHECK_EQ(spgz->start_compression(false), Error::OK);
Vector<uint8_t> big_data;
big_data.resize(2500);
// Filling it with random data because the issue is related to the size of the data when it's compress.
// Random data results in bigger compressed data size.
for (int i = 0; i < big_data.size(); i++) {
big_data.write[i] = Math::random(48, 122);
}
CHECK_EQ(spgz->put_data(big_data.ptr(), big_data.size()), Error::OK);
CHECK_EQ(spgz->finish(), Error::OK);
Vector<uint8_t> big_data_compressed;
int big_data_compressed_size = spgz->get_available_bytes();
big_data_compressed.resize(big_data_compressed_size);
CHECK_EQ(spgz->get_data(big_data_compressed.ptrw(), big_data_compressed_size), Error::OK);
spgz->clear();
CHECK_EQ(spgz->start_decompression(false), Error::OK);
CHECK_EQ(spgz->put_data(big_data_compressed.ptr(), big_data_compressed.size()), Error::OK);
Vector<uint8_t> big_data_decompressed;
int big_data_decompressed_size = spgz->get_available_bytes();
big_data_decompressed.resize(big_data_decompressed_size);
CHECK_EQ(spgz->get_data(big_data_decompressed.ptrw(), big_data_decompressed_size), Error::OK);
CHECK_EQ(big_data_decompressed, big_data);
}
TEST_CASE("[StreamPeerGZIP] Can't start twice") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
CHECK_EQ(spgz->start_compression(false), Error::OK);
ERR_PRINT_OFF;
CHECK_EQ(spgz->start_compression(false), Error::ERR_ALREADY_IN_USE);
CHECK_EQ(spgz->start_decompression(false), Error::ERR_ALREADY_IN_USE);
ERR_PRINT_ON;
}
TEST_CASE("[StreamPeerGZIP] Can't start with a buffer size equal or less than zero") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
ERR_PRINT_OFF;
CHECK_EQ(spgz->start_compression(false, 0), Error::ERR_INVALID_PARAMETER);
CHECK_EQ(spgz->start_compression(false, -1), Error::ERR_INVALID_PARAMETER);
CHECK_EQ(spgz->start_decompression(false, 0), Error::ERR_INVALID_PARAMETER);
CHECK_EQ(spgz->start_decompression(false, -1), Error::ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
TEST_CASE("[StreamPeerGZIP] Can't put/get data with a buffer size less than zero") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
CHECK_EQ(spgz->start_compression(false), Error::OK);
ERR_PRINT_OFF;
CHECK_EQ(spgz->put_data(hello.to_ascii_buffer().ptr(), -1), Error::ERR_INVALID_PARAMETER);
Vector<uint8_t> hello_compressed;
hello_compressed.resize(5);
CHECK_EQ(spgz->get_data(hello_compressed.ptrw(), -1), Error::ERR_INVALID_PARAMETER);
ERR_PRINT_ON;
}
TEST_CASE("[StreamPeerGZIP] Needs to be started before use") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
ERR_PRINT_OFF;
CHECK_EQ(spgz->put_data(hello.to_ascii_buffer().ptr(), hello.to_ascii_buffer().size()), Error::ERR_UNCONFIGURED);
ERR_PRINT_ON;
}
TEST_CASE("[StreamPeerGZIP] Can't be finished after clear or if it's decompressing") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
CHECK_EQ(spgz->start_compression(false), Error::OK);
spgz->clear();
ERR_PRINT_OFF;
CHECK_EQ(spgz->finish(), Error::ERR_UNAVAILABLE);
ERR_PRINT_ON;
spgz->clear();
CHECK_EQ(spgz->start_decompression(false), Error::OK);
ERR_PRINT_OFF;
CHECK_EQ(spgz->finish(), Error::ERR_UNAVAILABLE);
ERR_PRINT_ON;
}
TEST_CASE("[StreamPeerGZIP] Fails to get if nothing was compress/decompress") {
Ref<StreamPeerGZIP> spgz;
spgz.instantiate();
SUBCASE("Compression") {
CHECK_EQ(spgz->start_compression(false), Error::OK);
}
SUBCASE("Decompression") {
CHECK_EQ(spgz->start_decompression(false), Error::OK);
}
ERR_PRINT_OFF;
Vector<uint8_t> hello_compressed;
hello_compressed.resize(5);
CHECK_EQ(spgz->get_data(hello_compressed.ptrw(), hello_compressed.size()), Error::ERR_UNAVAILABLE);
ERR_PRINT_ON;
}
} // namespace TestStreamPeerGZIP

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_TCP_SERVER_H
#define TEST_TCP_SERVER_H
#pragma once
#include "core/io/stream_peer_tcp.h"
#include "core/io/tcp_server.h"
@ -251,5 +250,3 @@ TEST_CASE("[TCPServer] Should disconnect client") {
}
} // namespace TestTCPServer
#endif // TEST_TCP_SERVER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_UDP_SERVER_H
#define TEST_UDP_SERVER_H
#pragma once
#include "core/io/packet_peer_udp.h"
#include "core/io/udp_server.h"
@ -215,5 +214,3 @@ TEST_CASE("[UDPServer] Should not accept new connections after stop") {
}
} // namespace TestUDPServer
#endif // TEST_UDP_SERVER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_XML_PARSER_H
#define TEST_XML_PARSER_H
#pragma once
#include "core/io/xml_parser.h"
@ -231,5 +230,3 @@ TEST_CASE("[XMLParser] CDATA") {
CHECK_EQ(parser.get_node_name(), "a");
}
} // namespace TestXMLParser
#endif // TEST_XML_PARSER_H