diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-08-28 12:03:53 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-08-28 12:03:53 +0200 |
commit | 2c0a74a14938e053fc44e32b7fc134513c6f3bb5 (patch) | |
tree | be75aca5ccc3e82eda8664fdb662afbdb64d2576 /tests | |
parent | b00796eb1af9257f9fda22839447f765b3193161 (diff) | |
parent | 152572ac3862718e770b81c862970089810bcc34 (diff) | |
download | redot-engine-2c0a74a14938e053fc44e32b7fc134513c6f3bb5.tar.gz |
Merge pull request #80105 from Sauermann/fix-global-transform
Fix global transform validity for `Node2D` and `Control`
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scene/test_control.h | 66 | ||||
-rw-r--r-- | tests/scene/test_node_2d.h | 63 | ||||
-rw-r--r-- | tests/test_main.cpp | 2 |
3 files changed, 131 insertions, 0 deletions
diff --git a/tests/scene/test_control.h b/tests/scene/test_control.h new file mode 100644 index 0000000000..3d7e389e0a --- /dev/null +++ b/tests/scene/test_control.h @@ -0,0 +1,66 @@ +/**************************************************************************/ +/* test_control.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_CONTROL_H +#define TEST_CONTROL_H + +#include "scene/gui/control.h" + +#include "tests/test_macros.h" + +namespace TestControl { + +TEST_CASE("[SceneTree][Control]") { + SUBCASE("[Control][Global Transform] Global Transform should be accessible while not in SceneTree.") { // GH-79453 + Control *test_node = memnew(Control); + Control *test_child = memnew(Control); + test_node->add_child(test_child); + + test_node->set_global_position(Point2(1, 1)); + CHECK_EQ(test_node->get_global_position(), Point2(1, 1)); + CHECK_EQ(test_child->get_global_position(), Point2(1, 1)); + test_node->set_global_position(Point2(2, 2)); + CHECK_EQ(test_node->get_global_position(), Point2(2, 2)); + test_node->set_scale(Vector2(4, 4)); + CHECK_EQ(test_node->get_global_transform(), Transform2D(0, Size2(4, 4), 0, Vector2(2, 2))); + test_node->set_scale(Vector2(1, 1)); + test_node->set_rotation_degrees(90); + CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(2, 2))); + test_node->set_pivot_offset(Vector2(1, 0)); + CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(3, 1))); + + memdelete(test_child); + memdelete(test_node); + } +} + +} // namespace TestControl + +#endif // TEST_CONTROL_H diff --git a/tests/scene/test_node_2d.h b/tests/scene/test_node_2d.h new file mode 100644 index 0000000000..7e93c77e22 --- /dev/null +++ b/tests/scene/test_node_2d.h @@ -0,0 +1,63 @@ +/**************************************************************************/ +/* test_node_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_NODE_2D_H +#define TEST_NODE_2D_H + +#include "scene/2d/node_2d.h" + +#include "tests/test_macros.h" + +namespace TestNode2D { + +TEST_CASE("[SceneTree][Node2D]") { + SUBCASE("[Node2D][Global Transform] Global Transform should be accessible while not in SceneTree.") { // GH-79453 + Node2D *test_node = memnew(Node2D); + test_node->set_name("node"); + Node2D *test_child = memnew(Node2D); + test_child->set_name("child"); + test_node->add_child(test_child); + + test_node->set_global_position(Point2(1, 1)); + CHECK_EQ(test_node->get_global_position(), Point2(1, 1)); + CHECK_EQ(test_child->get_global_position(), Point2(1, 1)); + test_node->set_global_position(Point2(2, 2)); + CHECK_EQ(test_node->get_global_position(), Point2(2, 2)); + test_node->set_global_transform(Transform2D(0, Point2(3, 3))); + CHECK_EQ(test_node->get_global_position(), Point2(3, 3)); + + memdelete(test_child); + memdelete(test_node); + } +} + +} // namespace TestNode2D + +#endif // TEST_NODE_2D_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index f42fa517fe..6cc7aad48e 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -95,6 +95,7 @@ #include "tests/scene/test_bit_map.h" #include "tests/scene/test_code_edit.h" #include "tests/scene/test_color_picker.h" +#include "tests/scene/test_control.h" #include "tests/scene/test_curve.h" #include "tests/scene/test_curve_2d.h" #include "tests/scene/test_curve_3d.h" @@ -106,6 +107,7 @@ #include "tests/scene/test_navigation_region_2d.h" #include "tests/scene/test_navigation_region_3d.h" #include "tests/scene/test_node.h" +#include "tests/scene/test_node_2d.h" #include "tests/scene/test_packed_scene.h" #include "tests/scene/test_path_2d.h" #include "tests/scene/test_path_3d.h" |