Merge pull request #73121 from Scony/add-initial-navi-tests

Add initial navigation tests
This commit is contained in:
Rémi Verschelde 2023-03-16 10:46:34 -07:00 committed by GitHub
commit 1e0f7a12f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 248 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 {