summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/translations.csv5
-rw-r--r--tests/test_class_db.h62
-rw-r--r--tests/test_file_access.h29
-rw-r--r--tests/test_gui.cpp2
-rw-r--r--tests/test_math.cpp8
-rw-r--r--tests/test_object.h8
-rw-r--r--tests/test_physics_2d.cpp2
-rw-r--r--tests/test_physics_3d.cpp4
-rw-r--r--tests/test_render.cpp14
-rw-r--r--tests/test_text_server.h10
10 files changed, 83 insertions, 61 deletions
diff --git a/tests/data/translations.csv b/tests/data/translations.csv
index 4c9ad4996a..8cb7b800c5 100644
--- a/tests/data/translations.csv
+++ b/tests/data/translations.csv
@@ -1,3 +1,8 @@
keys,en,de
GOOD_MORNING,"Good Morning","Guten Morgen"
GOOD_EVENING,"Good Evening",""
+Without quotes,"With, comma","With ""inner"" quotes","With ""inner"", quotes"","" and comma","With ""inner
+split"" quotes and
+line breaks","With \nnewline chars"
+Some other~delimiter~should still work, shouldn't it?
+What about tab separated lines, good?
diff --git a/tests/test_class_db.h b/tests/test_class_db.h
index 29edf5a4a0..ea680da5d6 100644
--- a/tests/test_class_db.h
+++ b/tests/test_class_db.h
@@ -108,9 +108,9 @@ struct ExposedClass {
List<SignalData> signals_;
const PropertyData *find_property_by_name(const StringName &p_name) const {
- for (const List<PropertyData>::Element *E = properties.front(); E; E = E->next()) {
- if (E->get().name == p_name) {
- return &E->get();
+ for (const PropertyData &E : properties) {
+ if (E.name == p_name) {
+ return &E;
}
}
@@ -118,9 +118,9 @@ struct ExposedClass {
}
const MethodData *find_method_by_name(const StringName &p_name) const {
- for (const List<MethodData>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name == p_name) {
- return &E->get();
+ for (const MethodData &E : methods) {
+ if (E.name == p_name) {
+ return &E;
}
}
@@ -395,8 +395,8 @@ void validate_method(const Context &p_context, const ExposedClass &p_class, cons
}
}
- for (const List<ArgumentData>::Element *F = p_method.arguments.front(); F; F = F->next()) {
- const ArgumentData &arg = F->get();
+ for (const ArgumentData &F : p_method.arguments) {
+ const ArgumentData &arg = F;
const ExposedClass *arg_class = p_context.find_exposed_class(arg.type);
if (arg_class) {
@@ -427,8 +427,8 @@ void validate_method(const Context &p_context, const ExposedClass &p_class, cons
}
void validate_signal(const Context &p_context, const ExposedClass &p_class, const SignalData &p_signal) {
- for (const List<ArgumentData>::Element *F = p_signal.arguments.front(); F; F = F->next()) {
- const ArgumentData &arg = F->get();
+ for (const ArgumentData &F : p_signal.arguments) {
+ const ArgumentData &arg = F;
const ExposedClass *arg_class = p_context.find_exposed_class(arg.type);
if (arg_class) {
@@ -469,16 +469,16 @@ void validate_class(const Context &p_context, const ExposedClass &p_exposed_clas
TEST_FAIL_COND((is_derived_type && !p_context.exposed_classes.has(p_exposed_class.base)),
"Base type '", p_exposed_class.base.operator String(), "' does not exist, for class '", p_exposed_class.name, "'.");
- for (const List<PropertyData>::Element *F = p_exposed_class.properties.front(); F; F = F->next()) {
- validate_property(p_context, p_exposed_class, F->get());
+ for (const PropertyData &F : p_exposed_class.properties) {
+ validate_property(p_context, p_exposed_class, F);
}
- for (const List<MethodData>::Element *F = p_exposed_class.methods.front(); F; F = F->next()) {
- validate_method(p_context, p_exposed_class, F->get());
+ for (const MethodData &F : p_exposed_class.methods) {
+ validate_method(p_context, p_exposed_class, F);
}
- for (const List<SignalData>::Element *F = p_exposed_class.signals_.front(); F; F = F->next()) {
- validate_signal(p_context, p_exposed_class, F->get());
+ for (const SignalData &F : p_exposed_class.signals_) {
+ validate_signal(p_context, p_exposed_class, F);
}
}
@@ -526,9 +526,7 @@ void add_exposed_classes(Context &r_context) {
Map<StringName, StringName> accessor_methods;
- for (const List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
- const PropertyInfo &property = E->get();
-
+ for (const PropertyInfo &property : property_list) {
if (property.usage & PROPERTY_USAGE_GROUP || property.usage & PROPERTY_USAGE_SUBGROUP || property.usage & PROPERTY_USAGE_CATEGORY) {
continue;
}
@@ -561,8 +559,8 @@ void add_exposed_classes(Context &r_context) {
ClassDB::get_method_list(class_name, &method_list, true);
method_list.sort();
- for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
- const MethodInfo &method_info = E->get();
+ for (const MethodInfo &E : method_list) {
+ const MethodInfo &method_info = E;
int argc = method_info.arguments.size();
@@ -667,8 +665,8 @@ void add_exposed_classes(Context &r_context) {
// Methods starting with an underscore are ignored unless they're virtual or used as a property setter or getter.
if (!method.is_virtual && String(method.name)[0] == '_') {
- for (const List<PropertyData>::Element *F = exposed_class.properties.front(); F; F = F->next()) {
- const PropertyData &prop = F->get();
+ for (const PropertyData &F : exposed_class.properties) {
+ const PropertyData &prop = F;
if (prop.setter == method.name || prop.getter == method.name) {
exposed_class.methods.push_back(method);
@@ -752,8 +750,8 @@ void add_exposed_classes(Context &r_context) {
enum_.name = *k;
const List<StringName> &enum_constants = enum_map.get(*k);
- for (const List<StringName>::Element *E = enum_constants.front(); E; E = E->next()) {
- const StringName &constant_name = E->get();
+ for (const StringName &E : enum_constants) {
+ const StringName &constant_name = E;
TEST_FAIL_COND(String(constant_name).find("::") != -1,
"Enum constant contains '::', check bindings to remove the scope: '",
String(class_name), ".", String(enum_.name), ".", String(constant_name), "'.");
@@ -774,12 +772,12 @@ void add_exposed_classes(Context &r_context) {
r_context.enum_types.push_back(String(class_name) + "." + String(*k));
}
- for (const List<String>::Element *E = constants.front(); E; E = E->next()) {
- const String &constant_name = E->get();
+ for (const String &E : constants) {
+ const String &constant_name = E;
TEST_FAIL_COND(constant_name.find("::") != -1,
"Constant contains '::', check bindings to remove the scope: '",
String(class_name), ".", constant_name, "'.");
- int *value = class_info->constant_map.getptr(StringName(E->get()));
+ int *value = class_info->constant_map.getptr(StringName(E));
TEST_FAIL_COND(!value, "Missing constant value: '", String(class_name), ".", String(constant_name), "'.");
ConstantData constant;
@@ -829,8 +827,8 @@ void add_global_enums(Context &r_context) {
}
}
- for (List<EnumData>::Element *E = r_context.global_enums.front(); E; E = E->next()) {
- r_context.enum_types.push_back(E->get().name);
+ for (const EnumData &E : r_context.global_enums) {
+ r_context.enum_types.push_back(E.name);
}
}
@@ -840,10 +838,10 @@ void add_global_enums(Context &r_context) {
hardcoded_enums.push_back("Vector2i.Axis");
hardcoded_enums.push_back("Vector3.Axis");
hardcoded_enums.push_back("Vector3i.Axis");
- for (List<StringName>::Element *E = hardcoded_enums.front(); E; E = E->next()) {
+ for (const StringName &E : hardcoded_enums) {
// These enums are not generated and must be written manually (e.g.: Vector3.Axis)
// Here, we assume core types do not begin with underscore
- r_context.enum_types.push_back(E->get());
+ r_context.enum_types.push_back(E);
}
}
diff --git a/tests/test_file_access.h b/tests/test_file_access.h
index cb74e08a0d..b3da16c1d1 100644
--- a/tests/test_file_access.h
+++ b/tests/test_file_access.h
@@ -37,12 +37,12 @@
namespace TestFileAccess {
TEST_CASE("[FileAccess] CSV read") {
- FileAccess *f = FileAccess::open(TestUtils::get_data_path("translations.csv"), FileAccess::READ);
+ FileAccessRef f = FileAccess::open(TestUtils::get_data_path("translations.csv"), FileAccess::READ);
- Vector<String> header = f->get_csv_line(); // Default delimiter: ","
+ Vector<String> header = f->get_csv_line(); // Default delimiter: ",".
REQUIRE(header.size() == 3);
- Vector<String> row1 = f->get_csv_line(",");
+ Vector<String> row1 = f->get_csv_line(","); // Explicit delimiter, should be the same.
REQUIRE(row1.size() == 3);
CHECK(row1[0] == "GOOD_MORNING");
CHECK(row1[1] == "Good Morning");
@@ -53,12 +53,31 @@ TEST_CASE("[FileAccess] CSV read") {
CHECK(row2[0] == "GOOD_EVENING");
CHECK(row2[1] == "Good Evening");
CHECK(row2[2] == ""); // Use case: not yet translated!
-
// https://github.com/godotengine/godot/issues/44269
CHECK_MESSAGE(row2[2] != "\"", "Should not parse empty string as a single double quote.");
+ Vector<String> row3 = f->get_csv_line();
+ REQUIRE(row3.size() == 6);
+ CHECK(row3[0] == "Without quotes");
+ CHECK(row3[1] == "With, comma");
+ CHECK(row3[2] == "With \"inner\" quotes");
+ CHECK(row3[3] == "With \"inner\", quotes\",\" and comma");
+ CHECK(row3[4] == "With \"inner\nsplit\" quotes and\nline breaks");
+ CHECK(row3[5] == "With \\nnewline chars"); // Escaped, not an actual newline.
+
+ Vector<String> row4 = f->get_csv_line("~"); // Custom delimiter, makes inline commas easier.
+ REQUIRE(row4.size() == 3);
+ CHECK(row4[0] == "Some other");
+ CHECK(row4[1] == "delimiter");
+ CHECK(row4[2] == "should still work, shouldn't it?");
+
+ Vector<String> row5 = f->get_csv_line("\t"); // Tab separated variables.
+ REQUIRE(row5.size() == 3);
+ CHECK(row5[0] == "What about");
+ CHECK(row5[1] == "tab separated");
+ CHECK(row5[2] == "lines, good?");
+
f->close();
- memdelete(f);
}
} // namespace TestFileAccess
diff --git a/tests/test_gui.cpp b/tests/test_gui.cpp
index b83bd10af4..0ec8aa78c4 100644
--- a/tests/test_gui.cpp
+++ b/tests/test_gui.cpp
@@ -217,7 +217,7 @@ public:
richtext->add_text("faeries.\n");
richtext->pop();
richtext->add_text("In this new episode, we will attempt to ");
- richtext->push_font(richtext->get_theme_font("mono_font", "Fonts"));
+ richtext->push_font(richtext->get_theme_font(SNAME("mono_font"), SNAME("Fonts")));
richtext->push_color(Color(0.7, 0.5, 1.0));
richtext->add_text("deliver something nice");
richtext->pop();
diff --git a/tests/test_math.cpp b/tests/test_math.cpp
index 67d9a52539..a44040dfe2 100644
--- a/tests/test_math.cpp
+++ b/tests/test_math.cpp
@@ -549,8 +549,8 @@ MainLoop *test() {
List<StringName> tl;
ClassDB::get_class_list(&tl);
- for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
- Vector<uint8_t> m5b = E->get().operator String().md5_buffer();
+ for (const StringName &E : tl) {
+ Vector<uint8_t> m5b = E.operator String().md5_buffer();
hashes.push_back(hashes.size());
}
@@ -589,13 +589,13 @@ MainLoop *test() {
{
Vector3 v(1, 2, 3);
v.normalize();
- float a = 0.3;
+ real_t a = 0.3;
Basis m(v, a);
Vector3 v2(7, 3, 1);
v2.normalize();
- float a2 = 0.8;
+ real_t a2 = 0.8;
Basis m2(v2, a2);
diff --git a/tests/test_object.h b/tests/test_object.h
index b7eedc2670..a18adf31b6 100644
--- a/tests/test_object.h
+++ b/tests/test_object.h
@@ -139,7 +139,7 @@ TEST_CASE("[Object] Metadata") {
Color(object.get_meta(meta_path)).is_equal_approx(Color(0, 1, 0)),
"The returned object metadata after setting should match the expected value.");
- List<String> meta_list;
+ List<StringName> meta_list;
object.get_meta_list(&meta_list);
CHECK_MESSAGE(
meta_list.size() == 1,
@@ -154,7 +154,7 @@ TEST_CASE("[Object] Metadata") {
"The returned object metadata after removing should match the expected value.");
ERR_PRINT_ON;
- List<String> meta_list2;
+ List<StringName> meta_list2;
object.get_meta_list(&meta_list2);
CHECK_MESSAGE(
meta_list2.size() == 0,
@@ -206,7 +206,7 @@ TEST_CASE("[Object] Script instance property getter") {
}
TEST_CASE("[Object] Built-in property setter") {
- ClassDB::register_class<_TestDerivedObject>();
+ GDREGISTER_CLASS(_TestDerivedObject);
_TestDerivedObject derived_object;
bool valid = false;
@@ -218,7 +218,7 @@ TEST_CASE("[Object] Built-in property setter") {
}
TEST_CASE("[Object] Built-in property getter") {
- ClassDB::register_class<_TestDerivedObject>();
+ GDREGISTER_CLASS(_TestDerivedObject);
_TestDerivedObject derived_object;
derived_object.set_property(100);
diff --git a/tests/test_physics_2d.cpp b/tests/test_physics_2d.cpp
index a9e2e92b34..40dc74e89c 100644
--- a/tests/test_physics_2d.cpp
+++ b/tests/test_physics_2d.cpp
@@ -386,7 +386,7 @@ public:
//_add_plane(Vector2(-1,0).normalized(),-600);
}
- virtual bool process(float p_time) override {
+ virtual bool process(double p_time) override {
return false;
}
virtual void finalize() override {
diff --git a/tests/test_physics_3d.cpp b/tests/test_physics_3d.cpp
index 4488e4bf64..ed49b60c71 100644
--- a/tests/test_physics_3d.cpp
+++ b/tests/test_physics_3d.cpp
@@ -313,7 +313,7 @@ public:
test_fall();
quit = false;
}
- virtual bool physics_process(float p_time) override {
+ virtual bool physics_process(double p_time) override {
if (mover.is_valid()) {
static real_t joy_speed = 10;
PhysicsServer3D *ps = PhysicsServer3D::get_singleton();
@@ -399,7 +399,7 @@ public:
create_static_plane(Plane(Vector3(0, 1, 0), -1));
}
- virtual bool process(float p_time) override {
+ virtual bool process(double p_time) override {
return false;
}
diff --git a/tests/test_render.cpp b/tests/test_render.cpp
index fe223ca258..21b4da9b3b 100644
--- a/tests/test_render.cpp
+++ b/tests/test_render.cpp
@@ -184,7 +184,7 @@ public:
light = vs->instance_create2(lightaux, scenario);
Transform3D lla;
//lla.set_look_at(Vector3(),Vector3(1, -1, 1));
- lla.set_look_at(Vector3(), Vector3(0.0, -0.836026, -0.548690));
+ lla.basis = Basis::looking_at(Vector3(0.0, -0.836026, -0.548690));
vs->instance_set_transform(light, lla);
@@ -199,7 +199,7 @@ public:
ofs = 0;
quit = false;
}
- virtual bool iteration(float p_time) {
+ virtual bool iteration(double p_time) {
RenderingServer *vs = RenderingServer::get_singleton();
//Transform3D t;
//t.rotate(Vector3(0, 1, 0), ofs);
@@ -210,12 +210,12 @@ public:
//return quit;
- for (List<InstanceInfo>::Element *E = instances.front(); E; E = E->next()) {
- Transform3D pre(Basis(E->get().rot_axis, ofs), Vector3());
- vs->instance_set_transform(E->get().instance, pre * E->get().base);
+ for (const InstanceInfo &E : instances) {
+ Transform3D pre(Basis(E.rot_axis, ofs), Vector3());
+ vs->instance_set_transform(E.instance, pre * E.base);
/*
if( !E->next() ) {
- vs->free( E->get().instance );
+ vs->free( E.instance );
instances.erase(E );
}*/
}
@@ -223,7 +223,7 @@ public:
return quit;
}
- virtual bool idle(float p_time) {
+ virtual bool idle(double p_time) {
return quit;
}
diff --git a/tests/test_text_server.h b/tests/test_text_server.h
index 3d700f8ec4..cac022e33f 100644
--- a/tests/test_text_server.h
+++ b/tests/test_text_server.h
@@ -55,7 +55,7 @@ TEST_SUITE("[[TextServer]") {
for (int i = 0; i < TextServerManager::get_interface_count(); i++) {
TextServer *ts = TextServerManager::initialize(i, err);
- RID font = ts->create_font_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf");
+ RID font = ts->create_font_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf");
TEST_FAIL_COND(font == RID(), "Loading font failed.");
ts->free(font);
}
@@ -66,7 +66,7 @@ TEST_SUITE("[[TextServer]") {
TextServer *ts = TextServerManager::initialize(i, err);
Vector<RID> font;
- font.push_back(ts->create_font_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf"));
+ font.push_back(ts->create_font_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf"));
font.push_back(ts->create_font_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf"));
String test = U"คนอ้วน khon uan ראה";
@@ -112,7 +112,7 @@ TEST_SUITE("[[TextServer]") {
}
Vector<RID> font;
- font.push_back(ts->create_font_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf"));
+ font.push_back(ts->create_font_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf"));
font.push_back(ts->create_font_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf"));
String test = U"Arabic (اَلْعَرَبِيَّةُ, al-ʿarabiyyah)";
@@ -156,7 +156,7 @@ TEST_SUITE("[[TextServer]") {
// 5^ 10^
Vector<RID> font;
- font.push_back(ts->create_font_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf"));
+ font.push_back(ts->create_font_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf"));
font.push_back(ts->create_font_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf"));
RID ctx = ts->create_shaped_text();
@@ -186,7 +186,7 @@ TEST_SUITE("[[TextServer]") {
TextServer *ts = TextServerManager::initialize(i, err);
Vector<RID> font;
- font.push_back(ts->create_font_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf"));
+ font.push_back(ts->create_font_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf"));
font.push_back(ts->create_font_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf"));
String test_1 = U"الحمد";