summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/input/test_input_event_key.h7
-rw-r--r--tests/core/math/test_geometry_3d.h8
-rw-r--r--tests/core/object/test_class_db.h4
-rw-r--r--tests/core/variant/test_variant.h190
-rw-r--r--tests/scene/test_code_edit.h2
5 files changed, 202 insertions, 9 deletions
diff --git a/tests/core/input/test_input_event_key.h b/tests/core/input/test_input_event_key.h
index 697215bab7..3317941fad 100644
--- a/tests/core/input/test_input_event_key.h
+++ b/tests/core/input/test_input_event_key.h
@@ -106,11 +106,11 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
// Key is None without a physical key.
none_key.set_keycode(Key::NONE);
- CHECK(none_key.as_text() == " (Physical)");
+ CHECK(none_key.as_text() == "(Unset)");
// Key is none and has modifiers.
none_key.set_ctrl_pressed(true);
- CHECK(none_key.as_text() == "Ctrl+ (Physical)");
+ CHECK(none_key.as_text() == "Ctrl+(Unset)");
// Key is None WITH a physical key AND modifiers.
none_key.set_physical_keycode(Key::ENTER);
@@ -144,8 +144,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") {
InputEventKey none_key;
- // Set physical to true.
- CHECK(none_key.to_string() == "InputEventKey: keycode=0 (), mods=none, physical=true, pressed=false, echo=false");
+ CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, pressed=false, echo=false");
// Set physical key to Escape.
none_key.set_physical_keycode(Key::ESCAPE);
CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, pressed=false, echo=false");
diff --git a/tests/core/math/test_geometry_3d.h b/tests/core/math/test_geometry_3d.h
index 8d57bd5319..46a99aa4b6 100644
--- a/tests/core/math/test_geometry_3d.h
+++ b/tests/core/math/test_geometry_3d.h
@@ -388,13 +388,13 @@ TEST_CASE("[Geometry3D] Segment Intersects Triangle") {
TEST_CASE("[Geometry3D] Triangle and Box Overlap") {
struct Case {
- Vector3 box_centre;
+ Vector3 box_center;
Vector3 box_half_size;
Vector3 *tri_verts = nullptr;
bool want;
Case(){};
- Case(Vector3 p_centre, Vector3 p_half_size, Vector3 *p_verts, bool p_want) :
- box_centre(p_centre), box_half_size(p_half_size), tri_verts(p_verts), want(p_want){};
+ Case(Vector3 p_center, Vector3 p_half_size, Vector3 *p_verts, bool p_want) :
+ box_center(p_center), box_half_size(p_half_size), tri_verts(p_verts), want(p_want){};
};
Vector<Case> tt;
Vector3 GoodTriangle[3] = { Vector3(3, 2, 3), Vector3(2, 2, 1), Vector3(2, 1, 1) };
@@ -403,7 +403,7 @@ TEST_CASE("[Geometry3D] Triangle and Box Overlap") {
tt.push_back(Case(Vector3(1000, 1000, 1000), Vector3(1, 1, 1), BadTriangle, false));
for (int i = 0; i < tt.size(); ++i) {
Case current_case = tt[i];
- bool output = Geometry3D::triangle_box_overlap(current_case.box_centre, current_case.box_half_size, current_case.tri_verts);
+ bool output = Geometry3D::triangle_box_overlap(current_case.box_center, current_case.box_half_size, current_case.tri_verts);
CHECK(output == current_case.want);
}
}
diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h
index eeb1648924..e68995e539 100644
--- a/tests/core/object/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -559,6 +559,8 @@ void add_exposed_classes(Context &r_context) {
MethodData method;
method.name = method_info.name;
+ TEST_FAIL_COND(!String(method.name).is_valid_identifier(),
+ "Method name is not a valid identifier: '", exposed_class.name, ".", method.name, "'.");
if (method_info.flags & METHOD_FLAG_VIRTUAL) {
method.is_virtual = true;
@@ -682,6 +684,8 @@ void add_exposed_classes(Context &r_context) {
const MethodInfo &method_info = signal_map.get(K.key);
signal.name = method_info.name;
+ TEST_FAIL_COND(!String(signal.name).is_valid_identifier(),
+ "Signal name is not a valid identifier: '", exposed_class.name, ".", signal.name, "'.");
int argc = method_info.arguments.size();
diff --git a/tests/core/variant/test_variant.h b/tests/core/variant/test_variant.h
index 85b53264f2..dfbaa36af8 100644
--- a/tests/core/variant/test_variant.h
+++ b/tests/core/variant/test_variant.h
@@ -868,6 +868,196 @@ TEST_CASE("[Variant] Basic comparison") {
CHECK_NE(Variant(Dictionary()), Variant());
}
+TEST_CASE("[Variant] Identity comparison") {
+ // Value types are compared by value
+ Variant aabb = AABB();
+ CHECK(aabb.identity_compare(aabb));
+ CHECK(aabb.identity_compare(AABB()));
+ CHECK_FALSE(aabb.identity_compare(AABB(Vector3(1, 2, 3), Vector3(1, 2, 3))));
+
+ Variant basis = Basis();
+ CHECK(basis.identity_compare(basis));
+ CHECK(basis.identity_compare(Basis()));
+ CHECK_FALSE(basis.identity_compare(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45))));
+
+ Variant bool_var = true;
+ CHECK(bool_var.identity_compare(bool_var));
+ CHECK(bool_var.identity_compare(true));
+ CHECK_FALSE(bool_var.identity_compare(false));
+
+ Variant callable = Callable();
+ CHECK(callable.identity_compare(callable));
+ CHECK(callable.identity_compare(Callable()));
+ CHECK_FALSE(callable.identity_compare(Callable(ObjectID(), StringName("lambda"))));
+
+ Variant color = Color();
+ CHECK(color.identity_compare(color));
+ CHECK(color.identity_compare(Color()));
+ CHECK_FALSE(color.identity_compare(Color(255, 0, 255)));
+
+ Variant float_var = 1.0;
+ CHECK(float_var.identity_compare(float_var));
+ CHECK(float_var.identity_compare(1.0));
+ CHECK_FALSE(float_var.identity_compare(2.0));
+
+ Variant int_var = 1;
+ CHECK(int_var.identity_compare(int_var));
+ CHECK(int_var.identity_compare(1));
+ CHECK_FALSE(int_var.identity_compare(2));
+
+ Variant nil = Variant();
+ CHECK(nil.identity_compare(nil));
+ CHECK(nil.identity_compare(Variant()));
+ CHECK_FALSE(nil.identity_compare(true));
+
+ Variant node_path = NodePath("godot");
+ CHECK(node_path.identity_compare(node_path));
+ CHECK(node_path.identity_compare(NodePath("godot")));
+ CHECK_FALSE(node_path.identity_compare(NodePath("waiting")));
+
+ Variant plane = Plane();
+ CHECK(plane.identity_compare(plane));
+ CHECK(plane.identity_compare(Plane()));
+ CHECK_FALSE(plane.identity_compare(Plane(Vector3(1, 2, 3), 42)));
+
+ Variant projection = Projection();
+ CHECK(projection.identity_compare(projection));
+ CHECK(projection.identity_compare(Projection()));
+ CHECK_FALSE(projection.identity_compare(Projection(Transform3D(Basis(Vector3(1, 2, 3).normalized(), 45), Vector3(1, 2, 3)))));
+
+ Variant quaternion = Quaternion();
+ CHECK(quaternion.identity_compare(quaternion));
+ CHECK(quaternion.identity_compare(Quaternion()));
+ CHECK_FALSE(quaternion.identity_compare(Quaternion(Vector3(1, 2, 3).normalized(), 45)));
+
+ Variant rect2 = Rect2();
+ CHECK(rect2.identity_compare(rect2));
+ CHECK(rect2.identity_compare(Rect2()));
+ CHECK_FALSE(rect2.identity_compare(Rect2(Point2(Vector2(1, 2)), Size2(Vector2(1, 2)))));
+
+ Variant rect2i = Rect2i();
+ CHECK(rect2i.identity_compare(rect2i));
+ CHECK(rect2i.identity_compare(Rect2i()));
+ CHECK_FALSE(rect2i.identity_compare(Rect2i(Point2i(Vector2i(1, 2)), Size2i(Vector2i(1, 2)))));
+
+ Variant rid = RID();
+ CHECK(rid.identity_compare(rid));
+ CHECK(rid.identity_compare(RID()));
+ CHECK_FALSE(rid.identity_compare(RID::from_uint64(123)));
+
+ Variant signal = Signal();
+ CHECK(signal.identity_compare(signal));
+ CHECK(signal.identity_compare(Signal()));
+ CHECK_FALSE(signal.identity_compare(Signal(ObjectID(), StringName("lambda"))));
+
+ Variant str = "godot";
+ CHECK(str.identity_compare(str));
+ CHECK(str.identity_compare("godot"));
+ CHECK_FALSE(str.identity_compare("waiting"));
+
+ Variant str_name = StringName("godot");
+ CHECK(str_name.identity_compare(str_name));
+ CHECK(str_name.identity_compare(StringName("godot")));
+ CHECK_FALSE(str_name.identity_compare(StringName("waiting")));
+
+ Variant transform2d = Transform2D();
+ CHECK(transform2d.identity_compare(transform2d));
+ CHECK(transform2d.identity_compare(Transform2D()));
+ CHECK_FALSE(transform2d.identity_compare(Transform2D(45, Vector2(1, 2))));
+
+ Variant transform3d = Transform3D();
+ CHECK(transform3d.identity_compare(transform3d));
+ CHECK(transform3d.identity_compare(Transform3D()));
+ CHECK_FALSE(transform3d.identity_compare(Transform3D(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45)), Vector3(1, 2, 3))));
+
+ Variant vect2 = Vector2();
+ CHECK(vect2.identity_compare(vect2));
+ CHECK(vect2.identity_compare(Vector2()));
+ CHECK_FALSE(vect2.identity_compare(Vector2(1, 2)));
+
+ Variant vect2i = Vector2i();
+ CHECK(vect2i.identity_compare(vect2i));
+ CHECK(vect2i.identity_compare(Vector2i()));
+ CHECK_FALSE(vect2i.identity_compare(Vector2i(1, 2)));
+
+ Variant vect3 = Vector3();
+ CHECK(vect3.identity_compare(vect3));
+ CHECK(vect3.identity_compare(Vector3()));
+ CHECK_FALSE(vect3.identity_compare(Vector3(1, 2, 3)));
+
+ Variant vect3i = Vector3i();
+ CHECK(vect3i.identity_compare(vect3i));
+ CHECK(vect3i.identity_compare(Vector3i()));
+ CHECK_FALSE(vect3i.identity_compare(Vector3i(1, 2, 3)));
+
+ Variant vect4 = Vector4();
+ CHECK(vect4.identity_compare(vect4));
+ CHECK(vect4.identity_compare(Vector4()));
+ CHECK_FALSE(vect4.identity_compare(Vector4(1, 2, 3, 4)));
+
+ Variant vect4i = Vector4i();
+ CHECK(vect4i.identity_compare(vect4i));
+ CHECK(vect4i.identity_compare(Vector4i()));
+ CHECK_FALSE(vect4i.identity_compare(Vector4i(1, 2, 3, 4)));
+
+ // Reference types are compared by reference
+ Variant array = Array();
+ CHECK(array.identity_compare(array));
+ CHECK_FALSE(array.identity_compare(Array()));
+
+ Variant dictionary = Dictionary();
+ CHECK(dictionary.identity_compare(dictionary));
+ CHECK_FALSE(dictionary.identity_compare(Dictionary()));
+
+ Variant packed_byte_array = PackedByteArray();
+ CHECK(packed_byte_array.identity_compare(packed_byte_array));
+ CHECK_FALSE(packed_byte_array.identity_compare(PackedByteArray()));
+
+ Variant packed_color_array = PackedColorArray();
+ CHECK(packed_color_array.identity_compare(packed_color_array));
+ CHECK_FALSE(packed_color_array.identity_compare(PackedColorArray()));
+
+ Variant packed_float32_array = PackedFloat32Array();
+ CHECK(packed_float32_array.identity_compare(packed_float32_array));
+ CHECK_FALSE(packed_float32_array.identity_compare(PackedFloat32Array()));
+
+ Variant packed_float64_array = PackedFloat64Array();
+ CHECK(packed_float64_array.identity_compare(packed_float64_array));
+ CHECK_FALSE(packed_float64_array.identity_compare(PackedFloat64Array()));
+
+ Variant packed_int32_array = PackedInt32Array();
+ CHECK(packed_int32_array.identity_compare(packed_int32_array));
+ CHECK_FALSE(packed_int32_array.identity_compare(PackedInt32Array()));
+
+ Variant packed_int64_array = PackedInt64Array();
+ CHECK(packed_int64_array.identity_compare(packed_int64_array));
+ CHECK_FALSE(packed_int64_array.identity_compare(PackedInt64Array()));
+
+ Variant packed_string_array = PackedStringArray();
+ CHECK(packed_string_array.identity_compare(packed_string_array));
+ CHECK_FALSE(packed_string_array.identity_compare(PackedStringArray()));
+
+ Variant packed_vector2_array = PackedVector2Array();
+ CHECK(packed_vector2_array.identity_compare(packed_vector2_array));
+ CHECK_FALSE(packed_vector2_array.identity_compare(PackedVector2Array()));
+
+ Variant packed_vector3_array = PackedVector3Array();
+ CHECK(packed_vector3_array.identity_compare(packed_vector3_array));
+ CHECK_FALSE(packed_vector3_array.identity_compare(PackedVector3Array()));
+
+ Object obj_one = Object();
+ Variant obj_one_var = &obj_one;
+ Object obj_two = Object();
+ Variant obj_two_var = &obj_two;
+ CHECK(obj_one_var.identity_compare(obj_one_var));
+ CHECK_FALSE(obj_one_var.identity_compare(obj_two_var));
+
+ Variant obj_null_one_var = Variant((Object *)nullptr);
+ Variant obj_null_two_var = Variant((Object *)nullptr);
+ CHECK(obj_null_one_var.identity_compare(obj_null_one_var));
+ CHECK(obj_null_one_var.identity_compare(obj_null_two_var));
+}
+
TEST_CASE("[Variant] Nested array comparison") {
Array a1 = build_array(1, build_array(2, 3));
Array a2 = build_array(1, build_array(2, 3));
diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h
index e98aece305..828029dabe 100644
--- a/tests/scene/test_code_edit.h
+++ b/tests/scene/test_code_edit.h
@@ -2773,7 +2773,7 @@ TEST_CASE("[SceneTree][CodeEdit] completion") {
CHECK(code_edit->get_line(0) == "''");
CHECK(code_edit->get_caret_column() == 1);
- /* Move out from centre, Should match and insert larger key. */
+ /* Move out from center, Should match and insert larger key. */
SEND_GUI_ACTION(code_edit, "ui_text_caret_right");
SEND_GUI_KEY_EVENT(code_edit, Key::APOSTROPHE);
CHECK(code_edit->get_line(0) == "''''''");