diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core/io/test_image.h | 4 | ||||
-rw-r--r-- | tests/core/io/test_pck_packer.h | 8 | ||||
-rw-r--r-- | tests/core/io/test_resource.h | 8 | ||||
-rw-r--r-- | tests/core/math/test_vector2.h | 4 | ||||
-rw-r--r-- | tests/core/math/test_vector3.h | 4 | ||||
-rw-r--r-- | tests/core/object/test_class_db.h | 2 | ||||
-rw-r--r-- | tests/core/os/test_os.h | 2 | ||||
-rw-r--r-- | tests/core/variant/test_array.h | 37 | ||||
-rw-r--r-- | tests/scene/test_audio_stream_wav.h | 6 | ||||
-rw-r--r-- | tests/scene/test_code_edit.h | 159 | ||||
-rw-r--r-- | tests/scene/test_image_texture_3d.h | 101 | ||||
-rw-r--r-- | tests/scene/test_instance_placeholder.h | 10 | ||||
-rw-r--r-- | tests/scene/test_node.h | 65 | ||||
-rw-r--r-- | tests/servers/test_navigation_server_3d.h | 6 | ||||
-rw-r--r-- | tests/test_main.cpp | 1 | ||||
-rw-r--r-- | tests/test_utils.cpp | 7 | ||||
-rw-r--r-- | tests/test_utils.h | 1 |
17 files changed, 400 insertions, 25 deletions
diff --git a/tests/core/io/test_image.h b/tests/core/io/test_image.h index 7a0cbb13f9..1b51286a9f 100644 --- a/tests/core/io/test_image.h +++ b/tests/core/io/test_image.h @@ -78,8 +78,8 @@ TEST_CASE("[Image] Instantiation") { TEST_CASE("[Image] Saving and loading") { Ref<Image> image = memnew(Image(4, 4, false, Image::FORMAT_RGBA8)); - const String save_path_png = OS::get_singleton()->get_cache_path().path_join("image.png"); - const String save_path_exr = OS::get_singleton()->get_cache_path().path_join("image.exr"); + const String save_path_png = TestUtils::get_temp_path("image.png"); + const String save_path_exr = TestUtils::get_temp_path("image.exr"); // Save PNG Error err; diff --git a/tests/core/io/test_pck_packer.h b/tests/core/io/test_pck_packer.h index fc4534a949..7ef9451963 100644 --- a/tests/core/io/test_pck_packer.h +++ b/tests/core/io/test_pck_packer.h @@ -42,7 +42,7 @@ namespace TestPCKPacker { TEST_CASE("[PCKPacker] Pack an empty PCK file") { PCKPacker pck_packer; - const String output_pck_path = OS::get_singleton()->get_cache_path().path_join("output_empty.pck"); + const String output_pck_path = TestUtils::get_temp_path("output_empty.pck"); CHECK_MESSAGE( pck_packer.pck_start(output_pck_path) == OK, "Starting a PCK file should return an OK error code."); @@ -66,7 +66,7 @@ TEST_CASE("[PCKPacker] Pack an empty PCK file") { TEST_CASE("[PCKPacker] Pack empty with zero alignment invalid") { PCKPacker pck_packer; - const String output_pck_path = OS::get_singleton()->get_cache_path().path_join("output_empty.pck"); + const String output_pck_path = TestUtils::get_temp_path("output_empty.pck"); ERR_PRINT_OFF; CHECK_MESSAGE(pck_packer.pck_start(output_pck_path, 0) != OK, "PCK with zero alignment should fail."); ERR_PRINT_ON; @@ -74,7 +74,7 @@ TEST_CASE("[PCKPacker] Pack empty with zero alignment invalid") { TEST_CASE("[PCKPacker] Pack empty with invalid key") { PCKPacker pck_packer; - const String output_pck_path = OS::get_singleton()->get_cache_path().path_join("output_empty.pck"); + const String output_pck_path = TestUtils::get_temp_path("output_empty.pck"); ERR_PRINT_OFF; CHECK_MESSAGE(pck_packer.pck_start(output_pck_path, 32, "") != OK, "PCK with invalid key should fail."); ERR_PRINT_ON; @@ -82,7 +82,7 @@ TEST_CASE("[PCKPacker] Pack empty with invalid key") { 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().path_join("output_with_files.pck"); + const String output_pck_path = TestUtils::get_temp_path("output_with_files.pck"); CHECK_MESSAGE( pck_packer.pck_start(output_pck_path) == OK, "Starting a PCK file should return an OK error code."); diff --git a/tests/core/io/test_resource.h b/tests/core/io/test_resource.h index a83e7f88ba..cb1fa290b3 100644 --- a/tests/core/io/test_resource.h +++ b/tests/core/io/test_resource.h @@ -76,8 +76,8 @@ TEST_CASE("[Resource] Saving and loading") { Ref<Resource> child_resource = memnew(Resource); child_resource->set_name("I'm a child resource"); resource->set_meta("other_resource", child_resource); - const String save_path_binary = OS::get_singleton()->get_cache_path().path_join("resource.res"); - const String save_path_text = OS::get_singleton()->get_cache_path().path_join("resource.tres"); + const String save_path_binary = TestUtils::get_temp_path("resource.res"); + const String save_path_text = TestUtils::get_temp_path("resource.tres"); ResourceSaver::save(resource, save_path_binary); ResourceSaver::save(resource, save_path_text); @@ -123,8 +123,8 @@ TEST_CASE("[Resource] Breaking circular references on save") { resource_b->set_meta("next", resource_c); resource_c->set_meta("next", resource_b); - const String save_path_binary = OS::get_singleton()->get_cache_path().path_join("resource.res"); - const String save_path_text = OS::get_singleton()->get_cache_path().path_join("resource.tres"); + const String save_path_binary = TestUtils::get_temp_path("resource.res"); + const String save_path_text = TestUtils::get_temp_path("resource.tres"); ResourceSaver::save(resource_a, save_path_binary); // Suppress expected errors caused by the resources above being uncached. ERR_PRINT_OFF; diff --git a/tests/core/math/test_vector2.h b/tests/core/math/test_vector2.h index fc3fd6a87d..7bd494ec80 100644 --- a/tests/core/math/test_vector2.h +++ b/tests/core/math/test_vector2.h @@ -353,7 +353,6 @@ TEST_CASE("[Vector2] Plane methods") { const Vector2 vector = Vector2(1.2, 3.4); const Vector2 vector_y = Vector2(0, 1); const Vector2 vector_normal = Vector2(0.95879811270838721622267, 0.2840883296913739899919); - const Vector2 vector_non_normal = Vector2(5.4, 1.6); const real_t p_d = 99.1; CHECK_MESSAGE( vector.bounce(vector_y) == Vector2(1.2, -3.4), @@ -383,6 +382,8 @@ TEST_CASE("[Vector2] Plane methods") { vector.slide(vector_normal).is_equal_approx(Vector2(-0.8292559899117276166456, 2.798738965952080706179)), "Vector2 slide with normal should return expected value."); // There's probably a better way to test these ones? +#ifdef MATH_CHECKS + const Vector2 vector_non_normal = Vector2(5.4, 1.6); ERR_PRINT_OFF; CHECK_MESSAGE( vector.bounce(vector_non_normal).is_equal_approx(Vector2()), @@ -394,6 +395,7 @@ TEST_CASE("[Vector2] Plane methods") { vector.slide(vector_non_normal).is_equal_approx(Vector2()), "Vector2 slide should return empty Vector2 with non-normalized input."); ERR_PRINT_ON; +#endif // MATH_CHECKS } TEST_CASE("[Vector2] Rounding methods") { diff --git a/tests/core/math/test_vector3.h b/tests/core/math/test_vector3.h index ca0aa02882..4cab753d6f 100644 --- a/tests/core/math/test_vector3.h +++ b/tests/core/math/test_vector3.h @@ -368,7 +368,6 @@ TEST_CASE("[Vector3] Plane methods") { const Vector3 vector = Vector3(1.2, 3.4, 5.6); const Vector3 vector_y = Vector3(0, 1, 0); const Vector3 vector_normal = Vector3(0.88763458893247992491, 0.26300284116517923701, 0.37806658417494515320); - const Vector3 vector_non_normal = Vector3(5.4, 1.6, 2.3); CHECK_MESSAGE( vector.bounce(vector_y) == Vector3(1.2, -3.4, 5.6), "Vector3 bounce on a plane with normal of the Y axis should."); @@ -394,6 +393,8 @@ TEST_CASE("[Vector3] Plane methods") { vector.slide(vector_normal).is_equal_approx(Vector3(-2.41848149148878681437, 2.32785733585517427722237, 4.0587949202918130235)), "Vector3 slide with normal should return expected value."); // There's probably a better way to test these ones? +#ifdef MATH_CHECKS + const Vector3 vector_non_normal = Vector3(5.4, 1.6, 2.3); ERR_PRINT_OFF; CHECK_MESSAGE( vector.bounce(vector_non_normal).is_equal_approx(Vector3()), @@ -405,6 +406,7 @@ TEST_CASE("[Vector3] Plane methods") { vector.slide(vector_non_normal).is_equal_approx(Vector3()), "Vector3 slide should return empty Vector3 with non-normalized input."); ERR_PRINT_ON; +#endif // MATH_CHECKS } TEST_CASE("[Vector3] Rounding methods") { diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h index 381d759e5b..358bbc08a3 100644 --- a/tests/core/object/test_class_db.h +++ b/tests/core/object/test_class_db.h @@ -375,8 +375,10 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co } void validate_argument(const Context &p_context, const ExposedClass &p_class, const String &p_owner_name, const String &p_owner_type, const ArgumentData &p_arg) { +#ifdef DEBUG_METHODS_ENABLED TEST_COND((p_arg.name.is_empty() || p_arg.name.begins_with("_unnamed_arg")), vformat("Unnamed argument in position %d of %s '%s.%s'.", p_arg.position, p_owner_type, p_class.name, p_owner_name)); +#endif // DEBUG_METHODS_ENABLED const ExposedClass *arg_class = p_context.find_exposed_class(p_arg.type); if (arg_class) { diff --git a/tests/core/os/test_os.h b/tests/core/os/test_os.h index 6ee0ff82e7..1e2f5e222b 100644 --- a/tests/core/os/test_os.h +++ b/tests/core/os/test_os.h @@ -163,12 +163,14 @@ TEST_CASE("[OS] Processor count and memory information") { CHECK_MESSAGE( OS::get_singleton()->get_processor_count() >= 1, "The returned processor count should be greater than zero."); +#ifdef DEBUG_ENABLED CHECK_MESSAGE( OS::get_singleton()->get_static_memory_usage() >= 1, "The returned static memory usage should be greater than zero."); CHECK_MESSAGE( OS::get_singleton()->get_static_memory_peak_usage() >= 1, "The returned static memory peak usage should be greater than zero."); +#endif // DEBUG_ENABLED } TEST_CASE("[OS] Execute") { diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h index c54854e4d7..787b8f39d9 100644 --- a/tests/core/variant/test_array.h +++ b/tests/core/variant/test_array.h @@ -597,6 +597,43 @@ TEST_CASE("[Array] Iteration and modification") { a4.clear(); } +TEST_CASE("[Array] Typed copying") { + TypedArray<int> a1; + a1.push_back(1); + + TypedArray<double> a2; + a2.push_back(1.0); + + Array a3 = a1; + TypedArray<int> a4 = a3; + + Array a5 = a2; + TypedArray<int> a6 = a5; + + a3[0] = 2; + a4[0] = 3; + + // Same typed TypedArray should be shared. + CHECK_EQ(a1[0], Variant(3)); + CHECK_EQ(a3[0], Variant(3)); + CHECK_EQ(a4[0], Variant(3)); + + a5[0] = 2.0; + a6[0] = 3.0; + + // Different typed TypedArray should not be shared. + CHECK_EQ(a2[0], Variant(2.0)); + CHECK_EQ(a5[0], Variant(2.0)); + CHECK_EQ(a6[0], Variant(3.0)); + + a1.clear(); + a2.clear(); + a3.clear(); + a4.clear(); + a5.clear(); + a6.clear(); +} + } // namespace TestArray #endif // TEST_ARRAY_H diff --git a/tests/scene/test_audio_stream_wav.h b/tests/scene/test_audio_stream_wav.h index ed1697929e..e8f3c9e8f5 100644 --- a/tests/scene/test_audio_stream_wav.h +++ b/tests/scene/test_audio_stream_wav.h @@ -115,7 +115,7 @@ Vector<uint8_t> gen_pcm16_test(float wav_rate, int wav_count, bool stereo) { } void run_test(String file_name, AudioStreamWAV::Format data_format, bool stereo, float wav_rate, float wav_count) { - String save_path = OS::get_singleton()->get_cache_path().path_join(file_name); + String save_path = TestUtils::get_temp_path(file_name); Vector<uint8_t> test_data; if (data_format == AudioStreamWAV::FORMAT_8_BITS) { @@ -200,7 +200,7 @@ TEST_CASE("[AudioStreamWAV] Alternate mix rate") { } TEST_CASE("[AudioStreamWAV] save_to_wav() adds '.wav' file extension automatically") { - String save_path = OS::get_singleton()->get_cache_path().path_join("test_wav_extension"); + String save_path = TestUtils::get_temp_path("test_wav_extension"); Vector<uint8_t> test_data = gen_pcm8_test(WAV_RATE, WAV_COUNT, false); Ref<AudioStreamWAV> stream = memnew(AudioStreamWAV); stream->set_data(test_data); @@ -230,7 +230,7 @@ TEST_CASE("[AudioStreamWAV] Save empty file") { } TEST_CASE("[AudioStreamWAV] Saving IMA ADPCM is not supported") { - String save_path = OS::get_singleton()->get_cache_path().path_join("test_adpcm.wav"); + String save_path = TestUtils::get_temp_path("test_adpcm.wav"); Ref<AudioStreamWAV> stream = memnew(AudioStreamWAV); stream->set_format(AudioStreamWAV::FORMAT_IMA_ADPCM); ERR_PRINT_OFF; diff --git a/tests/scene/test_code_edit.h b/tests/scene/test_code_edit.h index c02830b6df..a166002cdd 100644 --- a/tests/scene/test_code_edit.h +++ b/tests/scene/test_code_edit.h @@ -3331,6 +3331,45 @@ TEST_CASE("[SceneTree][CodeEdit] folding") { CHECK_FALSE(code_edit->is_line_folded(1)); } + SUBCASE("[CodeEdit] actions unfold") { + // add_selection_for_next_occurrence unfolds. + code_edit->set_text("test\n\tline1 test\n\t\tline 2\ntest2"); + code_edit->select(0, 0, 0, 4); + code_edit->fold_line(0); + CHECK(code_edit->is_line_folded(0)); + code_edit->add_selection_for_next_occurrence(); + + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 0); + CHECK(code_edit->get_selection_origin_line() == 0); + CHECK(code_edit->get_caret_column() == 4); + CHECK(code_edit->get_selection_origin_column() == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_caret_line(1) == 1); + CHECK(code_edit->get_selection_origin_line(1) == 1); + CHECK(code_edit->get_caret_column(1) == 11); + CHECK(code_edit->get_selection_origin_column(1) == 7); + CHECK_FALSE(code_edit->is_line_folded(0)); + code_edit->remove_secondary_carets(); + + // skip_selection_for_next_occurrence unfolds. + code_edit->select(0, 0, 0, 4); + code_edit->fold_line(0); + CHECK(code_edit->is_line_folded(0)); + code_edit->skip_selection_for_next_occurrence(); + + CHECK(code_edit->get_caret_count() == 1); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 1); + CHECK(code_edit->get_selection_origin_line() == 1); + CHECK(code_edit->get_caret_column() == 11); + CHECK(code_edit->get_selection_origin_column() == 7); + CHECK_FALSE(code_edit->is_line_folded(0)); + code_edit->remove_secondary_carets(); + code_edit->deselect(); + } + SUBCASE("[CodeEdit] toggle folding carets") { code_edit->set_text("test\n\tline1\ntest2\n\tline2"); @@ -4850,6 +4889,17 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_caret_line() == 0); CHECK(code_edit->get_caret_column() == 1); + // Does nothing at the first line when selection ends at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(0, 0, 1, 0); + code_edit->move_lines_up(); + CHECK(code_edit->get_text() == "test\nlines\nto\n\nmove\naround"); + CHECK(code_edit->has_selection()); + CHECK(code_edit->get_selection_origin_line() == 0); + CHECK(code_edit->get_selection_origin_column() == 0); + CHECK(code_edit->get_caret_line() == 1); + CHECK(code_edit->get_caret_column() == 0); + // Works on empty line. code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->set_caret_line(3); @@ -4911,9 +4961,9 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK_FALSE(code_edit->has_selection(2)); CHECK(code_edit->get_caret_line(2) == 3); CHECK(code_edit->get_caret_column(2) == 4); + code_edit->remove_secondary_carets(); // Move multiple separate lines with multiple selections. - code_edit->remove_secondary_carets(); code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->select(2, 2, 1, 4); code_edit->add_caret(5, 0); @@ -4931,6 +4981,44 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_selection_origin_column(1) == 0); CHECK(code_edit->get_caret_line(1) == 4); CHECK(code_edit->get_caret_column(1) == 1); + code_edit->remove_secondary_carets(); + + // Move lines with adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(1, 2, 2, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 2, 3, 0, 1); + code_edit->move_lines_up(); + CHECK(code_edit->get_text() == "lines\nto\ntest\n\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 0); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 1); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 1); + CHECK(code_edit->get_selection_origin_column(1) == 2); + CHECK(code_edit->get_caret_line(1) == 2); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + code_edit->deselect(); + + code_edit->set_line_folding_enabled(true); + + // Move line up into a folded region unfolds it. + code_edit->set_text("test\n\tline1 test\n\t\tline 2\ntest2"); + code_edit->set_caret_line(3); + code_edit->set_caret_column(0); + code_edit->fold_line(0); + CHECK(code_edit->is_line_folded(0)); + code_edit->move_lines_up(); + CHECK(code_edit->get_caret_count() == 1); + CHECK_FALSE(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 2); + CHECK(code_edit->get_caret_column() == 0); + CHECK(code_edit->get_text() == "test\n\tline1 test\ntest2\n\t\tline 2"); + CHECK_FALSE(code_edit->is_line_folded(0)); } SUBCASE("[SceneTree][CodeEdit] move lines down") { @@ -4965,6 +5053,17 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_caret_line() == 5); CHECK(code_edit->get_caret_column() == 1); + // Does nothing at the last line when selection ends at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(4, 0, 5, 0); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "test\nlines\nto\n\nmove\naround"); + CHECK(code_edit->has_selection()); + CHECK(code_edit->get_selection_origin_line() == 4); + CHECK(code_edit->get_selection_origin_column() == 0); + CHECK(code_edit->get_caret_line() == 5); + CHECK(code_edit->get_caret_column() == 0); + // Works on empty line. code_edit->set_text("test\nlines\nto\n\nmove\naround"); code_edit->set_caret_line(3); @@ -5046,6 +5145,64 @@ TEST_CASE("[SceneTree][CodeEdit] text manipulation") { CHECK(code_edit->get_selection_origin_column(1) == 0); CHECK(code_edit->get_caret_line(1) == 5); CHECK(code_edit->get_caret_column(1) == 2); + + // Move lines with adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(1, 2, 2, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 2, 3, 0, 1); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "test\n\nlines\nto\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 2); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 3); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 3); + CHECK(code_edit->get_selection_origin_column(1) == 2); + CHECK(code_edit->get_caret_line(1) == 4); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + + // Move lines with disconnected adjacent selections that end at column 0. + code_edit->set_text("test\nlines\nto\n\nmove\naround"); + code_edit->select(0, 2, 1, 0); + code_edit->add_caret(2, 2); + code_edit->select(2, 0, 3, 0, 1); + code_edit->move_lines_down(); + CHECK(code_edit->get_text() == "lines\ntest\n\nto\nmove\naround"); + CHECK(code_edit->get_caret_count() == 2); + CHECK(code_edit->has_selection(0)); + CHECK(code_edit->get_selection_origin_line(0) == 1); + CHECK(code_edit->get_selection_origin_column(0) == 2); + CHECK(code_edit->get_caret_line(0) == 2); + CHECK(code_edit->get_caret_column(0) == 0); + CHECK(code_edit->has_selection(1)); + CHECK(code_edit->get_selection_origin_line(1) == 3); + CHECK(code_edit->get_selection_origin_column(1) == 0); + CHECK(code_edit->get_caret_line(1) == 4); + CHECK(code_edit->get_caret_column(1) == 0); + code_edit->remove_secondary_carets(); + code_edit->deselect(); + + code_edit->set_line_folding_enabled(true); + + // Move line down into a folded region unfolds it. + code_edit->set_text("test\ntest2\n\tline1 test\n\t\tline 2\ntest2"); + code_edit->set_caret_line(0); + code_edit->set_caret_column(0); + code_edit->fold_line(1); + CHECK(code_edit->is_line_folded(1)); + code_edit->move_lines_down(); + CHECK(code_edit->get_caret_count() == 1); + CHECK_FALSE(code_edit->has_selection(0)); + CHECK(code_edit->get_caret_line() == 1); + CHECK(code_edit->get_caret_column() == 0); + CHECK(code_edit->get_text() == "test2\ntest\n\tline1 test\n\t\tline 2\ntest2"); + CHECK_FALSE(code_edit->is_line_folded(0)); + CHECK_FALSE(code_edit->is_line_folded(1)); } SUBCASE("[SceneTree][CodeEdit] delete lines") { diff --git a/tests/scene/test_image_texture_3d.h b/tests/scene/test_image_texture_3d.h new file mode 100644 index 0000000000..f2a7abcf69 --- /dev/null +++ b/tests/scene/test_image_texture_3d.h @@ -0,0 +1,101 @@ +/**************************************************************************/ +/* test_image_texture_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_IMAGE_TEXTURE_3D_H +#define TEST_IMAGE_TEXTURE_3D_H + +#include "core/io/image.h" +#include "scene/resources/image_texture.h" + +#include "tests/test_macros.h" +#include "tests/test_utils.h" + +namespace TestImageTexture3D { + +// [SceneTree] in a test case name enables initializing a mock render server, +// which ImageTexture3D is dependent on. +TEST_CASE("[SceneTree][ImageTexture3D] Constructor") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->get_format() == Image::FORMAT_L8); + CHECK(image_texture_3d->get_width() == 1); + CHECK(image_texture_3d->get_height() == 1); + CHECK(image_texture_3d->get_depth() == 1); + CHECK(image_texture_3d->has_mipmaps() == false); +} + +TEST_CASE("[SceneTree][ImageTexture3D] get_format") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->get_format() == Image::FORMAT_L8); +} + +TEST_CASE("[SceneTree][ImageTexture3D] get_width") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->get_width() == 1); +} + +TEST_CASE("[SceneTree][ImageTexture3D] get_height") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->get_height() == 1); +} + +TEST_CASE("[SceneTree][ImageTexture3D] get_depth") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->get_depth() == 1); +} + +TEST_CASE("[SceneTree][ImageTexture3D] has_mipmaps") { + const Vector<Ref<Image>> images = { memnew(Image(8, 8, false, Image::FORMAT_RGBA8)), memnew(Image(8, 8, false, Image::FORMAT_RGBA8)) }; + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->has_mipmaps() == false); // No mipmaps. + image_texture_3d->create(Image::FORMAT_RGBA8, 2, 2, 2, true, images); + CHECK(image_texture_3d->has_mipmaps() == true); // Mipmaps. +} + +TEST_CASE("[SceneTree][ImageTexture3D] create") { + const Vector<Ref<Image>> images = { memnew(Image(8, 8, false, Image::FORMAT_RGBA8)), memnew(Image(8, 8, false, Image::FORMAT_RGBA8)) }; + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + CHECK(image_texture_3d->create(Image::FORMAT_RGBA8, 2, 2, 2, true, images) == OK); // Run create and check return value simultaneously. + CHECK(image_texture_3d->get_format() == Image::FORMAT_RGBA8); + CHECK(image_texture_3d->get_width() == 2); + CHECK(image_texture_3d->get_height() == 2); + CHECK(image_texture_3d->get_depth() == 2); + CHECK(image_texture_3d->has_mipmaps() == true); +} + +TEST_CASE("[SceneTree][ImageTexture3D] set_path") { + Ref<ImageTexture3D> image_texture_3d = memnew(ImageTexture3D); + String path = TestUtils::get_data_path("images/icon.png"); + image_texture_3d->set_path(path, true); + CHECK(image_texture_3d->get_path() == path); +} + +} //namespace TestImageTexture3D + +#endif // TEST_IMAGE_TEXTURE_3D_H diff --git a/tests/scene/test_instance_placeholder.h b/tests/scene/test_instance_placeholder.h index 8e8cf7c9df..17f2151d54 100644 --- a/tests/scene/test_instance_placeholder.h +++ b/tests/scene/test_instance_placeholder.h @@ -333,6 +333,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instantiate from placeholder with ov } } +#ifdef TOOLS_ENABLED TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an InstancePlaceholder with no overrides") { GDREGISTER_CLASS(_TestInstancePlaceholderNode); @@ -350,7 +351,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an Error err = internal_scene->pack(internal); REQUIRE(err == OK); - const String internal_path = OS::get_singleton()->get_cache_path().path_join("instance_placeholder_test_internal.tscn"); + const String internal_path = TestUtils::get_temp_path("instance_placeholder_test_internal.tscn"); err = ResourceSaver::save(internal_scene, internal_path); REQUIRE(err == OK); @@ -379,7 +380,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an err = main_scene->pack(root); REQUIRE(err == OK); - const String main_path = OS::get_singleton()->get_cache_path().path_join("instance_placeholder_test_main.tscn"); + const String main_path = TestUtils::get_temp_path("instance_placeholder_test_main.tscn"); err = ResourceSaver::save(main_scene, main_path); REQUIRE(err == OK); @@ -439,7 +440,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an Error err = internal_scene->pack(internal); REQUIRE(err == OK); - const String internal_path = OS::get_singleton()->get_cache_path().path_join("instance_placeholder_test_internal_override.tscn"); + const String internal_path = TestUtils::get_temp_path("instance_placeholder_test_internal_override.tscn"); err = ResourceSaver::save(internal_scene, internal_path); REQUIRE(err == OK); @@ -480,7 +481,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an err = main_scene->pack(root); REQUIRE(err == OK); - const String main_path = OS::get_singleton()->get_cache_path().path_join("instance_placeholder_test_main_override.tscn"); + const String main_path = TestUtils::get_temp_path("instance_placeholder_test_main_override.tscn"); err = ResourceSaver::save(main_scene, main_path); REQUIRE(err == OK); @@ -526,6 +527,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an DirAccess::remove_file_or_error(internal_path); DirAccess::remove_file_or_error(main_path); } +#endif // TOOLS_ENABLED } //namespace TestInstancePlaceholder diff --git a/tests/scene/test_node.h b/tests/scene/test_node.h index 2b14be76e2..e387c73f9f 100644 --- a/tests/scene/test_node.h +++ b/tests/scene/test_node.h @@ -68,6 +68,10 @@ protected: ClassDB::bind_method(D_METHOD("set_exported_node", "node"), &TestNode::set_exported_node); ClassDB::bind_method(D_METHOD("get_exported_node"), &TestNode::get_exported_node); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "exported_node", PROPERTY_HINT_NODE_TYPE, "Node"), "set_exported_node", "get_exported_node"); + + ClassDB::bind_method(D_METHOD("set_exported_nodes", "node"), &TestNode::set_exported_nodes); + ClassDB::bind_method(D_METHOD("get_exported_nodes"), &TestNode::get_exported_nodes); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exported_nodes", PROPERTY_HINT_TYPE_STRING, "24/34:Node"), "set_exported_nodes", "get_exported_nodes"); } private: @@ -84,11 +88,15 @@ public: int physics_process_counter = 0; Node *exported_node = nullptr; + Array exported_nodes; List<Node *> *callback_list = nullptr; void set_exported_node(Node *p_node) { exported_node = p_node; } Node *get_exported_node() const { return exported_node; } + + void set_exported_nodes(const Array &p_nodes) { exported_nodes = p_nodes; } + Array get_exported_nodes() const { return exported_nodes; } }; TEST_CASE("[SceneTree][Node] Testing node operations with a very simple scene tree") { @@ -500,7 +508,16 @@ TEST_CASE("[SceneTree][Node]Exported node checks") { node->add_child(child); child->set_owner(node); + Node *child2 = memnew(Node); + child2->set_name("Child2"); + node->add_child(child2); + child2->set_owner(node); + + Array children; + children.append(child); + node->set("exported_node", child); + node->set("exported_nodes", children); SUBCASE("Property of duplicated node should point to duplicated child") { GDREGISTER_CLASS(TestNode); @@ -512,13 +529,13 @@ TEST_CASE("[SceneTree][Node]Exported node checks") { memdelete(dup); } - SUBCASE("Saving instance with exported node should not store the unchanged property") { - node->set_process_mode(Node::PROCESS_MODE_ALWAYS); +#ifdef TOOLS_ENABLED + SUBCASE("Saving instance with exported nodes should not store the unchanged property") { Ref<PackedScene> ps; ps.instantiate(); ps->pack(node); - String scene_path = OS::get_singleton()->get_cache_path().path_join("test_scene.tscn"); + String scene_path = TestUtils::get_temp_path("test_scene.tscn"); ps->set_path(scene_path); Node *root = memnew(Node); @@ -531,7 +548,7 @@ TEST_CASE("[SceneTree][Node]Exported node checks") { ps2.instantiate(); ps2->pack(root); - scene_path = OS::get_singleton()->get_cache_path().path_join("new_test_scene.tscn"); + scene_path = TestUtils::get_temp_path("new_test_scene.tscn"); ResourceSaver::save(ps2, scene_path); memdelete(root); @@ -548,6 +565,46 @@ TEST_CASE("[SceneTree][Node]Exported node checks") { CHECK_FALSE(is_wrong); } + SUBCASE("Saving instance with exported nodes should store property if changed") { + Ref<PackedScene> ps; + ps.instantiate(); + ps->pack(node); + + String scene_path = TestUtils::get_temp_path("test_scene.tscn"); + ps->set_path(scene_path); + + Node *root = memnew(Node); + + Node *sub_child = ps->instantiate(PackedScene::GEN_EDIT_STATE_MAIN); + root->add_child(sub_child); + sub_child->set_owner(root); + + sub_child->set("exported_node", sub_child->get_child(1)); + + children = Array(); + children.append(sub_child->get_child(1)); + sub_child->set("exported_nodes", children); + + Ref<PackedScene> ps2; + ps2.instantiate(); + ps2->pack(root); + + scene_path = TestUtils::get_temp_path("new_test_scene2.tscn"); + ResourceSaver::save(ps2, scene_path); + memdelete(root); + + int stored_properties = 0; + Ref<FileAccess> fa = FileAccess::open(scene_path, FileAccess::READ); + while (!fa->eof_reached()) { + const String line = fa->get_line(); + if (line.begins_with("exported_node")) { + stored_properties++; + } + } + CHECK_EQ(stored_properties, 2); + } +#endif // TOOLS_ENABLED + memdelete(node); } diff --git a/tests/servers/test_navigation_server_3d.h b/tests/servers/test_navigation_server_3d.h index 8778ea86a6..cf6b89c330 100644 --- a/tests/servers/test_navigation_server_3d.h +++ b/tests/servers/test_navigation_server_3d.h @@ -697,12 +697,16 @@ TEST_SUITE("[Navigation]") { CHECK_NE(navigation_server->map_get_closest_point(map, Vector3(0, 0, 0)), Vector3(0, 0, 0)); CHECK_NE(navigation_server->map_get_closest_point_normal(map, Vector3(0, 0, 0)), Vector3()); CHECK(navigation_server->map_get_closest_point_owner(map, Vector3(0, 0, 0)).is_valid()); - // TODO: Test map_get_closest_point_to_segment() with p_use_collision=true as well. CHECK_NE(navigation_server->map_get_closest_point_to_segment(map, Vector3(0, 0, 0), Vector3(1, 1, 1), false), Vector3()); + CHECK_NE(navigation_server->map_get_closest_point_to_segment(map, Vector3(0, 0, 0), Vector3(1, 1, 1), true), Vector3()); CHECK_NE(navigation_server->map_get_path(map, Vector3(0, 0, 0), Vector3(10, 0, 10), true).size(), 0); CHECK_NE(navigation_server->map_get_path(map, Vector3(0, 0, 0), Vector3(10, 0, 10), false).size(), 0); } + SUBCASE("'map_get_closest_point_to_segment' with 'use_collision' should return default if segment doesn't intersect map") { + CHECK_EQ(navigation_server->map_get_closest_point_to_segment(map, Vector3(1, 2, 1), Vector3(1, 1, 1), true), Vector3()); + } + SUBCASE("Elaborate query with 'CORRIDORFUNNEL' post-processing should yield non-empty result") { Ref<NavigationPathQueryParameters3D> query_parameters = memnew(NavigationPathQueryParameters3D); query_parameters->set_map(map); diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 041231888b..3c875797a4 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -111,6 +111,7 @@ #include "tests/scene/test_curve_3d.h" #include "tests/scene/test_gradient.h" #include "tests/scene/test_image_texture.h" +#include "tests/scene/test_image_texture_3d.h" #include "tests/scene/test_instance_placeholder.h" #include "tests/scene/test_node.h" #include "tests/scene/test_node_2d.h" diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index cbd6d1ffbb..9d41e74020 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -30,6 +30,7 @@ #include "tests/test_utils.h" +#include "core/io/dir_access.h" #include "core/os/os.h" String TestUtils::get_data_path(const String &p_file) { @@ -40,3 +41,9 @@ String TestUtils::get_data_path(const String &p_file) { String TestUtils::get_executable_dir() { return OS::get_singleton()->get_executable_path().get_base_dir(); } + +String TestUtils::get_temp_path(const String &p_suffix) { + const String temp_base = OS::get_singleton()->get_cache_path().path_join("godot_test"); + DirAccess::make_dir_absolute(temp_base); // Ensure the directory exists. + return temp_base.path_join(p_suffix); +} diff --git a/tests/test_utils.h b/tests/test_utils.h index 48abe75c06..876a59ee7b 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -37,6 +37,7 @@ namespace TestUtils { String get_data_path(const String &p_file); String get_executable_dir(); +String get_temp_path(const String &p_suffix); } // namespace TestUtils #endif // TEST_UTILS_H |