summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/input/test_input_event_key.h56
-rw-r--r--tests/scene/test_camera_3d.h12
-rw-r--r--tests/scene/test_navigation_region_3d.h40
-rw-r--r--tests/servers/test_navigation_server_3d.h18
4 files changed, 113 insertions, 13 deletions
diff --git a/tests/core/input/test_input_event_key.h b/tests/core/input/test_input_event_key.h
index 3317941fad..80918542ce 100644
--- a/tests/core/input/test_input_event_key.h
+++ b/tests/core/input/test_input_event_key.h
@@ -85,6 +85,16 @@ TEST_CASE("[InputEventKey] Key correctly stores and retrieves unicode") {
CHECK(key.get_unicode() != 'y');
}
+TEST_CASE("[InputEventKey] Key correctly stores and retrieves location") {
+ InputEventKey key;
+
+ CHECK(key.get_location() == KeyLocation::UNSPECIFIED);
+
+ key.set_location(KeyLocation::LEFT);
+ CHECK(key.get_location() == KeyLocation::LEFT);
+ CHECK(key.get_location() != KeyLocation::RIGHT);
+}
+
TEST_CASE("[InputEventKey] Key correctly stores and checks echo") {
InputEventKey key;
@@ -144,32 +154,36 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") {
InputEventKey none_key;
- CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, pressed=false, echo=false");
+ CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, location=unspecified, 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");
+ CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, location=unspecified, pressed=false, echo=false");
InputEventKey key;
// Set physical to None, set keycode to Space.
key.set_keycode(Key::SPACE);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=false, echo=false");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=unspecified, pressed=false, echo=false");
+
+ // Set location
+ key.set_location(KeyLocation::RIGHT);
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=false, echo=false");
// Set pressed to true.
key.set_pressed(true);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=false");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=false");
// set echo to true.
key.set_echo(true);
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=none, physical=false, location=right, pressed=true, echo=true");
// Press Ctrl and Alt.
key.set_ctrl_pressed(true);
key.set_alt_pressed(true);
#ifdef MACOS_ENABLED
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Option, physical=false, location=right, pressed=true, echo=true");
#else
- CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, pressed=true, echo=true");
+ CHECK(key.to_string() == "InputEventKey: keycode=32 (Space), mods=Ctrl+Alt, physical=false, location=right, pressed=true, echo=true");
#endif
}
@@ -291,6 +305,34 @@ TEST_CASE("[IsMatch] Keys are correctly matched") {
CHECK(key2.is_match(match, true) == true);
CHECK(key2.is_match(no_match, true) == false);
+
+ // Physical key with location.
+ InputEventKey key3;
+ key3.set_keycode(Key::NONE);
+ key3.set_physical_keycode(Key::SHIFT);
+
+ Ref<InputEventKey> loc_ref = key.create_reference(Key::NONE);
+
+ loc_ref->set_keycode(Key::SHIFT);
+ loc_ref->set_physical_keycode(Key::SHIFT);
+
+ CHECK(key3.is_match(loc_ref, false) == true);
+ key3.set_location(KeyLocation::UNSPECIFIED);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ loc_ref->set_location(KeyLocation::LEFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ key3.set_location(KeyLocation::LEFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
+
+ key3.set_location(KeyLocation::RIGHT);
+ CHECK(key3.is_match(loc_ref, false) == false);
+
+ // Keycode key with location.
+ key3.set_physical_keycode(Key::NONE);
+ key3.set_keycode(Key::SHIFT);
+ CHECK(key3.is_match(loc_ref, false) == true);
}
} // namespace TestInputEventKey
diff --git a/tests/scene/test_camera_3d.h b/tests/scene/test_camera_3d.h
index 169486d108..830c667257 100644
--- a/tests/scene/test_camera_3d.h
+++ b/tests/scene/test_camera_3d.h
@@ -65,17 +65,17 @@ TEST_CASE("[SceneTree][Camera3D] Getters and setters") {
}
SUBCASE("Camera frustum properties") {
- constexpr float near = 0.2f;
- constexpr float far = 995.0f;
+ constexpr float depth_near = 0.2f;
+ constexpr float depth_far = 995.0f;
constexpr float fov = 120.0f;
constexpr float size = 7.0f;
constexpr float h_offset = 1.1f;
constexpr float v_offset = -1.6f;
const Vector2 frustum_offset(5, 7);
- test_camera->set_near(near);
- CHECK(test_camera->get_near() == near);
- test_camera->set_far(far);
- CHECK(test_camera->get_far() == far);
+ test_camera->set_near(depth_near);
+ CHECK(test_camera->get_near() == depth_near);
+ test_camera->set_far(depth_far);
+ CHECK(test_camera->get_far() == depth_far);
test_camera->set_fov(fov);
CHECK(test_camera->get_fov() == fov);
test_camera->set_size(size);
diff --git a/tests/scene/test_navigation_region_3d.h b/tests/scene/test_navigation_region_3d.h
index 4c5ae34615..f7cf7c7912 100644
--- a/tests/scene/test_navigation_region_3d.h
+++ b/tests/scene/test_navigation_region_3d.h
@@ -31,8 +31,10 @@
#ifndef TEST_NAVIGATION_REGION_3D_H
#define TEST_NAVIGATION_REGION_3D_H
+#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/navigation_region_3d.h"
#include "scene/main/window.h"
+#include "scene/resources/primitive_meshes.h"
#include "tests/test_macros.h"
@@ -44,6 +46,44 @@ TEST_SUITE("[Navigation]") {
CHECK(region_node->get_region_rid().is_valid());
memdelete(region_node);
}
+
+ TEST_CASE("[SceneTree][NavigationRegion3D] Region should bake successfully from valid geometry") {
+ Node3D *node_3d = memnew(Node3D);
+ SceneTree::get_singleton()->get_root()->add_child(node_3d);
+ Ref<NavigationMesh> navigation_mesh = memnew(NavigationMesh);
+ NavigationRegion3D *navigation_region = memnew(NavigationRegion3D);
+ navigation_region->set_navigation_mesh(navigation_mesh);
+ node_3d->add_child(navigation_region);
+ Ref<PlaneMesh> plane_mesh = memnew(PlaneMesh);
+ plane_mesh->set_size(Size2(10.0, 10.0));
+ MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
+ mesh_instance->set_mesh(plane_mesh);
+ navigation_region->add_child(mesh_instance);
+
+ CHECK_FALSE(navigation_region->is_baking());
+ CHECK_EQ(navigation_mesh->get_polygon_count(), 0);
+ CHECK_EQ(navigation_mesh->get_vertices().size(), 0);
+
+ SUBCASE("Synchronous bake should have immediate effects") {
+ navigation_region->bake_navigation_mesh(false);
+ CHECK_FALSE(navigation_region->is_baking());
+ CHECK_NE(navigation_mesh->get_polygon_count(), 0);
+ CHECK_NE(navigation_mesh->get_vertices().size(), 0);
+ }
+
+ // Race condition is present in the below subcase, but baking should take many
+ // orders of magnitude longer than basic checks on the main thread, so it's fine.
+ SUBCASE("Asynchronous bake should not be immediate") {
+ navigation_region->bake_navigation_mesh(true);
+ CHECK(navigation_region->is_baking());
+ CHECK_EQ(navigation_mesh->get_polygon_count(), 0);
+ CHECK_EQ(navigation_mesh->get_vertices().size(), 0);
+ }
+
+ memdelete(mesh_instance);
+ memdelete(navigation_region);
+ memdelete(node_3d);
+ }
}
} //namespace TestNavigationRegion3D
diff --git a/tests/servers/test_navigation_server_3d.h b/tests/servers/test_navigation_server_3d.h
index 5ab2975b74..5b5c1faac8 100644
--- a/tests/servers/test_navigation_server_3d.h
+++ b/tests/servers/test_navigation_server_3d.h
@@ -720,6 +720,24 @@ TEST_SUITE("[Navigation]") {
navigation_server->free(map);
navigation_server->process(0.0); // Give server some cycles to commit.
}
+
+ TEST_CASE("[NavigationServer3D] Server should be able to bake asynchronously") {
+ NavigationServer3D *navigation_server = NavigationServer3D::get_singleton();
+ Ref<NavigationMesh> navigation_mesh = memnew(NavigationMesh);
+ Ref<NavigationMeshSourceGeometryData3D> source_geometry = memnew(NavigationMeshSourceGeometryData3D);
+
+ Array arr;
+ arr.resize(RS::ARRAY_MAX);
+ BoxMesh::create_mesh_array(arr, Vector3(10.0, 0.001, 10.0));
+ source_geometry->add_mesh_array(arr, Transform3D());
+
+ // Race condition is present below, but baking should take many orders of magnitude
+ // longer than basic checks on the main thread, so it's fine.
+ navigation_server->bake_from_source_geometry_data_async(navigation_mesh, source_geometry, Callable());
+ CHECK(navigation_server->is_baking_navigation_mesh(navigation_mesh));
+ CHECK_EQ(navigation_mesh->get_polygon_count(), 0);
+ CHECK_EQ(navigation_mesh->get_vertices().size(), 0);
+ }
}
} //namespace TestNavigationServer3D