diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_astar.h | 1 | ||||
-rw-r--r-- | tests/test_basis.h | 1 | ||||
-rw-r--r-- | tests/test_class_db.h | 1 | ||||
-rw-r--r-- | tests/test_color.h | 1 | ||||
-rw-r--r-- | tests/test_command_queue.h | 1 | ||||
-rw-r--r-- | tests/test_config_file.h | 156 | ||||
-rw-r--r-- | tests/test_curve.h | 221 | ||||
-rw-r--r-- | tests/test_expression.h | 1 | ||||
-rw-r--r-- | tests/test_gradient.h | 1 | ||||
-rw-r--r-- | tests/test_gui.cpp | 1 | ||||
-rw-r--r-- | tests/test_list.h | 1 | ||||
-rw-r--r-- | tests/test_main.cpp | 4 | ||||
-rw-r--r-- | tests/test_math.cpp | 1 | ||||
-rw-r--r-- | tests/test_method_bind.h | 1 | ||||
-rw-r--r-- | tests/test_node_path.h | 172 | ||||
-rw-r--r-- | tests/test_oa_hash_map.cpp | 1 | ||||
-rw-r--r-- | tests/test_ordered_hash_map.h | 1 | ||||
-rw-r--r-- | tests/test_pck_packer.h | 114 | ||||
-rw-r--r-- | tests/test_physics_2d.cpp | 1 | ||||
-rw-r--r-- | tests/test_physics_3d.cpp | 1 | ||||
-rw-r--r-- | tests/test_render.cpp | 3 | ||||
-rw-r--r-- | tests/test_shader_lang.cpp | 1 | ||||
-rw-r--r-- | tests/test_string.h | 1 | ||||
-rw-r--r-- | tests/test_variant.h | 1 |
24 files changed, 667 insertions, 21 deletions
diff --git a/tests/test_astar.h b/tests/test_astar.h index bef6127471..cd1bd84c15 100644 --- a/tests/test_astar.h +++ b/tests/test_astar.h @@ -362,7 +362,6 @@ TEST_CASE("[Stress][AStar] Find paths") { CHECK_MESSAGE(match, "Found all paths."); } } - } // namespace TestAStar #endif // TEST_ASTAR_H diff --git a/tests/test_basis.h b/tests/test_basis.h index db4e0b347f..00a00b4a5b 100644 --- a/tests/test_basis.h +++ b/tests/test_basis.h @@ -282,7 +282,6 @@ TEST_CASE("[Stress][Basis] Euler conversions") { } } } - } // namespace TestBasis #endif diff --git a/tests/test_class_db.h b/tests/test_class_db.h index 29fe837587..9a30891c16 100644 --- a/tests/test_class_db.h +++ b/tests/test_class_db.h @@ -830,7 +830,6 @@ TEST_SUITE("[ClassDB]") { } } } - } // namespace TestClassDB #endif //GODOT_TEST_CLASS_DB_H diff --git a/tests/test_color.h b/tests/test_color.h index 04b66811e3..c2bb63b7d0 100644 --- a/tests/test_color.h +++ b/tests/test_color.h @@ -202,7 +202,6 @@ TEST_CASE("[Color] Manipulation methods") { red.lerp(yellow, 0.5).is_equal_approx(Color(1, 0.5, 0, 0.5)), "Red interpolated with yellow should be orange (with interpolated alpha)."); } - } // namespace TestColor #endif // TEST_COLOR_H diff --git a/tests/test_command_queue.h b/tests/test_command_queue.h index c3cfa08b61..ce42d94475 100644 --- a/tests/test_command_queue.h +++ b/tests/test_command_queue.h @@ -474,7 +474,6 @@ TEST_CASE("[Stress][CommandQueue] Stress test command queue") { ProjectSettings::get_singleton()->set_setting(COMMAND_QUEUE_SETTING, ProjectSettings::get_singleton()->property_get_revert(COMMAND_QUEUE_SETTING)); } - } // namespace TestCommandQueue #endif // !defined(NO_THREADS) diff --git a/tests/test_config_file.h b/tests/test_config_file.h new file mode 100644 index 0000000000..f910ca4b1f --- /dev/null +++ b/tests/test_config_file.h @@ -0,0 +1,156 @@ +/*************************************************************************/ +/* test_config_file.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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_CONFIG_FILE_H +#define TEST_CONFIG_FILE_H + +#include "core/io/config_file.h" + +#include "tests/test_macros.h" + +namespace TestConfigFile { + +TEST_CASE("[ConfigFile] Parsing well-formatted files") { + ConfigFile config_file; + // Formatting is intentionally hand-edited to see how human-friendly the parser is. + const Error error = config_file.parse(R"( +[player] + +name = "Unnamed Player" +tagline="Waiting +for +Godot" + +color =Color( 0, 0.5,1, 1) ; Inline comment +position= Vector2( + 3, + 4 +) + +[graphics] + +antialiasing = true + +; Testing comments and case-sensitivity... +antiAliasing = false +)"); + + CHECK_MESSAGE(error == OK, "The configuration file should parse successfully."); + CHECK_MESSAGE( + String(config_file.get_value("player", "name")) == "Unnamed Player", + "Reading `player/name` should return the expected value."); + CHECK_MESSAGE( + String(config_file.get_value("player", "tagline")) == "Waiting\nfor\nGodot", + "Reading `player/tagline` should return the expected value."); + CHECK_MESSAGE( + Color(config_file.get_value("player", "color")).is_equal_approx(Color(0, 0.5, 1)), + "Reading `player/color` should return the expected value."); + CHECK_MESSAGE( + Vector2(config_file.get_value("player", "position")).is_equal_approx(Vector2(3, 4)), + "Reading `player/position` should return the expected value."); + CHECK_MESSAGE( + bool(config_file.get_value("graphics", "antialiasing")), + "Reading `graphics/antialiasing` should return `true`."); + CHECK_MESSAGE( + bool(config_file.get_value("graphics", "antiAliasing")) == false, + "Reading `graphics/antiAliasing` should return `false`."); + + // An empty ConfigFile is valid. + const Error error_empty = config_file.parse(""); + CHECK_MESSAGE(error_empty == OK, + "An empty configuration file should parse successfully."); +} + +TEST_CASE("[ConfigFile] Parsing malformatted file") { + ConfigFile config_file; + ERR_PRINT_OFF; + const Error error = config_file.parse(R"( +[player] + +name = "Unnamed Player"" ; Extraneous closing quote. +tagline = "Waiting\nfor\nGodot" + +color = Color(0, 0.5, 1) ; Missing 4th parameter. +position = Vector2( + 3,, + 4 +) ; Extraneous comma. + +[graphics] + +antialiasing = true +antialiasing = false ; Duplicate key. +)"); + ERR_PRINT_ON; + + CHECK_MESSAGE(error == ERR_PARSE_ERROR, + "The configuration file shouldn't parse successfully."); +} + +TEST_CASE("[ConfigFile] Saving file") { + ConfigFile config_file; + config_file.set_value("player", "name", "Unnamed Player"); + config_file.set_value("player", "tagline", "Waiting\nfor\nGodot"); + config_file.set_value("player", "color", Color(0, 0.5, 1)); + config_file.set_value("player", "position", Vector2(3, 4)); + config_file.set_value("graphics", "antialiasing", true); + config_file.set_value("graphics", "antiAliasing", false); + +#ifdef WINDOWS_ENABLED + const String config_path = OS::get_singleton()->get_environment("TEMP").plus_file("config.ini"); +#else + const String config_path = "/tmp/config.ini"; +#endif + + config_file.save(config_path); + + // Expected contents of the saved ConfigFile. + const String contents = R"([player] + +name="Unnamed Player" +tagline="Waiting +for +Godot" +color=Color( 0, 0.5, 1, 1 ) +position=Vector2( 3, 4 ) + +[graphics] + +antialiasing=true +antiAliasing=false +)"; + + FileAccessRef file = FileAccess::open(config_path, FileAccess::READ); + CHECK_MESSAGE(file->get_as_utf8_string() == contents, + "The saved configuration file should match the expected format."); +} +} // namespace TestConfigFile + +#endif // TEST_CONFIG_FILE_H diff --git a/tests/test_curve.h b/tests/test_curve.h new file mode 100644 index 0000000000..b123ef6325 --- /dev/null +++ b/tests/test_curve.h @@ -0,0 +1,221 @@ +/*************************************************************************/ +/* test_curve.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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_CURVE_H +#define TEST_CURVE_H + +#include "scene/resources/curve.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestCurve { + +TEST_CASE("[Curve] Default curve") { + const Ref<Curve> curve = memnew(Curve); + + CHECK_MESSAGE( + curve->get_point_count() == 0, + "Default curve should contain the expected number of points."); + CHECK_MESSAGE( + Math::is_zero_approx(curve->interpolate(0)), + "Default curve should return the expected value at offset 0.0."); + CHECK_MESSAGE( + Math::is_zero_approx(curve->interpolate(0.5)), + "Default curve should return the expected value at offset 0.5."); + CHECK_MESSAGE( + Math::is_zero_approx(curve->interpolate(1)), + "Default curve should return the expected value at offset 1.0."); +} + +TEST_CASE("[Curve] Custom curve with free tangents") { + Ref<Curve> curve = memnew(Curve); + // "Sawtooth" curve with an open ending towards the 1.0 offset. + curve->add_point(Vector2(0, 0)); + curve->add_point(Vector2(0.25, 1)); + curve->add_point(Vector2(0.5, 0)); + curve->add_point(Vector2(0.75, 1)); + + CHECK_MESSAGE( + Math::is_zero_approx(curve->get_point_left_tangent(0)), + "get_point_left_tangent() should return the expected value for point index 0."); + CHECK_MESSAGE( + Math::is_zero_approx(curve->get_point_right_tangent(0)), + "get_point_right_tangent() should return the expected value for point index 0."); + CHECK_MESSAGE( + curve->get_point_left_mode(0) == Curve::TangentMode::TANGENT_FREE, + "get_point_left_mode() should return the expected value for point index 0."); + CHECK_MESSAGE( + curve->get_point_right_mode(0) == Curve::TangentMode::TANGENT_FREE, + "get_point_right_mode() should return the expected value for point index 0."); + + CHECK_MESSAGE( + curve->get_point_count() == 4, + "Custom free curve should contain the expected number of points."); + + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(-0.1), 0), + "Custom free curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.1), 0.352), + "Custom free curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.4), 0.352), + "Custom free curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.7), 0.896), + "Custom free curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(1), 1), + "Custom free curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(2), 1), + "Custom free curve should return the expected value at offset 0.1."); + + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(-0.1), 0), + "Custom free curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.1), 0.352), + "Custom free curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.4), 0.352), + "Custom free curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.7), 0.896), + "Custom free curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(1), 1), + "Custom free curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(2), 1), + "Custom free curve should return the expected baked value at offset 0.1."); + + curve->remove_point(1); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.1), 0), + "Custom free curve should return the expected value at offset 0.1 after removing point at index 1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.1), 0), + "Custom free curve should return the expected baked value at offset 0.1 after removing point at index 1."); + + curve->clear_points(); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.6), 0), + "Custom free curve should return the expected value at offset 0.6 after clearing all points."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.6), 0), + "Custom free curve should return the expected baked value at offset 0.6 after clearing all points."); +} + +TEST_CASE("[Curve] Custom curve with linear tangents") { + Ref<Curve> curve = memnew(Curve); + // "Sawtooth" curve with an open ending towards the 1.0 offset. + curve->add_point(Vector2(0, 0), 0, 0, Curve::TangentMode::TANGENT_LINEAR, Curve::TangentMode::TANGENT_LINEAR); + curve->add_point(Vector2(0.25, 1), 0, 0, Curve::TangentMode::TANGENT_LINEAR, Curve::TangentMode::TANGENT_LINEAR); + curve->add_point(Vector2(0.5, 0), 0, 0, Curve::TangentMode::TANGENT_LINEAR, Curve::TangentMode::TANGENT_LINEAR); + curve->add_point(Vector2(0.75, 1), 0, 0, Curve::TangentMode::TANGENT_LINEAR, Curve::TangentMode::TANGENT_LINEAR); + + CHECK_MESSAGE( + Math::is_equal_approx(curve->get_point_left_tangent(3), 4), + "get_point_left_tangent() should return the expected value for point index 3."); + CHECK_MESSAGE( + Math::is_zero_approx(curve->get_point_right_tangent(3)), + "get_point_right_tangent() should return the expected value for point index 3."); + CHECK_MESSAGE( + curve->get_point_left_mode(3) == Curve::TangentMode::TANGENT_LINEAR, + "get_point_left_mode() should return the expected value for point index 3."); + CHECK_MESSAGE( + curve->get_point_right_mode(3) == Curve::TangentMode::TANGENT_LINEAR, + "get_point_right_mode() should return the expected value for point index 3."); + + ERR_PRINT_OFF; + CHECK_MESSAGE( + Math::is_zero_approx(curve->get_point_right_tangent(300)), + "get_point_right_tangent() should return the expected value for invalid point index 300."); + CHECK_MESSAGE( + curve->get_point_left_mode(-12345) == Curve::TangentMode::TANGENT_FREE, + "get_point_left_mode() should return the expected value for invalid point index -12345."); + ERR_PRINT_ON; + + CHECK_MESSAGE( + curve->get_point_count() == 4, + "Custom linear curve should contain the expected number of points."); + + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(-0.1), 0), + "Custom linear curve should return the expected value at offset -0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.1), 0.4), + "Custom linear curve should return the expected value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.4), 0.4), + "Custom linear curve should return the expected value at offset 0.4."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.7), 0.8), + "Custom linear curve should return the expected value at offset 0.7."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(1), 1), + "Custom linear curve should return the expected value at offset 1.0."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(2), 1), + "Custom linear curve should return the expected value at offset 2.0."); + + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(-0.1), 0), + "Custom linear curve should return the expected baked value at offset -0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.1), 0.4), + "Custom linear curve should return the expected baked value at offset 0.1."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.4), 0.4), + "Custom linear curve should return the expected baked value at offset 0.4."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.7), 0.8), + "Custom linear curve should return the expected baked value at offset 0.7."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(1), 1), + "Custom linear curve should return the expected baked value at offset 1.0."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(2), 1), + "Custom linear curve should return the expected baked value at offset 2.0."); + + ERR_PRINT_OFF; + curve->remove_point(10); + ERR_PRINT_ON; + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate(0.7), 0.8), + "Custom free curve should return the expected value at offset 0.7 after removing point at invalid index 10."); + CHECK_MESSAGE( + Math::is_equal_approx(curve->interpolate_baked(0.7), 0.8), + "Custom free curve should return the expected baked value at offset 0.7 after removing point at invalid index 10."); +} +} // namespace TestCurve + +#endif // TEST_CURVE_H diff --git a/tests/test_expression.h b/tests/test_expression.h index c9cb0158f3..0d970ba87a 100644 --- a/tests/test_expression.h +++ b/tests/test_expression.h @@ -439,7 +439,6 @@ TEST_CASE("[Expression] Unusual expressions") { // int64_t(expression.execute()) == 0, // "`(-9223372036854775807 - 1) / -1` should return the expected result."); } - } // namespace TestExpression #endif // TEST_EXPRESSION_H diff --git a/tests/test_gradient.h b/tests/test_gradient.h index 8f28dfd9b4..0c018c33e5 100644 --- a/tests/test_gradient.h +++ b/tests/test_gradient.h @@ -146,7 +146,6 @@ TEST_CASE("[Gradient] Custom gradient (points specified out-of-order)") { gradient->get_color_at_offset(0.1).is_equal_approx(Color(1, 0, 0)), "Custom out-of-order gradient should return the expected interpolated value at offset 0.1 after removing point at index 0."); } - } // namespace TestGradient #endif // TEST_GRADIENT_H diff --git a/tests/test_gui.cpp b/tests/test_gui.cpp index 03c9dfd2ba..c2d81bda69 100644 --- a/tests/test_gui.cpp +++ b/tests/test_gui.cpp @@ -265,7 +265,6 @@ public: MainLoop *test() { return memnew(TestMainLoop); } - } // namespace TestGUI #endif diff --git a/tests/test_list.h b/tests/test_list.h index adeedaaf3e..1b23233838 100644 --- a/tests/test_list.h +++ b/tests/test_list.h @@ -273,7 +273,6 @@ TEST_CASE("[Stress][List] Swap random 10 elements, 1000 iterations.") { populate_integers(list, n, 10); swap_random(list, n, 10, 1000); } - } // namespace TestList #endif // TEST_LIST_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index b4ddf0f1c1..cd7f1d3eac 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -37,14 +37,18 @@ #include "test_class_db.h" #include "test_color.h" #include "test_command_queue.h" +#include "test_config_file.h" +#include "test_curve.h" #include "test_expression.h" #include "test_gradient.h" #include "test_gui.h" #include "test_list.h" #include "test_math.h" #include "test_method_bind.h" +#include "test_node_path.h" #include "test_oa_hash_map.h" #include "test_ordered_hash_map.h" +#include "test_pck_packer.h" #include "test_physics_2d.h" #include "test_physics_3d.h" #include "test_render.h" diff --git a/tests/test_math.cpp b/tests/test_math.cpp index e745d1609e..a7f99e5401 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -699,5 +699,4 @@ MainLoop *test() { return nullptr; } - } // namespace TestMath diff --git a/tests/test_method_bind.h b/tests/test_method_bind.h index 9507a10d3e..62d8bd132c 100644 --- a/tests/test_method_bind.h +++ b/tests/test_method_bind.h @@ -159,7 +159,6 @@ TEST_CASE("[MethodBind] check all method binds") { memdelete(mbt); } - } // namespace TestMethodBind #endif // TEST_METHOD_BIND_H diff --git a/tests/test_node_path.h b/tests/test_node_path.h new file mode 100644 index 0000000000..e9e06186f5 --- /dev/null +++ b/tests/test_node_path.h @@ -0,0 +1,172 @@ +/*************************************************************************/ +/* test_node_path.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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_PATH_H +#define TEST_NODE_PATH_H + +#include "core/string/node_path.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestNodePath { + +TEST_CASE("[NodePath] Relative path") { + const NodePath node_path_relative = NodePath("Path2D/PathFollow2D/Sprite2D:position:x"); + + CHECK_MESSAGE( + node_path_relative.get_as_property_path() == NodePath(":Path2D/PathFollow2D/Sprite2D:position:x"), + "The returned property path should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_concatenated_subnames() == "position:x", + "The returned concatenated subnames should match the expected value."); + + CHECK_MESSAGE( + node_path_relative.get_name(0) == "Path2D", + "The returned name at index 0 should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_name(1) == "PathFollow2D", + "The returned name at index 1 should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_name(2) == "Sprite2D", + "The returned name at index 2 should match the expected value."); + ERR_PRINT_OFF; + CHECK_MESSAGE( + node_path_relative.get_name(3) == "", + "The returned name at invalid index 3 should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_name(-1) == "", + "The returned name at invalid index -1 should match the expected value."); + ERR_PRINT_ON; + + CHECK_MESSAGE( + node_path_relative.get_name_count() == 3, + "The returned number of names should match the expected value."); + + CHECK_MESSAGE( + node_path_relative.get_subname(0) == "position", + "The returned subname at index 0 should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_subname(1) == "x", + "The returned subname at index 1 should match the expected value."); + ERR_PRINT_OFF; + CHECK_MESSAGE( + node_path_relative.get_subname(2) == "", + "The returned subname at invalid index 2 should match the expected value."); + CHECK_MESSAGE( + node_path_relative.get_subname(-1) == "", + "The returned subname at invalid index -1 should match the expected value."); + ERR_PRINT_ON; + + CHECK_MESSAGE( + node_path_relative.get_subname_count() == 2, + "The returned number of subnames should match the expected value."); + + CHECK_MESSAGE( + !node_path_relative.is_absolute(), + "The node path should be considered relative."); + + CHECK_MESSAGE( + !node_path_relative.is_empty(), + "The node path shouldn't be considered empty."); +} + +TEST_CASE("[NodePath] Absolute path") { + const NodePath node_path_aboslute = NodePath("/root/Sprite2D"); + + CHECK_MESSAGE( + node_path_aboslute.get_as_property_path() == NodePath(":root/Sprite2D"), + "The returned property path should match the expected value."); + CHECK_MESSAGE( + node_path_aboslute.get_concatenated_subnames() == "", + "The returned concatenated subnames should match the expected value."); + + CHECK_MESSAGE( + node_path_aboslute.get_name(0) == "root", + "The returned name at index 0 should match the expected value."); + CHECK_MESSAGE( + node_path_aboslute.get_name(1) == "Sprite2D", + "The returned name at index 1 should match the expected value."); + ERR_PRINT_OFF; + CHECK_MESSAGE( + node_path_aboslute.get_name(2) == "", + "The returned name at invalid index 2 should match the expected value."); + CHECK_MESSAGE( + node_path_aboslute.get_name(-1) == "", + "The returned name at invalid index -1 should match the expected value."); + ERR_PRINT_ON; + + CHECK_MESSAGE( + node_path_aboslute.get_name_count() == 2, + "The returned number of names should match the expected value."); + + CHECK_MESSAGE( + node_path_aboslute.get_subname_count() == 0, + "The returned number of subnames should match the expected value."); + + CHECK_MESSAGE( + node_path_aboslute.is_absolute(), + "The node path should be considered absolute."); + + CHECK_MESSAGE( + !node_path_aboslute.is_empty(), + "The node path shouldn't be considered empty."); +} + +TEST_CASE("[NodePath] Empty path") { + const NodePath node_path_empty = NodePath(); + + CHECK_MESSAGE( + node_path_empty.get_as_property_path() == NodePath(), + "The returned property path should match the expected value."); + ERR_PRINT_OFF; + CHECK_MESSAGE( + node_path_empty.get_concatenated_subnames() == "", + "The returned concatenated subnames should match the expected value."); + ERR_PRINT_ON; + + CHECK_MESSAGE( + node_path_empty.get_name_count() == 0, + "The returned number of names should match the expected value."); + + CHECK_MESSAGE( + node_path_empty.get_subname_count() == 0, + "The returned number of subnames should match the expected value."); + + CHECK_MESSAGE( + !node_path_empty.is_absolute(), + "The node path shouldn't be considered absolute."); + + CHECK_MESSAGE( + node_path_empty.is_empty(), + "The node path should be considered empty."); +} +} // namespace TestNodePath + +#endif // TEST_NODE_PATH_H diff --git a/tests/test_oa_hash_map.cpp b/tests/test_oa_hash_map.cpp index 44717e5690..b0bb01bc71 100644 --- a/tests/test_oa_hash_map.cpp +++ b/tests/test_oa_hash_map.cpp @@ -295,5 +295,4 @@ MainLoop *test() { return nullptr; } - } // namespace TestOAHashMap diff --git a/tests/test_ordered_hash_map.h b/tests/test_ordered_hash_map.h index 9f987e8833..ef26d2531b 100644 --- a/tests/test_ordered_hash_map.h +++ b/tests/test_ordered_hash_map.h @@ -133,7 +133,6 @@ TEST_CASE("[OrderedHashMap] Const iteration") { ++idx; } } - } // namespace TestOrderedHashMap #endif // TEST_ORDERED_HASH_MAP_H diff --git a/tests/test_pck_packer.h b/tests/test_pck_packer.h new file mode 100644 index 0000000000..e086d65105 --- /dev/null +++ b/tests/test_pck_packer.h @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* test_pck_packer.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* 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_PCK_PACKER_H +#define TEST_PCK_PACKER_H + +#include "core/io/file_access_pack.h" +#include "core/io/pck_packer.h" +#include "core/os/os.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestPCKPacker { + +// Dummy 64-character encryption key (since it's required). +constexpr const char *ENCRYPTION_KEY = "0000000000000000000000000000000000000000000000000000000000000000"; + +TEST_CASE("[PCKPacker] Pack an empty PCK file") { + PCKPacker pck_packer; + const String output_pck_path = OS::get_singleton()->get_cache_path().plus_file("output_empty.pck"); + CHECK_MESSAGE( + pck_packer.pck_start( + output_pck_path, + 32, + ENCRYPTION_KEY) == OK, + "Starting a PCK file should return an OK error code."); + + CHECK_MESSAGE( + pck_packer.flush() == OK, + "Flushing the PCK should return an OK error code."); + + Error err; + FileAccessRef f = FileAccess::open(output_pck_path, FileAccess::READ, &err); + CHECK_MESSAGE( + err == OK, + "The generated empty PCK file should be opened successfully."); + CHECK_MESSAGE( + f->get_len() >= 100, + "The generated empty PCK file shouldn't be too small (it should have the PCK header)."); + CHECK_MESSAGE( + f->get_len() <= 500, + "The generated empty PCK file shouldn't be too large."); +} + +TEST_CASE("[PCKPacker] Pack a PCK file with some files and directories") { + PCKPacker pck_packer; + const String output_pck_path = OS::get_singleton()->get_cache_path().plus_file("output_with_files.pck"); + CHECK_MESSAGE( + pck_packer.pck_start( + output_pck_path, + 32, + ENCRYPTION_KEY) == OK, + "Starting a PCK file should return an OK error code."); + + const String base_dir = OS::get_singleton()->get_executable_path().get_base_dir(); + + CHECK_MESSAGE( + pck_packer.add_file("version.py", base_dir.plus_file("../version.py"), "version.py") == OK, + "Adding a file to the PCK should return an OK error code."); + CHECK_MESSAGE( + pck_packer.add_file("some/directories with spaces/to/create/icon.png", base_dir.plus_file("../icon.png")) == OK, + "Adding a file to a new subdirectory in the PCK should return an OK error code."); + CHECK_MESSAGE( + pck_packer.add_file("some/directories with spaces/to/create/icon.svg", base_dir.plus_file("../icon.svg")) == OK, + "Adding a file to an existing subdirectory in the PCK should return an OK error code."); + CHECK_MESSAGE( + pck_packer.add_file("some/directories with spaces/to/create/icon.png", base_dir.plus_file("../logo.png")) == OK, + "Overriding a non-flushed file to an existing subdirectory in the PCK should return an OK error code."); + CHECK_MESSAGE( + pck_packer.flush() == OK, + "Flushing the PCK should return an OK error code."); + + Error err; + FileAccessRef f = FileAccess::open(output_pck_path, FileAccess::READ, &err); + CHECK_MESSAGE( + err == OK, + "The generated non-empty PCK file should be opened successfully."); + CHECK_MESSAGE( + f->get_len() >= 25000, + "The generated non-empty PCK file should be large enough to actually hold the contents specified above."); + CHECK_MESSAGE( + f->get_len() <= 35000, + "The generated non-empty PCK file shouldn't be too large."); +} +} // namespace TestPCKPacker + +#endif // TEST_PCK_PACKER_H diff --git a/tests/test_physics_2d.cpp b/tests/test_physics_2d.cpp index 54d373b454..d40df52f1b 100644 --- a/tests/test_physics_2d.cpp +++ b/tests/test_physics_2d.cpp @@ -403,5 +403,4 @@ namespace TestPhysics2D { MainLoop *test() { return memnew(TestPhysics2DMainLoop); } - } // namespace TestPhysics2D diff --git a/tests/test_physics_3d.cpp b/tests/test_physics_3d.cpp index 1b453be76d..5f84b2eb50 100644 --- a/tests/test_physics_3d.cpp +++ b/tests/test_physics_3d.cpp @@ -409,5 +409,4 @@ namespace TestPhysics3D { MainLoop *test() { return memnew(TestPhysics3DMainLoop); } - } // namespace TestPhysics3D diff --git a/tests/test_render.cpp b/tests/test_render.cpp index 8c5cac694c..d14251bc6a 100644 --- a/tests/test_render.cpp +++ b/tests/test_render.cpp @@ -98,7 +98,6 @@ public: } }*/ /*for(int i=0;i<100;i++) { - vts.push_back( Vector3(Math::randf()*2-1.0,Math::randf()*2-1.0,Math::randf()*2-1.0).normalized()*2); }*/ /* @@ -216,7 +215,6 @@ public: vs->instance_set_transform(E->get().instance, pre * E->get().base); /* if( !E->next() ) { - vs->free( E->get().instance ); instances.erase(E ); }*/ @@ -236,5 +234,4 @@ public: MainLoop *test() { return memnew(TestMainLoop); } - } // namespace TestRender diff --git a/tests/test_shader_lang.cpp b/tests/test_shader_lang.cpp index 4bfd593279..e79c83b001 100644 --- a/tests/test_shader_lang.cpp +++ b/tests/test_shader_lang.cpp @@ -357,5 +357,4 @@ MainLoop *test() { return nullptr; } - } // namespace TestShaderLang diff --git a/tests/test_string.h b/tests/test_string.h index acdcaccecd..48132cb278 100644 --- a/tests/test_string.h +++ b/tests/test_string.h @@ -1296,7 +1296,6 @@ TEST_CASE("[String] humanize_size") { CHECK(String::humanize_size(100523550) == "95.86 MiB"); CHECK(String::humanize_size(5345555000) == "4.97 GiB"); } - } // namespace TestString #endif // TEST_STRING_H diff --git a/tests/test_variant.h b/tests/test_variant.h index b7421c29a5..b575f6744d 100644 --- a/tests/test_variant.h +++ b/tests/test_variant.h @@ -105,7 +105,6 @@ TEST_CASE("[Variant] Writer and parser float") { CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should not overflow."); } - } // namespace TestVariant #endif // TEST_VARIANT_H |