Browse Source

Merge pull request #1875 from dsnopek/tween-smoke-test

Add smoke test with `Tween` to check for issues with handling `RefCounted`
David Snopek 1 month ago
parent
commit
fde93df450
4 changed files with 12 additions and 0 deletions
  1. 1 0
      test/build_profile.json
  2. 3 0
      test/project/main.gd
  3. 6 0
      test/src/example.cpp
  4. 2 0
      test/src/example.h

+ 1 - 0
test/build_profile.json

@@ -8,6 +8,7 @@
 		"OS",
 		"TileMap",
 		"TileSet",
+		"Tween",
 		"Viewport"
 	]
 }

+ 3 - 0
test/project/main.gd

@@ -225,6 +225,9 @@ func _ready():
 	assert_equal(new_tilemap.tile_set, new_tileset)
 	new_tilemap.queue_free()
 
+	# Creates a Tween and checks that it's valid. Improper refcount handling will crash now or at shutdown.
+	assert_equal(example.test_tween_smoke_test(), true)
+
 	# Test variant call.
 	var test_obj = TestClass.new()
 	assert_equal(example.test_variant_call(test_obj), "hello world")

+ 6 - 0
test/src/example.cpp

@@ -222,6 +222,7 @@ void Example::_bind_methods() {
 
 	ClassDB::bind_method(D_METHOD("test_add_child", "node"), &Example::test_add_child);
 	ClassDB::bind_method(D_METHOD("test_set_tileset", "tilemap", "tileset"), &Example::test_set_tileset);
+	ClassDB::bind_method(D_METHOD("test_tween_smoke_test"), &Example::test_tween_smoke_test);
 
 	ClassDB::bind_method(D_METHOD("test_variant_call", "variant"), &Example::test_variant_call);
 
@@ -616,6 +617,11 @@ void Example::test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset
 	p_tilemap->set_tileset(p_tileset);
 }
 
+bool Example::test_tween_smoke_test() {
+	Ref<Tween> tween = create_tween();
+	return tween.is_valid() && tween->is_class("Tween") && tween->get_reference_count() > 1;
+}
+
 Variant Example::test_variant_call(Variant p_variant) {
 	return p_variant.call("test", "hello");
 }

+ 2 - 0
test/src/example.h

@@ -19,6 +19,7 @@
 #include <godot_cpp/classes/input_event_key.hpp>
 #include <godot_cpp/classes/tile_map.hpp>
 #include <godot_cpp/classes/tile_set.hpp>
+#include <godot_cpp/classes/tween.hpp>
 #include <godot_cpp/classes/viewport.hpp>
 #include <godot_cpp/variant/typed_dictionary.hpp>
 #include <godot_cpp/variant/variant.hpp>
@@ -154,6 +155,7 @@ public:
 
 	void test_add_child(Node *p_node);
 	void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
+	bool test_tween_smoke_test();
 
 	Variant test_variant_call(Variant p_variant);