summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2023-03-16 10:46:34 -0700
committerGitHub <noreply@github.com>2023-03-16 10:46:34 -0700
commit1e0f7a12f7c762ee1d73795485b0d00db3cf2ac8 (patch)
treea0d8d3e189890a3f89e8c9fe407e95dd09837176 /tests
parentd418def752febfcdc59ed102b89c8ce1b8b110c0 (diff)
parente92adba19c100bb61b767378b97776bdf707fdbb (diff)
downloadredot-engine-1e0f7a12f7c762ee1d73795485b0d00db3cf2ac8.tar.gz
Merge pull request #73121 from Scony/add-initial-navi-tests
Add initial navigation tests
Diffstat (limited to 'tests')
-rw-r--r--tests/scene/test_navigation_agent_2d.h72
-rw-r--r--tests/scene/test_navigation_agent_3d.h71
-rw-r--r--tests/servers/test_navigation_server_2d.h47
-rw-r--r--tests/servers/test_navigation_server_3d.h47
-rw-r--r--tests/test_main.cpp11
5 files changed, 248 insertions, 0 deletions
diff --git a/tests/scene/test_navigation_agent_2d.h b/tests/scene/test_navigation_agent_2d.h
new file mode 100644
index 0000000000..e20435d401
--- /dev/null
+++ b/tests/scene/test_navigation_agent_2d.h
@@ -0,0 +1,72 @@
+/**************************************************************************/
+/* test_navigation_agent_2d.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. */
+/**************************************************************************/
+
+#ifndef TEST_NAVIGATION_AGENT_2D_H
+#define TEST_NAVIGATION_AGENT_2D_H
+
+#include "scene/2d/navigation_agent_2d.h"
+#include "scene/2d/node_2d.h"
+#include "scene/main/window.h"
+#include "scene/resources/world_2d.h"
+
+#include "tests/test_macros.h"
+
+namespace TestNavigationAgent2D {
+
+TEST_SUITE("[Navigation]") {
+ TEST_CASE("[SceneTree][NavigationAgent2D] New agent should have valid RID") {
+ NavigationAgent2D *agent_node = memnew(NavigationAgent2D);
+ CHECK(agent_node->get_rid().is_valid());
+ memdelete(agent_node);
+ }
+
+ TEST_CASE("[SceneTree][NavigationAgent2D] New agent should attach to default map") {
+ Node2D *node_2d = memnew(Node2D);
+ SceneTree::get_singleton()->get_root()->add_child(node_2d);
+
+ NavigationAgent2D *agent_node = memnew(NavigationAgent2D);
+
+ // agent should not be attached to any map when outside of tree
+ CHECK_FALSE(agent_node->get_navigation_map().is_valid());
+
+ SUBCASE("Agent should attach to default map when it enters the tree") {
+ node_2d->add_child(agent_node);
+ CHECK(agent_node->get_navigation_map().is_valid());
+ CHECK(agent_node->get_navigation_map() == node_2d->get_world_2d()->get_navigation_map());
+ }
+
+ memdelete(agent_node);
+ memdelete(node_2d);
+ }
+}
+
+} //namespace TestNavigationAgent2D
+
+#endif // TEST_NAVIGATION_AGENT_2D_H
diff --git a/tests/scene/test_navigation_agent_3d.h b/tests/scene/test_navigation_agent_3d.h
new file mode 100644
index 0000000000..f240279b9f
--- /dev/null
+++ b/tests/scene/test_navigation_agent_3d.h
@@ -0,0 +1,71 @@
+/**************************************************************************/
+/* test_navigation_agent_3d.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. */
+/**************************************************************************/
+
+#ifndef TEST_NAVIGATION_AGENT_3D_H
+#define TEST_NAVIGATION_AGENT_3D_H
+
+#include "scene/3d/navigation_agent_3d.h"
+#include "scene/3d/node_3d.h"
+#include "scene/main/window.h"
+
+#include "tests/test_macros.h"
+
+namespace TestNavigationAgent3D {
+
+TEST_SUITE("[Navigation]") {
+ TEST_CASE("[SceneTree][NavigationAgent3D] New agent should have valid RID") {
+ NavigationAgent3D *agent_node = memnew(NavigationAgent3D);
+ CHECK(agent_node->get_rid().is_valid());
+ memdelete(agent_node);
+ }
+
+ TEST_CASE("[SceneTree][NavigationAgent3D] New agent should attach to default map") {
+ Node3D *node_3d = memnew(Node3D);
+ SceneTree::get_singleton()->get_root()->add_child(node_3d);
+
+ NavigationAgent3D *agent_node = memnew(NavigationAgent3D);
+
+ // agent should not be attached to any map when outside of tree
+ CHECK_FALSE(agent_node->get_navigation_map().is_valid());
+
+ SUBCASE("Agent should attach to default map when it enters the tree") {
+ node_3d->add_child(agent_node);
+ CHECK(agent_node->get_navigation_map().is_valid());
+ CHECK(agent_node->get_navigation_map() == node_3d->get_world_3d()->get_navigation_map());
+ }
+
+ memdelete(agent_node);
+ memdelete(node_3d);
+ }
+}
+
+} //namespace TestNavigationAgent3D
+
+#endif // TEST_NAVIGATION_AGENT_3D_H
diff --git a/tests/servers/test_navigation_server_2d.h b/tests/servers/test_navigation_server_2d.h
new file mode 100644
index 0000000000..ff9bb620be
--- /dev/null
+++ b/tests/servers/test_navigation_server_2d.h
@@ -0,0 +1,47 @@
+/**************************************************************************/
+/* test_navigation_server_2d.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. */
+/**************************************************************************/
+
+#ifndef TEST_NAVIGATION_SERVER_2D_H
+#define TEST_NAVIGATION_SERVER_2D_H
+
+#include "servers/navigation_server_2d.h"
+
+#include "tests/test_macros.h"
+
+namespace TestNavigationServer2D {
+TEST_SUITE("[Navigation]") {
+ TEST_CASE("[NavigationServer2D] Server should be empty when initialized") {
+ NavigationServer2D *navigation_server = NavigationServer2D::get_singleton();
+ CHECK_EQ(navigation_server->get_maps().size(), 0);
+ }
+}
+} //namespace TestNavigationServer2D
+
+#endif // TEST_NAVIGATION_SERVER_2D_H
diff --git a/tests/servers/test_navigation_server_3d.h b/tests/servers/test_navigation_server_3d.h
new file mode 100644
index 0000000000..a3c5aa8624
--- /dev/null
+++ b/tests/servers/test_navigation_server_3d.h
@@ -0,0 +1,47 @@
+/**************************************************************************/
+/* test_navigation_server_3d.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. */
+/**************************************************************************/
+
+#ifndef TEST_NAVIGATION_SERVER_3D_H
+#define TEST_NAVIGATION_SERVER_3D_H
+
+#include "servers/navigation_server_3d.h"
+
+#include "tests/test_macros.h"
+
+namespace TestNavigationServer3D {
+TEST_SUITE("[Navigation]") {
+ TEST_CASE("[NavigationServer3D] Server should be empty when initialized") {
+ NavigationServer3D *navigation_server = NavigationServer3D::get_singleton();
+ CHECK_EQ(navigation_server->get_maps().size(), 0);
+ }
+}
+} //namespace TestNavigationServer3D
+
+#endif // TEST_NAVIGATION_SERVER_3D_H
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index e029ea7190..291321a45e 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -94,6 +94,8 @@
#include "tests/scene/test_curve.h"
#include "tests/scene/test_curve_2d.h"
#include "tests/scene/test_gradient.h"
+#include "tests/scene/test_navigation_agent_2d.h"
+#include "tests/scene/test_navigation_agent_3d.h"
#include "tests/scene/test_node.h"
#include "tests/scene/test_path_2d.h"
#include "tests/scene/test_path_3d.h"
@@ -103,6 +105,8 @@
#include "tests/scene/test_theme.h"
#include "tests/scene/test_viewport.h"
#include "tests/scene/test_visual_shader.h"
+#include "tests/servers/test_navigation_server_2d.h"
+#include "tests/servers/test_navigation_server_3d.h"
#include "tests/servers/test_text_server.h"
#include "tests/test_validate_testing.h"
@@ -198,6 +202,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
SignalWatcher::get_singleton()->_clear_signals();
String name = String(p_in.m_name);
+ String suite_name = String(p_in.m_test_suite);
if (name.find("[SceneTree]") != -1) {
memnew(MessageQueue);
@@ -248,6 +253,12 @@ struct GodotTestCaseListener : public doctest::IReporter {
audio_server->init();
return;
}
+
+ if (suite_name.find("[Navigation]") != -1 && navigation_server_2d == nullptr && navigation_server_3d == nullptr) {
+ navigation_server_2d = memnew(NavigationServer2D);
+ navigation_server_3d = NavigationServer3DManager::new_default_server();
+ return;
+ }
}
void test_case_end(const doctest::CurrentTestCaseStats &) override {