From b28853aff1a917c3a9ad47915856ea0fd2373254 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 28 Sep 2021 15:49:53 +0200 Subject: [PATCH] Add test for Reference passing/returning. --- test/demo/main.gd | 2 ++ test/src/example.cpp | 10 ++++++++++ test/src/example.h | 1 + 3 files changed, 13 insertions(+) diff --git a/test/demo/main.gd b/test/demo/main.gd index 557e9019..f519c099 100644 --- a/test/demo/main.gd +++ b/test/demo/main.gd @@ -10,6 +10,8 @@ func _ready(): prints("returned", $Example.return_something("some string")) prints("returned const", $Example.return_something_const()) prints("returned ref", $Example.return_extended_ref()) + var ref = ExampleRef.new() + prints("sending ref: ", ref.get_instance_id(), "returned ref: ", $Example.extended_ref_checks(ref).get_instance_id()) prints("vararg args", $Example.varargs_func("some", "arguments", "to", "test")) # Use properties. diff --git a/test/src/example.cpp b/test/src/example.cpp index e3ed3164..4d34d4c8 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -53,6 +53,7 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("return_something"), &Example::return_something); ClassDB::bind_method(D_METHOD("return_something_const"), &Example::return_something_const); ClassDB::bind_method(D_METHOD("return_extended_ref"), &Example::return_extended_ref); + ClassDB::bind_method(D_METHOD("extended_ref_checks"), &Example::extended_ref_checks); { MethodInfo mi; @@ -107,6 +108,15 @@ ExampleRef *Example::return_extended_ref() const { return memnew(ExampleRef()); } +Ref Example::extended_ref_checks(Ref p_ref) const { + Ref ref; + ref.instantiate(); + // TODO the returned value gets dereferenced too early and return a null object otherwise. + ref->reference(); + UtilityFunctions::print("Example ref checks called with value: ", p_ref->get_instance_id(), ", returning value: ", ref->get_instance_id()); + return ref; +} + Variant Example::varargs_func(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { UtilityFunctions::print("Varargs called with ", String::num(arg_count), " arguments"); return arg_count; diff --git a/test/src/example.h b/test/src/example.h index e72051b5..c72ad607 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -76,6 +76,7 @@ public: String return_something(const String &base); Viewport *return_something_const() const; ExampleRef *return_extended_ref() const; + Ref extended_ref_checks(Ref p_ref) const; Variant varargs_func(const Variant **args, GDNativeInt arg_count, GDNativeCallError &error); void emit_custom_signal(const String &name, int value);