From de8eecc8470b238717b4ad504f1fd923b8809768 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Sun, 26 Jul 2026 07:10:46 -0500 Subject: [PATCH] In tests, remove the word "example" to avoid confusion --- test/CMakeLists.txt | 7 +- test/SConstruct | 8 +- .../{Example.xml => MyTestMain.xml} | 2 +- test/generate_xcframework.sh | 2 +- test/project/example.gdextension | 43 -- test/project/main.gd | 280 ++++++------- test/project/main.tscn | 12 +- test/project/{example.gd => my_test.gd} | 2 +- .../{example.gd.uid => my_test.gd.uid} | 0 test/project/my_test.gdextension | 43 ++ ...dextension.uid => my_test.gdextension.uid} | 0 test/project/project.godot | 2 +- test/project/test_typed_dictionary.gd | 6 +- test/src/{example.cpp => my_test.cpp} | 392 +++++++++--------- test/src/{example.h => my_test.h} | 82 ++-- test/src/register_types.cpp | 34 +- test/src/register_types.h | 4 +- 17 files changed, 459 insertions(+), 460 deletions(-) rename test/doc_classes/{Example.xml => MyTestMain.xml} (70%) delete mode 100644 test/project/example.gdextension rename test/project/{example.gd => my_test.gd} (84%) rename test/project/{example.gd.uid => my_test.gd.uid} (100%) create mode 100644 test/project/my_test.gdextension rename test/project/{example.gdextension.uid => my_test.gdextension.uid} (100%) rename test/src/{example.cpp => my_test.cpp} (50%) rename test/src/{example.h => my_test.h} (80%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 239d28f59..d5139e981 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(${TARGET_NAME} SHARED EXCLUDE_FROM_ALL) target_sources( ${TARGET_NAME} - PRIVATE src/example.cpp src/example.h src/register_types.cpp src/register_types.h src/tests.h + PRIVATE src/my_test.cpp src/my_test.h src/register_types.cpp src/register_types.h src/tests.h ) # conditionally add doc data to compile output @@ -52,8 +52,7 @@ set_target_properties( PDB_OUTPUT_DIRECTORY "$<1:${OUTPUT_DIR}>" #MSVC Only, ignored on other platforms PREFIX "lib" - OUTPUT_NAME "gdexample${GODOTCPP_SUFFIX}" - # TODO rename the file for both CMake and SCons + OUTPUT_NAME "mytest${GODOTCPP_SUFFIX}" # Some IDE's respect this property to logically group targets FOLDER "godot-cpp" @@ -64,6 +63,6 @@ set_target_properties( if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set_target_properties( ${TARGET_NAME} - PROPERTIES SUFFIX "" OUTPUT_DIR "${OUTPUT_DIR}/libgdexample.macos.${GODOTCPP_TARGET}.framework" + PROPERTIES SUFFIX "" OUTPUT_DIR "${OUTPUT_DIR}/libmytest.macos.${GODOTCPP_TARGET}.framework" ) endif() diff --git a/test/SConstruct b/test/SConstruct index b949bcacf..131ab10fc 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -20,7 +20,7 @@ if env["target"] in ["editor", "template_debug"]: if env["platform"] == "macos": library = env.SharedLibrary( - "project/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format( + "project/bin/libmytest.{}.{}.framework/libmytest.{}.{}".format( env["platform"], env["target"], env["platform"], env["target"] ), source=sources, @@ -28,17 +28,17 @@ if env["platform"] == "macos": elif env["platform"] == "ios": if env["ios_simulator"]: library = env.StaticLibrary( - "project/bin/libgdexample.{}.{}.simulator.a".format(env["platform"], env["target"]), + "project/bin/libmytest.{}.{}.simulator.a".format(env["platform"], env["target"]), source=sources, ) else: library = env.StaticLibrary( - "project/bin/libgdexample.{}.{}.a".format(env["platform"], env["target"]), + "project/bin/libmytest.{}.{}.a".format(env["platform"], env["target"]), source=sources, ) else: library = env.SharedLibrary( - "project/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]), + "project/bin/libmytest{}{}".format(env["suffix"], env["SHLIBSUFFIX"]), source=sources, ) diff --git a/test/doc_classes/Example.xml b/test/doc_classes/MyTestMain.xml similarity index 70% rename from test/doc_classes/Example.xml rename to test/doc_classes/MyTestMain.xml index 457709d52..9136cbcd8 100644 --- a/test/doc_classes/Example.xml +++ b/test/doc_classes/MyTestMain.xml @@ -1,5 +1,5 @@ - + A test control defined in GDExtension. diff --git a/test/generate_xcframework.sh b/test/generate_xcframework.sh index 7adddff59..39b4dfedd 100755 --- a/test/generate_xcframework.sh +++ b/test/generate_xcframework.sh @@ -3,5 +3,5 @@ scons arch=universal ios_simulator=yes platform=ios target=$1 $2 scons arch=arm64 ios_simulator=no platform=ios target=$1 $2 -xcodebuild -create-xcframework -library ./project/bin/libgdexample.ios.$1.a -library ./project/bin/libgdexample.ios.$1.simulator.a -output ./project/bin/libgdexample.ios.$1.xcframework +xcodebuild -create-xcframework -library ./project/bin/libmytest.ios.$1.a -library ./project/bin/libmytest.ios.$1.simulator.a -output ./project/bin/libmytest.ios.$1.xcframework xcodebuild -create-xcframework -library ../bin/libgodot-cpp.ios.$1.arm64.a -library ../bin/libgodot-cpp.ios.$1.universal.simulator.a -output ./project/bin/libgodot-cpp.ios.$1.xcframework diff --git a/test/project/example.gdextension b/test/project/example.gdextension deleted file mode 100644 index 8e2f794d1..000000000 --- a/test/project/example.gdextension +++ /dev/null @@ -1,43 +0,0 @@ -[configuration] - -entry_symbol = "example_library_init" -compatibility_minimum = "4.1" - -[libraries] - -macos.debug = "res://bin/libgdexample.macos.template_debug.framework" -macos.release = "res://bin/libgdexample.macos.template_release.framework" -windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll" -windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll" -windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll" -windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll" -windows.debug.arm64 = "res://bin/libgdexample.windows.template_debug.arm64.dll" -windows.release.arm64 = "res://bin/libgdexample.windows.template_release.arm64.dll" -linux.debug.x86_32 = "res://bin/libgdexample.linux.template_debug.x86_32.so" -linux.release.x86_32 = "res://bin/libgdexample.linux.template_release.x86_32.so" -linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so" -linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so" -linux.debug.arm32 = "res://bin/libgdexample.linux.template_debug.arm32.so" -linux.release.arm32 = "res://bin/libgdexample.linux.template_release.arm32.so" -linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so" -linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so" -linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so" -linux.release.rv64 = "res://bin/libgdexample.linux.template_release.rv64.so" -android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so" -android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so" -android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so" -android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so" -ios.debug = "res://bin/libgdexample.ios.template_debug.xcframework" -ios.release = "res://bin/libgdexample.ios.template_release.xcframework" -web.debug.threads.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm" -web.release.threads.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm" -web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.nothreads.wasm" -web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.nothreads.wasm" - -[dependencies] -ios.debug = { - "res://bin/libgodot-cpp.ios.template_debug.xcframework": "" -} -ios.release = { - "res://bin/libgodot-cpp.ios.template_release.xcframework": "" -} diff --git a/test/project/main.gd b/test/project/main.gd index 52d7c0f13..d2057f1ab 100644 --- a/test/project/main.gd +++ b/test/project/main.gd @@ -7,158 +7,158 @@ class TestClass: return p_msg + " world" func _ready(): - var example: Example = $Example - var godot_target_version := example.get_godot_target_version() + var my_test: MyTestMain = $MyTestMain + var godot_target_version := my_test.get_godot_target_version() var godot_runtime_version := Engine.get_version_info() # Timing of set instance binding. - assert_equal(example.is_object_binding_set_by_parent_constructor(), true) + assert_equal(my_test.is_object_binding_set_by_parent_constructor(), true) # Signal. - example.emit_custom_signal("Button", 42) + my_test.emit_custom_signal("Button", 42) assert_equal(custom_signal_emitted, ["Button", 42]) # To string. - assert_equal(example.to_string(),'[ GDExtension::Example <--> Instance ID:%s ]' % example.get_instance_id()) - assert_equal($Example/ExampleMin.to_string(), 'ExampleMin:' % $Example/ExampleMin.get_instance_id()) + assert_equal(my_test.to_string(),'[ GDExtension::MyTestMain <--> Instance ID:%s ]' % my_test.get_instance_id()) + assert_equal($MyTestMain/MyTestMin.to_string(), 'MyTestMin:' % $MyTestMain/MyTestMin.get_instance_id()) # Call static methods. - assert_equal(Example.test_static(9, 100), 109); + assert_equal(MyTestMain.test_static(9, 100), 109); # It's void and static, so all we know is that it didn't crash. - Example.test_static2() + MyTestMain.test_static2() # Property list. - example.property_from_list = Vector3(100, 200, 300) - assert_equal(example.property_from_list, Vector3(100, 200, 300)) - var prop_list = example.get_property_list() + my_test.property_from_list = Vector3(100, 200, 300) + assert_equal(my_test.property_from_list, Vector3(100, 200, 300)) + var prop_list = my_test.get_property_list() for prop_info in prop_list: if prop_info['name'] == 'mouse_filter': assert_equal(prop_info['usage'], PROPERTY_USAGE_NO_EDITOR) # Call simple methods. - example.simple_func() + my_test.simple_func() assert_equal(custom_signal_emitted, ['simple_func', 3]) - example.simple_const_func() + my_test.simple_const_func() assert_equal(custom_signal_emitted, ['simple_const_func', 4]) # Pass custom reference. - assert_equal(example.custom_ref_func(null), -1) - var ref1 = ExampleRef.new() + assert_equal(my_test.custom_ref_func(null), -1) + var ref1 = MyTestRef.new() assert_equal(ref1.get_reference_count(), 1) ref1.id = 27 - assert_equal(example.custom_ref_func(ref1), 27) + assert_equal(my_test.custom_ref_func(ref1), 27) ref1.id += 1; - assert_equal(example.custom_const_ref_func(ref1), 28) + assert_equal(my_test.custom_const_ref_func(ref1), 28) # Pass core reference. - assert_equal(example.image_ref_func(null), "invalid") - assert_equal(example.image_const_ref_func(null), "invalid") + assert_equal(my_test.image_ref_func(null), "invalid") + assert_equal(my_test.image_const_ref_func(null), "invalid") var image = Image.new() - assert_equal(example.image_ref_func(image), "valid") - assert_equal(example.image_const_ref_func(image), "valid") + assert_equal(my_test.image_ref_func(image), "valid") + assert_equal(my_test.image_const_ref_func(image), "valid") # Return values. - assert_equal(example.return_something("some string"), "some string42") - assert_equal(example.return_something_const(), get_viewport()) - var null_ref = example.return_empty_ref() + assert_equal(my_test.return_something("some string"), "some string42") + assert_equal(my_test.return_something_const(), get_viewport()) + var null_ref = my_test.return_empty_ref() assert_equal(null_ref, null) - var ret_ref = example.return_extended_ref() + var ret_ref = my_test.return_extended_ref() assert_not_equal(ret_ref.get_instance_id(), 0) assert_equal(ret_ref.get_reference_count(), 1) assert_equal(ret_ref.get_id(), 0) - assert_equal(example.get_v4(), Vector4(1.2, 3.4, 5.6, 7.8)) - assert_equal(example.test_node_argument(example), example) + assert_equal(my_test.get_v4(), Vector4(1.2, 3.4, 5.6, 7.8)) + assert_equal(my_test.test_node_argument(my_test), my_test) # VarArg method calls. - var var_ref = ExampleRef.new() - assert_not_equal(example.extended_ref_checks(var_ref).get_instance_id(), var_ref.get_instance_id()) - assert_equal(example.varargs_func("some", "arguments", "to", "test"), 4) - assert_equal(example.varargs_func_nv("some", "arguments", "to", "test"), 46) - example.varargs_func_void("some", "arguments", "to", "test") + var var_ref = MyTestRef.new() + assert_not_equal(my_test.extended_ref_checks(var_ref).get_instance_id(), var_ref.get_instance_id()) + assert_equal(my_test.varargs_func("some", "arguments", "to", "test"), 4) + assert_equal(my_test.varargs_func_nv("some", "arguments", "to", "test"), 46) + my_test.varargs_func_void("some", "arguments", "to", "test") assert_equal(custom_signal_emitted, ["varargs_func_void", 5]) # Method calls with default values. - assert_equal(example.def_args(), 300) - assert_equal(example.def_args(50), 250) - assert_equal(example.def_args(50, 100), 150) + assert_equal(my_test.def_args(), 300) + assert_equal(my_test.def_args(50), 250) + assert_equal(my_test.def_args(50, 100), 150) # Array and Dictionary - assert_equal(example.test_array(), [1, 2]) - assert_equal(example.test_tarray(), [Vector2(1, 2), Vector2(2, 3)]) + assert_equal(my_test.test_array(), [1, 2]) + assert_equal(my_test.test_tarray(), [Vector2(1, 2), Vector2(2, 3)]) var array: Array[int] = [1, 2, 3] - assert_equal(example.test_tarray_arg(array), 6) - assert_equal(example.test_dictionary(), { "hello": "world", "foo": "bar" }) + assert_equal(my_test.test_tarray_arg(array), 6) + assert_equal(my_test.test_dictionary(), { "hello": "world", "foo": "bar" }) if godot_target_version["minor"] >= 4: var test = load("res://test_typed_dictionary.gd").new() - test.test_typed_dictionary(self, example) + test.test_typed_dictionary(self, my_test) - example.callable_bind() + my_test.callable_bind() assert_equal(custom_signal_emitted, ["bound", 11]) # String += operator - assert_equal(example.test_string_ops(), "ABCĎE") + assert_equal(my_test.test_string_ops(), "ABCĎE") # UtilityFunctions::str() - assert_equal(example.test_str_utility(), "Hello, World! The answer is 42") + assert_equal(my_test.test_str_utility(), "Hello, World! The answer is 42") # Test converting string to char* and doing comparison. - assert_equal(example.test_string_is_forty_two("blah"), false) - assert_equal(example.test_string_is_forty_two("forty two"), true) + assert_equal(my_test.test_string_is_forty_two("blah"), false) + assert_equal(my_test.test_string_is_forty_two("forty two"), true) # String::resize(). - assert_equal(example.test_string_resize("What"), "What!?") + assert_equal(my_test.test_string_resize("What"), "What!?") # mp_callable() with void method. - var mp_callable: Callable = example.test_callable_mp() + var mp_callable: Callable = my_test.test_callable_mp() assert_equal(mp_callable.is_valid(), true) assert_equal(mp_callable.get_argument_count(), 3) - mp_callable.call(example, "void", 36) - assert_equal(custom_signal_emitted, ["unbound_method1: Example - void", 36]) + mp_callable.call(my_test, "void", 36) + assert_equal(custom_signal_emitted, ["unbound_method1: MyTestMain - void", 36]) # Check that it works with is_connected(). - assert_equal(example.renamed.is_connected(mp_callable), false) - example.renamed.connect(mp_callable) - assert_equal(example.renamed.is_connected(mp_callable), true) + assert_equal(my_test.renamed.is_connected(mp_callable), false) + my_test.renamed.connect(mp_callable) + assert_equal(my_test.renamed.is_connected(mp_callable), true) # Make sure a new object is still treated as equivalent. - assert_equal(example.renamed.is_connected(example.test_callable_mp()), true) - assert_equal(mp_callable.hash(), example.test_callable_mp().hash()) - example.renamed.disconnect(mp_callable) - assert_equal(example.renamed.is_connected(mp_callable), false) + assert_equal(my_test.renamed.is_connected(my_test.test_callable_mp()), true) + assert_equal(mp_callable.hash(), my_test.test_callable_mp().hash()) + my_test.renamed.disconnect(mp_callable) + assert_equal(my_test.renamed.is_connected(mp_callable), false) # mp_callable() with return value. - var mp_callable_ret: Callable = example.test_callable_mp_ret() + var mp_callable_ret: Callable = my_test.test_callable_mp_ret() assert_equal(mp_callable_ret.get_argument_count(), 3) - assert_equal(mp_callable_ret.call(example, "test", 77), "unbound_method2: Example - test - 77") + assert_equal(mp_callable_ret.call(my_test, "test", 77), "unbound_method2: MyTestMain - test - 77") # mp_callable() with const method and return value. - var mp_callable_retc: Callable = example.test_callable_mp_retc() + var mp_callable_retc: Callable = my_test.test_callable_mp_retc() assert_equal(mp_callable_retc.get_argument_count(), 3) - assert_equal(mp_callable_retc.call(example, "const", 101), "unbound_method3: Example - const - 101") + assert_equal(mp_callable_retc.call(my_test, "const", 101), "unbound_method3: MyTestMain - const - 101") # mp_callable_static() with void method. - var mp_callable_static: Callable = example.test_callable_mp_static() + var mp_callable_static: Callable = my_test.test_callable_mp_static() assert_equal(mp_callable_static.get_argument_count(), 3) - mp_callable_static.call(example, "static", 83) - assert_equal(custom_signal_emitted, ["unbound_static_method1: Example - static", 83]) + mp_callable_static.call(my_test, "static", 83) + assert_equal(custom_signal_emitted, ["unbound_static_method1: MyTestMain - static", 83]) # Check that it works with is_connected(). - assert_equal(example.renamed.is_connected(mp_callable_static), false) - example.renamed.connect(mp_callable_static) - assert_equal(example.renamed.is_connected(mp_callable_static), true) + assert_equal(my_test.renamed.is_connected(mp_callable_static), false) + my_test.renamed.connect(mp_callable_static) + assert_equal(my_test.renamed.is_connected(mp_callable_static), true) # Make sure a new object is still treated as equivalent. - assert_equal(example.renamed.is_connected(example.test_callable_mp_static()), true) - assert_equal(mp_callable_static.hash(), example.test_callable_mp_static().hash()) - example.renamed.disconnect(mp_callable_static) - assert_equal(example.renamed.is_connected(mp_callable_static), false) + assert_equal(my_test.renamed.is_connected(my_test.test_callable_mp_static()), true) + assert_equal(mp_callable_static.hash(), my_test.test_callable_mp_static().hash()) + my_test.renamed.disconnect(mp_callable_static) + assert_equal(my_test.renamed.is_connected(mp_callable_static), false) # mp_callable_static() with return value. - var mp_callable_static_ret: Callable = example.test_callable_mp_static_ret() + var mp_callable_static_ret: Callable = my_test.test_callable_mp_static_ret() assert_equal(mp_callable_static_ret.get_argument_count(), 3) - assert_equal(mp_callable_static_ret.call(example, "static-ret", 84), "unbound_static_method2: Example - static-ret - 84") + assert_equal(mp_callable_static_ret.call(my_test, "static-ret", 84), "unbound_static_method2: MyTestMain - static-ret - 84") # CallableCustom. - var custom_callable: Callable = example.test_custom_callable(); + var custom_callable: Callable = my_test.test_custom_callable(); assert_equal(custom_callable.is_custom(), true); assert_equal(custom_callable.is_valid(), true); assert_equal(custom_callable.call(), "Hi") @@ -169,96 +169,96 @@ func _ready(): assert_equal(str(custom_callable), ""); # PackedArray iterators - assert_equal(example.test_vector_ops(), 105) - assert_equal(example.test_vector_init_list(), 105) + assert_equal(my_test.test_vector_ops(), 105) + assert_equal(my_test.test_vector_init_list(), 105) # Properties. - assert_equal(example.group_subgroup_custom_position, Vector2(0, 0)) - example.group_subgroup_custom_position = Vector2(50, 50) - assert_equal(example.group_subgroup_custom_position, Vector2(50, 50)) + assert_equal(my_test.group_subgroup_custom_position, Vector2(0, 0)) + my_test.group_subgroup_custom_position = Vector2(50, 50) + assert_equal(my_test.group_subgroup_custom_position, Vector2(50, 50)) # Test Object::cast_to<>() and that correct wrappers are being used. var control = Control.new() var sprite = Sprite2D.new() - var example_ref = ExampleRef.new() + var my_test_ref = MyTestRef.new() - assert_equal(example.test_object_cast_to_node(control), true) - assert_equal(example.test_object_cast_to_control(control), true) - assert_equal(example.test_object_cast_to_example(control), false) + assert_equal(my_test.test_object_cast_to_node(control), true) + assert_equal(my_test.test_object_cast_to_control(control), true) + assert_equal(my_test.test_object_cast_to_my_test_main(control), false) - assert_equal(example.test_object_cast_to_node(example), true) - assert_equal(example.test_object_cast_to_control(example), true) - assert_equal(example.test_object_cast_to_example(example), true) + assert_equal(my_test.test_object_cast_to_node(my_test), true) + assert_equal(my_test.test_object_cast_to_control(my_test), true) + assert_equal(my_test.test_object_cast_to_my_test_main(my_test), true) - assert_equal(example.test_object_cast_to_node(sprite), true) - assert_equal(example.test_object_cast_to_control(sprite), false) - assert_equal(example.test_object_cast_to_example(sprite), false) + assert_equal(my_test.test_object_cast_to_node(sprite), true) + assert_equal(my_test.test_object_cast_to_control(sprite), false) + assert_equal(my_test.test_object_cast_to_my_test_main(sprite), false) - assert_equal(example.test_object_cast_to_node(example_ref), false) - assert_equal(example.test_object_cast_to_control(example_ref), false) - assert_equal(example.test_object_cast_to_example(example_ref), false) + assert_equal(my_test.test_object_cast_to_node(my_test_ref), false) + assert_equal(my_test.test_object_cast_to_control(my_test_ref), false) + assert_equal(my_test.test_object_cast_to_my_test_main(my_test_ref), false) control.queue_free() sprite.queue_free() # Test that passing null for objects works as expected too. - var example_null : Example = null - assert_equal(example.test_object_cast_to_node(example_null), false) + var my_test_null : MyTestMain = null + assert_equal(my_test.test_object_cast_to_node(my_test_null), false) # Test conversions to and from Variant. - assert_equal(example.test_variant_vector2i_conversion(Vector2i(1, 1)), Vector2i(1, 1)) - assert_equal(example.test_variant_vector2i_conversion(Vector2(1.0, 1.0)), Vector2i(1, 1)) - assert_equal(example.test_variant_int_conversion(10), 10) - assert_equal(example.test_variant_int_conversion(10.0), 10) - assert_equal(example.test_variant_float_conversion(10.0), 10.0) - assert_equal(example.test_variant_float_conversion(10), 10.0) + assert_equal(my_test.test_variant_vector2i_conversion(Vector2i(1, 1)), Vector2i(1, 1)) + assert_equal(my_test.test_variant_vector2i_conversion(Vector2(1.0, 1.0)), Vector2i(1, 1)) + assert_equal(my_test.test_variant_int_conversion(10), 10) + assert_equal(my_test.test_variant_int_conversion(10.0), 10) + assert_equal(my_test.test_variant_float_conversion(10.0), 10.0) + assert_equal(my_test.test_variant_float_conversion(10), 10.0) if godot_target_version["minor"] >= 4: # Test checking if objects are valid. var object_of_questionable_validity = Object.new() - assert_equal(example.test_object_is_valid(object_of_questionable_validity), true) + assert_equal(my_test.test_object_is_valid(object_of_questionable_validity), true) object_of_questionable_validity.free() - assert_equal(example.test_object_is_valid(object_of_questionable_validity), false) + assert_equal(my_test.test_object_is_valid(object_of_questionable_validity), false) # Test that ptrcalls from GDExtension to the engine are correctly encoding Object and RefCounted. var new_node = Node.new() - example.test_add_child(new_node) - assert_equal(new_node.get_parent(), example) + my_test.test_add_child(new_node) + assert_equal(new_node.get_parent(), my_test) var new_tileset = TileSet.new() var new_tilemap = TileMap.new() - example.test_set_tileset(new_tilemap, new_tileset) + my_test.test_set_tileset(new_tilemap, new_tileset) 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) + assert_equal(my_test.test_tween_smoke_test(), true) # Test variant call. var test_obj = TestClass.new() - assert_equal(example.test_variant_call(test_obj), "hello world") + assert_equal(my_test.test_variant_call(test_obj), "hello world") # Constants. - assert_equal(Example.FIRST, 0) - assert_equal(Example.ANSWER_TO_EVERYTHING, 42) - assert_equal(Example.CONSTANT_WITHOUT_ENUM, 314) + assert_equal(MyTestMain.FIRST, 0) + assert_equal(MyTestMain.ANSWER_TO_EVERYTHING, 42) + assert_equal(MyTestMain.CONSTANT_WITHOUT_ENUM, 314) # BitFields. - assert_equal(Example.FLAG_ONE, 1) - assert_equal(Example.FLAG_TWO, 2) - assert_equal(example.test_bitfield(0), 0) - assert_equal(example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3) + assert_equal(MyTestMain.FLAG_ONE, 1) + assert_equal(MyTestMain.FLAG_TWO, 2) + assert_equal(my_test.test_bitfield(0), 0) + assert_equal(my_test.test_bitfield(MyTestMain.FLAG_ONE | MyTestMain.FLAG_TWO), 3) # Test variant iterator. - assert_equal(example.test_variant_iterator([10, 20, 30]), [15, 25, 35]) - assert_equal(example.test_variant_iterator(null), "iter_init: not valid") + assert_equal(my_test.test_variant_iterator([10, 20, 30]), [15, 25, 35]) + assert_equal(my_test.test_variant_iterator(null), "iter_init: not valid") # RPCs. - assert_equal(example.return_last_rpc_arg(), 0) - example.test_rpc(42) - assert_equal(example.return_last_rpc_arg(), 42) - example.test_send_rpc(100) - assert_equal(example.return_last_rpc_arg(), 100) + assert_equal(my_test.return_last_rpc_arg(), 0) + my_test.test_rpc(42) + assert_equal(my_test.return_last_rpc_arg(), 42) + my_test.test_send_rpc(100) + assert_equal(my_test.return_last_rpc_arg(), 100) # Virtual method. var event = InputEventKey.new() @@ -268,49 +268,49 @@ func _ready(): assert_equal(custom_signal_emitted, ["_input: H", 72]) # Check NOTIFICATION_POST_INITIALIZED, both when created from GDScript and godot-cpp. - var new_example_ref = ExampleRef.new() - assert_equal(new_example_ref.was_post_initialized(), true) - assert_equal(example.test_post_initialize(), true) + var new_my_test_ref = MyTestRef.new() + assert_equal(new_my_test_ref.was_post_initialized(), true) + assert_equal(my_test.test_post_initialize(), true) # Test a virtual method defined in GDExtension and implemented in script. - assert_equal(example.test_virtual_implemented_in_script("Virtual", 939), "Implemented") + assert_equal(my_test.test_virtual_implemented_in_script("Virtual", 939), "Implemented") assert_equal(custom_signal_emitted, ["Virtual", 939]) # Test that we can access an engine singleton. - assert_equal(example.test_use_engine_singleton(), OS.get_name()) + assert_equal(my_test.test_use_engine_singleton(), OS.get_name()) if godot_target_version["minor"] >= 4: - assert_equal(example.test_get_internal(1), 1) - assert_equal(example.test_get_internal(true), -1) + assert_equal(my_test.test_get_internal(1), 1) + assert_equal(my_test.test_get_internal(true), -1) # Test that notifications happen on both parent and child classes. - var example_child = $ExampleChild - assert_equal(example_child.get_value1(), 11) - assert_equal(example_child.get_value2(), 33) - example_child.notification(NOTIFICATION_ENTER_TREE, true) - assert_equal(example_child.get_value1(), 11) - assert_equal(example_child.get_value2(), 22) + var my_test_child = $MyTestChild + assert_equal(my_test_child.get_value1(), 11) + assert_equal(my_test_child.get_value2(), 33) + my_test_child.notification(NOTIFICATION_ENTER_TREE, true) + assert_equal(my_test_child.get_value1(), 11) + assert_equal(my_test_child.get_value2(), 22) # Test that the extension's library path is absolute and valid. - var library_path = Example.test_library_path() + var library_path = MyTestMain.test_library_path() assert_equal(library_path.begins_with("res://"), false) assert_equal(library_path, ProjectSettings.globalize_path(library_path)) assert_equal(FileAccess.file_exists(library_path), true) if godot_target_version["minor"] >= 5: # Test that internal classes work as expected (at least for Godot 4.5+). - assert_equal(ClassDB.can_instantiate("ExampleInternal"), false) - assert_equal(ClassDB.instantiate("ExampleInternal"), null) - var internal_class = example.test_get_internal_class() + assert_equal(ClassDB.can_instantiate("MyTestInternal"), false) + assert_equal(ClassDB.instantiate("MyTestInternal"), null) + var internal_class = my_test.test_get_internal_class() assert_equal(internal_class.get_the_answer(), 42) - assert_equal(internal_class.get_class(), "ExampleInternal") + assert_equal(internal_class.get_class(), "MyTestInternal") if godot_runtime_version["minor"] >= 4: # Test a class with a unicode name. - var przykład = ClassDB.instantiate("ExamplePrzykład") + var przykład = ClassDB.instantiate("MyTestPrzykład") assert_equal(przykład.get_the_word(), "słowo to przykład") exit_with_status() -func _on_Example_custom_signal(signal_name, value): +func _on_my_test_custom_signal(signal_name, value): custom_signal_emitted = [signal_name, value] diff --git a/test/project/main.tscn b/test/project/main.tscn index e786025a6..e9ca2d08e 100644 --- a/test/project/main.tscn +++ b/test/project/main.tscn @@ -1,18 +1,18 @@ [gd_scene load_steps=3 format=3 uid="uid://dmx2xuigcpvt4"] [ext_resource type="Script" path="res://main.gd" id="1_qesh5"] -[ext_resource type="Script" path="res://example.gd" id="2_jju25"] +[ext_resource type="Script" path="res://my_test.gd" id="2_jju25"] [node name="Node" type="Node"] script = ExtResource("1_qesh5") -[node name="Example" type="Example" parent="."] +[node name="MyTestMain" type="MyTestMain" parent="."] script = ExtResource("2_jju25") -[node name="ExampleMin" type="ExampleMin" parent="Example"] +[node name="MyTestMin" type="MyTestMin" parent="MyTestMain"] layout_mode = 0 -[node name="Label" type="Label" parent="Example"] +[node name="Label" type="Label" parent="MyTestMain"] layout_mode = 0 offset_left = 194.0 offset_top = -2.0 @@ -24,6 +24,6 @@ offset_right = 79.0 offset_bottom = 29.0 text = "Click me!" -[node name="ExampleChild" type="ExampleChild" parent="."] +[node name="MyTestChild" type="MyTestChild" parent="."] -[connection signal="custom_signal" from="Example" to="." method="_on_Example_custom_signal"] +[connection signal="custom_signal" from="MyTestMain" to="." method="_on_my_test_custom_signal"] diff --git a/test/project/example.gd b/test/project/my_test.gd similarity index 84% rename from test/project/example.gd rename to test/project/my_test.gd index b20280a3a..a323133e6 100644 --- a/test/project/example.gd +++ b/test/project/my_test.gd @@ -1,4 +1,4 @@ -extends Example +extends MyTestMain func _do_something_virtual(p_name, p_value): custom_signal.emit(p_name, p_value) diff --git a/test/project/example.gd.uid b/test/project/my_test.gd.uid similarity index 100% rename from test/project/example.gd.uid rename to test/project/my_test.gd.uid diff --git a/test/project/my_test.gdextension b/test/project/my_test.gdextension new file mode 100644 index 000000000..2d8ae9208 --- /dev/null +++ b/test/project/my_test.gdextension @@ -0,0 +1,43 @@ +[configuration] + +entry_symbol = "my_test_library_init" +compatibility_minimum = "4.1" + +[libraries] + +macos.debug = "res://bin/libmytest.macos.template_debug.framework" +macos.release = "res://bin/libmytest.macos.template_release.framework" +windows.debug.x86_32 = "res://bin/libmytest.windows.template_debug.x86_32.dll" +windows.release.x86_32 = "res://bin/libmytest.windows.template_release.x86_32.dll" +windows.debug.x86_64 = "res://bin/libmytest.windows.template_debug.x86_64.dll" +windows.release.x86_64 = "res://bin/libmytest.windows.template_release.x86_64.dll" +windows.debug.arm64 = "res://bin/libmytest.windows.template_debug.arm64.dll" +windows.release.arm64 = "res://bin/libmytest.windows.template_release.arm64.dll" +linux.debug.x86_32 = "res://bin/libmytest.linux.template_debug.x86_32.so" +linux.release.x86_32 = "res://bin/libmytest.linux.template_release.x86_32.so" +linux.debug.x86_64 = "res://bin/libmytest.linux.template_debug.x86_64.so" +linux.release.x86_64 = "res://bin/libmytest.linux.template_release.x86_64.so" +linux.debug.arm32 = "res://bin/libmytest.linux.template_debug.arm32.so" +linux.release.arm32 = "res://bin/libmytest.linux.template_release.arm32.so" +linux.debug.arm64 = "res://bin/libmytest.linux.template_debug.arm64.so" +linux.release.arm64 = "res://bin/libmytest.linux.template_release.arm64.so" +linux.debug.rv64 = "res://bin/libmytest.linux.template_debug.rv64.so" +linux.release.rv64 = "res://bin/libmytest.linux.template_release.rv64.so" +android.debug.x86_64 = "res://bin/libmytest.android.template_debug.x86_64.so" +android.release.x86_64 = "res://bin/libmytest.android.template_release.x86_64.so" +android.debug.arm64 = "res://bin/libmytest.android.template_debug.arm64.so" +android.release.arm64 = "res://bin/libmytest.android.template_release.arm64.so" +ios.debug = "res://bin/libmytest.ios.template_debug.xcframework" +ios.release = "res://bin/libmytest.ios.template_release.xcframework" +web.debug.threads.wasm32 = "res://bin/libmytest.web.template_debug.wasm32.wasm" +web.release.threads.wasm32 = "res://bin/libmytest.web.template_release.wasm32.wasm" +web.debug.wasm32 = "res://bin/libmytest.web.template_debug.wasm32.nothreads.wasm" +web.release.wasm32 = "res://bin/libmytest.web.template_release.wasm32.nothreads.wasm" + +[dependencies] +ios.debug = { + "res://bin/libgodot-cpp.ios.template_debug.xcframework": "" +} +ios.release = { + "res://bin/libgodot-cpp.ios.template_release.xcframework": "" +} diff --git a/test/project/example.gdextension.uid b/test/project/my_test.gdextension.uid similarity index 100% rename from test/project/example.gdextension.uid rename to test/project/my_test.gdextension.uid diff --git a/test/project/project.godot b/test/project/project.godot index df3dd70f7..5d82a98bd 100644 --- a/test/project/project.godot +++ b/test/project/project.godot @@ -17,7 +17,7 @@ config/icon="res://icon.png" [native_extensions] -paths=["res://example.gdextension"] +paths=["res://my_test.gdextension"] [rendering] diff --git a/test/project/test_typed_dictionary.gd b/test/project/test_typed_dictionary.gd index 4cf6e71c2..86db6522f 100644 --- a/test/project/test_typed_dictionary.gd +++ b/test/project/test_typed_dictionary.gd @@ -1,6 +1,6 @@ extends RefCounted -func test_typed_dictionary(test, example: Example): - test.assert_equal(example.test_tdictionary(), { Vector2(1, 2): Vector2i(2, 3) }) +func test_typed_dictionary(test, my_test: MyTestMain): + test.assert_equal(my_test.test_tdictionary(), { Vector2(1, 2): Vector2i(2, 3) }) var dictionary: Dictionary[String, int] = { "1": 1, "2": 2, "3": 3 } - test.assert_equal(example.test_tdictionary_arg(dictionary), 6) + test.assert_equal(my_test.test_tdictionary_arg(dictionary), 6) diff --git a/test/src/example.cpp b/test/src/my_test.cpp similarity index 50% rename from test/src/example.cpp rename to test/src/my_test.cpp index 43f781c4e..642794013 100644 --- a/test/src/example.cpp +++ b/test/src/my_test.cpp @@ -3,7 +3,7 @@ * This is free and unencumbered software released into the public domain. */ -#include "example.h" +#include "my_test.h" #include @@ -61,37 +61,37 @@ class MyCallableCustom : public CallableCustom { } }; -void ExampleRef::set_id(int p_id) { +void MyTestRef::set_id(int p_id) { id = p_id; } -int ExampleRef::get_id() const { +int MyTestRef::get_id() const { return id; } -void ExampleRef::_notification(int p_what) { +void MyTestRef::_notification(int p_what) { if (p_what == NOTIFICATION_POSTINITIALIZE) { post_initialized = true; } } -void ExampleRef::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_id", "id"), &ExampleRef::set_id); - ClassDB::bind_method(D_METHOD("get_id"), &ExampleRef::get_id); +void MyTestRef::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_id", "id"), &MyTestRef::set_id); + ClassDB::bind_method(D_METHOD("get_id"), &MyTestRef::get_id); - ClassDB::bind_method(D_METHOD("was_post_initialized"), &ExampleRef::was_post_initialized); + ClassDB::bind_method(D_METHOD("was_post_initialized"), &MyTestRef::was_post_initialized); ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); } -ExampleRef::ExampleRef() { +MyTestRef::MyTestRef() { id = 0; } -ExampleRef::~ExampleRef() { +MyTestRef::~MyTestRef() { } -Dictionary Example::get_godot_target_version() const { +Dictionary MyTestMain::get_godot_target_version() const { Dictionary ret; ret["major"] = GODOT_VERSION_MAJOR; ret["minor"] = GODOT_VERSION_MINOR; @@ -99,19 +99,19 @@ Dictionary Example::get_godot_target_version() const { return ret; } -int Example::test_static(int p_a, int p_b) { +int MyTestMain::test_static(int p_a, int p_b) { return p_a + p_b; } -void Example::test_static2() { +void MyTestMain::test_static2() { //UtilityFunctions::print(" void static"); } -int Example::def_args(int p_a, int p_b) { +int MyTestMain::def_args(int p_a, int p_b) { return p_a + p_b; } -void Example::_notification(int p_what) { +void MyTestMain::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { Dictionary opts; opts["rpc_mode"] = MultiplayerAPI::RPC_MODE_AUTHORITY; @@ -123,7 +123,7 @@ void Example::_notification(int p_what) { //UtilityFunctions::print("Notification: ", String::num(p_what)); } -bool Example::_set(const StringName &p_name, const Variant &p_value) { +bool MyTestMain::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("dproperty")) { int64_t index = name.get_slicec('_', 1).to_int(); @@ -137,7 +137,7 @@ bool Example::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool Example::_get(const StringName &p_name, Variant &r_ret) const { +bool MyTestMain::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name.begins_with("dproperty")) { int64_t index = name.get_slicec('_', 1).to_int(); @@ -151,18 +151,18 @@ bool Example::_get(const StringName &p_name, Variant &r_ret) const { return false; } -String Example::_to_string() const { - return "[ GDExtension::Example <--> Instance ID:" + uitos(get_instance_id()) + " ]"; +String MyTestMain::_to_string() const { + return "[ GDExtension::MyTestMain <--> Instance ID:" + uitos(get_instance_id()) + " ]"; } -void Example::_get_property_list(List *p_list) const { +void MyTestMain::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::VECTOR3, "property_from_list")); for (int i = 0; i < 3; i++) { p_list->push_back(PropertyInfo(Variant::VECTOR2, "dproperty_" + itos(i))); } } -bool Example::_property_can_revert(const StringName &p_name) const { +bool MyTestMain::_property_can_revert(const StringName &p_name) const { if (p_name == StringName("property_from_list") && property_from_list != Vector3(42, 42, 42)) { return true; } else { @@ -170,7 +170,7 @@ bool Example::_property_can_revert(const StringName &p_name) const { } } -bool Example::_property_get_revert(const StringName &p_name, Variant &r_property) const { +bool MyTestMain::_property_get_revert(const StringName &p_name, Variant &r_property) const { if (p_name == StringName("property_from_list")) { r_property = Vector3(42, 42, 42); return true; @@ -179,7 +179,7 @@ bool Example::_property_get_revert(const StringName &p_name, Variant &r_property } } -void Example::_validate_property(PropertyInfo &p_property) const { +void MyTestMain::_validate_property(PropertyInfo &p_property) const { String name = p_property.name; // Test hiding the "mouse_filter" property from the editor. if (name == "mouse_filter") { @@ -187,126 +187,126 @@ void Example::_validate_property(PropertyInfo &p_property) const { } } -void Example::_bind_methods() { +void MyTestMain::_bind_methods() { // Methods. - ClassDB::bind_method(D_METHOD("get_godot_target_version"), &Example::get_godot_target_version); - ClassDB::bind_method(D_METHOD("simple_func"), &Example::simple_func); - ClassDB::bind_method(D_METHOD("simple_const_func"), &Example::simple_const_func); - ClassDB::bind_method(D_METHOD("custom_ref_func", "ref"), &Example::custom_ref_func); - ClassDB::bind_method(D_METHOD("custom_const_ref_func", "ref"), &Example::custom_const_ref_func); - ClassDB::bind_method(D_METHOD("image_ref_func", "image"), &Example::image_ref_func); - ClassDB::bind_method(D_METHOD("image_const_ref_func", "image"), &Example::image_const_ref_func); - 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_empty_ref"), &Example::return_empty_ref); - ClassDB::bind_method(D_METHOD("return_extended_ref"), &Example::return_extended_ref); - ClassDB::bind_method(D_METHOD("extended_ref_checks", "ref"), &Example::extended_ref_checks); - - ClassDB::bind_method(D_METHOD("is_object_binding_set_by_parent_constructor"), &Example::is_object_binding_set_by_parent_constructor); - - ClassDB::bind_method(D_METHOD("test_array"), &Example::test_array); - ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &Example::test_tarray_arg); - ClassDB::bind_method(D_METHOD("test_tarray"), &Example::test_tarray); - ClassDB::bind_method(D_METHOD("test_dictionary"), &Example::test_dictionary); + ClassDB::bind_method(D_METHOD("get_godot_target_version"), &MyTestMain::get_godot_target_version); + ClassDB::bind_method(D_METHOD("simple_func"), &MyTestMain::simple_func); + ClassDB::bind_method(D_METHOD("simple_const_func"), &MyTestMain::simple_const_func); + ClassDB::bind_method(D_METHOD("custom_ref_func", "ref"), &MyTestMain::custom_ref_func); + ClassDB::bind_method(D_METHOD("custom_const_ref_func", "ref"), &MyTestMain::custom_const_ref_func); + ClassDB::bind_method(D_METHOD("image_ref_func", "image"), &MyTestMain::image_ref_func); + ClassDB::bind_method(D_METHOD("image_const_ref_func", "image"), &MyTestMain::image_const_ref_func); + ClassDB::bind_method(D_METHOD("return_something"), &MyTestMain::return_something); + ClassDB::bind_method(D_METHOD("return_something_const"), &MyTestMain::return_something_const); + ClassDB::bind_method(D_METHOD("return_empty_ref"), &MyTestMain::return_empty_ref); + ClassDB::bind_method(D_METHOD("return_extended_ref"), &MyTestMain::return_extended_ref); + ClassDB::bind_method(D_METHOD("extended_ref_checks", "ref"), &MyTestMain::extended_ref_checks); + + ClassDB::bind_method(D_METHOD("is_object_binding_set_by_parent_constructor"), &MyTestMain::is_object_binding_set_by_parent_constructor); + + ClassDB::bind_method(D_METHOD("test_array"), &MyTestMain::test_array); + ClassDB::bind_method(D_METHOD("test_tarray_arg", "array"), &MyTestMain::test_tarray_arg); + ClassDB::bind_method(D_METHOD("test_tarray"), &MyTestMain::test_tarray); + ClassDB::bind_method(D_METHOD("test_dictionary"), &MyTestMain::test_dictionary); #if GODOT_VERSION_MINOR >= 4 - ClassDB::bind_method(D_METHOD("test_tdictionary_arg", "dictionary"), &Example::test_tdictionary_arg); - ClassDB::bind_method(D_METHOD("test_tdictionary"), &Example::test_tdictionary); + ClassDB::bind_method(D_METHOD("test_tdictionary_arg", "dictionary"), &MyTestMain::test_tdictionary_arg); + ClassDB::bind_method(D_METHOD("test_tdictionary"), &MyTestMain::test_tdictionary); #endif // GODOT_VERSION_MINOR >= 4 - ClassDB::bind_method(D_METHOD("test_node_argument"), &Example::test_node_argument); - ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); - ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility); - ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &Example::test_string_is_forty_two); - ClassDB::bind_method(D_METHOD("test_string_resize"), &Example::test_string_resize); - ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &Example::test_typed_array_of_packed); - ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); - ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list); + ClassDB::bind_method(D_METHOD("test_node_argument"), &MyTestMain::test_node_argument); + ClassDB::bind_method(D_METHOD("test_string_ops"), &MyTestMain::test_string_ops); + ClassDB::bind_method(D_METHOD("test_str_utility"), &MyTestMain::test_str_utility); + ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &MyTestMain::test_string_is_forty_two); + ClassDB::bind_method(D_METHOD("test_string_resize"), &MyTestMain::test_string_resize); + ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &MyTestMain::test_typed_array_of_packed); + ClassDB::bind_method(D_METHOD("test_vector_ops"), &MyTestMain::test_vector_ops); + ClassDB::bind_method(D_METHOD("test_vector_init_list"), &MyTestMain::test_vector_init_list); - ClassDB::bind_method(D_METHOD("test_object_cast_to_node", "object"), &Example::test_object_cast_to_node); - ClassDB::bind_method(D_METHOD("test_object_cast_to_control", "object"), &Example::test_object_cast_to_control); - ClassDB::bind_method(D_METHOD("test_object_cast_to_example", "object"), &Example::test_object_cast_to_example); + ClassDB::bind_method(D_METHOD("test_object_cast_to_node", "object"), &MyTestMain::test_object_cast_to_node); + ClassDB::bind_method(D_METHOD("test_object_cast_to_control", "object"), &MyTestMain::test_object_cast_to_control); + ClassDB::bind_method(D_METHOD("test_object_cast_to_my_test_main", "object"), &MyTestMain::test_object_cast_to_my_test_main); - ClassDB::bind_method(D_METHOD("test_variant_vector2i_conversion", "variant"), &Example::test_variant_vector2i_conversion); - ClassDB::bind_method(D_METHOD("test_variant_int_conversion", "variant"), &Example::test_variant_int_conversion); - ClassDB::bind_method(D_METHOD("test_variant_float_conversion", "variant"), &Example::test_variant_float_conversion); - ClassDB::bind_method(D_METHOD("test_object_is_valid", "variant"), &Example::test_object_is_valid); + ClassDB::bind_method(D_METHOD("test_variant_vector2i_conversion", "variant"), &MyTestMain::test_variant_vector2i_conversion); + ClassDB::bind_method(D_METHOD("test_variant_int_conversion", "variant"), &MyTestMain::test_variant_int_conversion); + ClassDB::bind_method(D_METHOD("test_variant_float_conversion", "variant"), &MyTestMain::test_variant_float_conversion); + ClassDB::bind_method(D_METHOD("test_object_is_valid", "variant"), &MyTestMain::test_object_is_valid); - 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_add_child", "node"), &MyTestMain::test_add_child); + ClassDB::bind_method(D_METHOD("test_set_tileset", "tilemap", "tileset"), &MyTestMain::test_set_tileset); + ClassDB::bind_method(D_METHOD("test_tween_smoke_test"), &MyTestMain::test_tween_smoke_test); - ClassDB::bind_method(D_METHOD("test_variant_call", "variant"), &Example::test_variant_call); + ClassDB::bind_method(D_METHOD("test_variant_call", "variant"), &MyTestMain::test_variant_call); - ClassDB::bind_method(D_METHOD("test_callable_mp"), &Example::test_callable_mp); - ClassDB::bind_method(D_METHOD("test_callable_mp_ret"), &Example::test_callable_mp_ret); - ClassDB::bind_method(D_METHOD("test_callable_mp_retc"), &Example::test_callable_mp_retc); - ClassDB::bind_method(D_METHOD("test_callable_mp_static"), &Example::test_callable_mp_static); - ClassDB::bind_method(D_METHOD("test_callable_mp_static_ret"), &Example::test_callable_mp_static_ret); - ClassDB::bind_method(D_METHOD("test_custom_callable"), &Example::test_custom_callable); + ClassDB::bind_method(D_METHOD("test_callable_mp"), &MyTestMain::test_callable_mp); + ClassDB::bind_method(D_METHOD("test_callable_mp_ret"), &MyTestMain::test_callable_mp_ret); + ClassDB::bind_method(D_METHOD("test_callable_mp_retc"), &MyTestMain::test_callable_mp_retc); + ClassDB::bind_method(D_METHOD("test_callable_mp_static"), &MyTestMain::test_callable_mp_static); + ClassDB::bind_method(D_METHOD("test_callable_mp_static_ret"), &MyTestMain::test_callable_mp_static_ret); + ClassDB::bind_method(D_METHOD("test_custom_callable"), &MyTestMain::test_custom_callable); - ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield); + ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &MyTestMain::test_bitfield); - ClassDB::bind_method(D_METHOD("test_variant_iterator", "input"), &Example::test_variant_iterator); + ClassDB::bind_method(D_METHOD("test_variant_iterator", "input"), &MyTestMain::test_variant_iterator); - ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc); - ClassDB::bind_method(D_METHOD("test_send_rpc", "value"), &Example::test_send_rpc); - ClassDB::bind_method(D_METHOD("return_last_rpc_arg"), &Example::return_last_rpc_arg); + ClassDB::bind_method(D_METHOD("test_rpc", "value"), &MyTestMain::test_rpc); + ClassDB::bind_method(D_METHOD("test_send_rpc", "value"), &MyTestMain::test_send_rpc); + ClassDB::bind_method(D_METHOD("return_last_rpc_arg"), &MyTestMain::return_last_rpc_arg); - ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200)); - ClassDB::bind_method(D_METHOD("callable_bind"), &Example::callable_bind); - ClassDB::bind_method(D_METHOD("test_post_initialize"), &Example::test_post_initialize); + ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &MyTestMain::def_args, DEFVAL(100), DEFVAL(200)); + ClassDB::bind_method(D_METHOD("callable_bind"), &MyTestMain::callable_bind); + ClassDB::bind_method(D_METHOD("test_post_initialize"), &MyTestMain::test_post_initialize); #if GODOT_VERSION_MINOR >= 4 - ClassDB::bind_method(D_METHOD("test_get_internal", "a"), &Example::test_get_internal); + ClassDB::bind_method(D_METHOD("test_get_internal", "a"), &MyTestMain::test_get_internal); #endif // GODOT_VERSION_MINOR >= 4 GDVIRTUAL_BIND(_do_something_virtual, "name", "value"); - ClassDB::bind_method(D_METHOD("test_virtual_implemented_in_script"), &Example::test_virtual_implemented_in_script); + ClassDB::bind_method(D_METHOD("test_virtual_implemented_in_script"), &MyTestMain::test_virtual_implemented_in_script); GDVIRTUAL_BIND(_do_something_virtual_with_control, "control"); - ClassDB::bind_method(D_METHOD("test_use_engine_singleton"), &Example::test_use_engine_singleton); + ClassDB::bind_method(D_METHOD("test_use_engine_singleton"), &MyTestMain::test_use_engine_singleton); - ClassDB::bind_method(D_METHOD("test_get_internal_class"), &Example::test_get_internal_class); + ClassDB::bind_method(D_METHOD("test_get_internal_class"), &MyTestMain::test_get_internal_class); - ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static); - ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2); + ClassDB::bind_static_method("MyTestMain", D_METHOD("test_static", "a", "b"), &MyTestMain::test_static); + ClassDB::bind_static_method("MyTestMain", D_METHOD("test_static2"), &MyTestMain::test_static2); - ClassDB::bind_static_method("Example", D_METHOD("test_library_path"), &Example::test_library_path); + ClassDB::bind_static_method("MyTestMain", D_METHOD("test_library_path"), &MyTestMain::test_library_path); { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); mi.name = "varargs_func"; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func", &Example::varargs_func, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func", &MyTestMain::varargs_func, mi); } { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); mi.name = "varargs_func_nv"; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_nv", &Example::varargs_func_nv, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_nv", &MyTestMain::varargs_func_nv, mi); } { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); mi.name = "varargs_func_void"; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_void", &Example::varargs_func_void, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "varargs_func_void", &MyTestMain::varargs_func_void, mi); } // Properties. ADD_GROUP("Test group", "group_"); ADD_SUBGROUP("Test subgroup", "group_subgroup_"); - ClassDB::bind_method(D_METHOD("get_custom_position"), &Example::get_custom_position); - ClassDB::bind_method(D_METHOD("get_v4"), &Example::get_v4); - ClassDB::bind_method(D_METHOD("set_custom_position", "position"), &Example::set_custom_position); + ClassDB::bind_method(D_METHOD("get_custom_position"), &MyTestMain::get_custom_position); + ClassDB::bind_method(D_METHOD("get_v4"), &MyTestMain::get_v4); + ClassDB::bind_method(D_METHOD("set_custom_position", "position"), &MyTestMain::set_custom_position); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "group_subgroup_custom_position"), "set_custom_position", "get_custom_position"); // Signals. ADD_SIGNAL(MethodInfo("custom_signal", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::INT, "value"))); - ClassDB::bind_method(D_METHOD("emit_custom_signal", "name", "value"), &Example::emit_custom_signal); + ClassDB::bind_method(D_METHOD("emit_custom_signal", "name", "value"), &MyTestMain::emit_custom_signal); // Constants. BIND_ENUM_CONSTANT(FIRST); @@ -319,11 +319,11 @@ void Example::_bind_methods() { BIND_ENUM_CONSTANT(OUTSIDE_OF_CLASS); } -bool Example::has_object_instance_binding() const { +bool MyTestMain::has_object_instance_binding() const { return ::godot::gdextension_interface::object_get_instance_binding(_owner, ::godot::gdextension_interface::token, nullptr); } -Example::Example() : +MyTestMain::MyTestMain() : object_instance_binding_set_by_parent_constructor(has_object_instance_binding()) { // Test conversion, to ensure users can use all parent class functions at this time. // It would crash if instance binding still not be initialized. @@ -333,40 +333,40 @@ Example::Example() : //UtilityFunctions::print("Constructor."); } -Example::~Example() { +MyTestMain::~MyTestMain() { //UtilityFunctions::print("Destructor."); } // Methods. -void Example::simple_func() { +void MyTestMain::simple_func() { emit_custom_signal("simple_func", 3); } -void Example::simple_const_func() const { - ((Example *)this)->emit_custom_signal("simple_const_func", 4); +void MyTestMain::simple_const_func() const { + ((MyTestMain *)this)->emit_custom_signal("simple_const_func", 4); } -int Example::custom_ref_func(Ref p_ref) { +int MyTestMain::custom_ref_func(Ref p_ref) { return p_ref.is_valid() ? p_ref->get_id() : -1; } -int Example::custom_const_ref_func(const Ref &p_ref) { +int MyTestMain::custom_const_ref_func(const Ref &p_ref) { return p_ref.is_valid() ? p_ref->get_id() : -1; } -String Example::image_ref_func(Ref p_image) { +String MyTestMain::image_ref_func(Ref p_image) { return p_image.is_valid() ? String("valid") : String("invalid"); } -String Example::image_const_ref_func(const Ref &p_image) { +String MyTestMain::image_const_ref_func(const Ref &p_image) { return p_image.is_valid() ? String("valid") : String("invalid"); } -String Example::return_something(const String &base) { +String MyTestMain::return_something(const String &base) { return base + String("42"); } -Viewport *Example::return_something_const() const { +Viewport *MyTestMain::return_something_const() const { if (is_inside_tree()) { Viewport *result = get_viewport(); return result; @@ -374,43 +374,43 @@ Viewport *Example::return_something_const() const { return nullptr; } -Ref Example::return_empty_ref() const { - Ref ref; +Ref MyTestMain::return_empty_ref() const { + Ref ref; return ref; } -Ref Example::return_extended_ref() const { - return memnew(ExampleRef()); +Ref MyTestMain::return_extended_ref() const { + return memnew(MyTestRef()); } -Ref Example::extended_ref_checks(Ref p_ref) const { +Ref MyTestMain::extended_ref_checks(Ref p_ref) const { // This is therefore the preferred way of instancing and returning a refcounted object: - Ref ref; + Ref ref; ref.instantiate(); return ref; } -Variant Example::varargs_func(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { +Variant MyTestMain::varargs_func(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { return arg_count; } -int Example::varargs_func_nv(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { +int MyTestMain::varargs_func_nv(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { return 42 + arg_count; } -void Example::varargs_func_void(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { +void MyTestMain::varargs_func_void(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) { emit_custom_signal("varargs_func_void", arg_count + 1); } -void Example::emit_custom_signal(const String &name, int value) { +void MyTestMain::emit_custom_signal(const String &name, int value) { emit_signal("custom_signal", name, value); } -bool Example::is_object_binding_set_by_parent_constructor() const { +bool MyTestMain::is_object_binding_set_by_parent_constructor() const { return object_instance_binding_set_by_parent_constructor; } -Array Example::test_array() const { +Array MyTestMain::test_array() const { Array arr; arr.resize(2); @@ -420,7 +420,7 @@ Array Example::test_array() const { return arr; } -String Example::test_string_ops() const { +String MyTestMain::test_string_ops() const { String s = String("A"); s += "B"; s += "C"; @@ -429,15 +429,15 @@ String Example::test_string_ops() const { return s; } -String Example::test_str_utility() const { +String MyTestMain::test_str_utility() const { return UtilityFunctions::str("Hello, ", "World", "! The answer is ", 42); } -bool Example::test_string_is_forty_two(const String &p_string) const { +bool MyTestMain::test_string_is_forty_two(const String &p_string) const { return strcmp(p_string.utf8().ptr(), "forty two") == 0; } -String Example::test_string_resize(String p_string) const { +String MyTestMain::test_string_resize(String p_string) const { int orig_len = p_string.length(); p_string.resize(orig_len + 3); char32_t *data = p_string.ptrw(); @@ -447,7 +447,7 @@ String Example::test_string_resize(String p_string) const { return p_string; } -TypedArray Example::test_typed_array_of_packed() const { +TypedArray MyTestMain::test_typed_array_of_packed() const { TypedArray arr; PackedInt32Array packed_arr1; packed_arr1.push_back(1); @@ -460,7 +460,7 @@ TypedArray Example::test_typed_array_of_packed() const { return arr; } -int Example::test_vector_ops() const { +int MyTestMain::test_vector_ops() const { PackedInt32Array arr; arr.push_back(10); arr.push_back(20); @@ -473,7 +473,7 @@ int Example::test_vector_ops() const { return ret; } -int Example::test_vector_init_list() const { +int MyTestMain::test_vector_init_list() const { PackedInt32Array arr = { 10, 20, 30, 45 }; int ret = 0; for (const int32_t &E : arr) { @@ -482,38 +482,38 @@ int Example::test_vector_init_list() const { return ret; } -Callable Example::test_callable_mp() { - return callable_mp(this, &Example::unbound_method1); +Callable MyTestMain::test_callable_mp() { + return callable_mp(this, &MyTestMain::unbound_method1); } -Callable Example::test_callable_mp_ret() { - return callable_mp(this, &Example::unbound_method2); +Callable MyTestMain::test_callable_mp_ret() { + return callable_mp(this, &MyTestMain::unbound_method2); } -Callable Example::test_callable_mp_retc() const { - return callable_mp(this, &Example::unbound_method3); +Callable MyTestMain::test_callable_mp_retc() const { + return callable_mp(this, &MyTestMain::unbound_method3); } -Callable Example::test_callable_mp_static() const { - return callable_mp_static(&Example::unbound_static_method1); +Callable MyTestMain::test_callable_mp_static() const { + return callable_mp_static(&MyTestMain::unbound_static_method1); } -Callable Example::test_callable_mp_static_ret() const { - return callable_mp_static(&Example::unbound_static_method2); +Callable MyTestMain::test_callable_mp_static_ret() const { + return callable_mp_static(&MyTestMain::unbound_static_method2); } -Callable Example::test_custom_callable() const { +Callable MyTestMain::test_custom_callable() const { return Callable(memnew(MyCallableCustom)); } -void Example::unbound_method1(Object *p_object, String p_string, int p_int) { +void MyTestMain::unbound_method1(Object *p_object, String p_string, int p_int) { String test = "unbound_method1: "; test += p_object->get_class(); test += " - " + p_string; emit_custom_signal(test, p_int); } -String Example::unbound_method2(Object *p_object, String p_string, int p_int) { +String MyTestMain::unbound_method2(Object *p_object, String p_string, int p_int) { String test = "unbound_method2: "; test += p_object->get_class(); test += " - " + p_string; @@ -521,7 +521,7 @@ String Example::unbound_method2(Object *p_object, String p_string, int p_int) { return test; } -String Example::unbound_method3(Object *p_object, String p_string, int p_int) const { +String MyTestMain::unbound_method3(Object *p_object, String p_string, int p_int) const { String test = "unbound_method3: "; test += p_object->get_class(); test += " - " + p_string; @@ -529,14 +529,14 @@ String Example::unbound_method3(Object *p_object, String p_string, int p_int) co return test; } -void Example::unbound_static_method1(Example *p_object, String p_string, int p_int) { +void MyTestMain::unbound_static_method1(MyTestMain *p_object, String p_string, int p_int) { String test = "unbound_static_method1: "; test += p_object->get_class(); test += " - " + p_string; p_object->emit_custom_signal(test, p_int); } -String Example::unbound_static_method2(Object *p_object, String p_string, int p_int) { +String MyTestMain::unbound_static_method2(Object *p_object, String p_string, int p_int) { String test = "unbound_static_method2: "; test += p_object->get_class(); test += " - " + p_string; @@ -544,7 +544,7 @@ String Example::unbound_static_method2(Object *p_object, String p_string, int p_ return test; } -int Example::test_tarray_arg(const TypedArray &p_array) { +int MyTestMain::test_tarray_arg(const TypedArray &p_array) { int sum = 0; for (int i = 0; i < p_array.size(); i++) { sum += (int)p_array[i]; @@ -552,7 +552,7 @@ int Example::test_tarray_arg(const TypedArray &p_array) { return sum; } -TypedArray Example::test_tarray() const { +TypedArray MyTestMain::test_tarray() const { TypedArray arr; arr.resize(2); @@ -562,7 +562,7 @@ TypedArray Example::test_tarray() const { return arr; } -Dictionary Example::test_dictionary() const { +Dictionary MyTestMain::test_dictionary() const { Dictionary dict; dict["hello"] = "world"; @@ -572,7 +572,7 @@ Dictionary Example::test_dictionary() const { } #if GODOT_VERSION_MINOR >= 4 -int Example::test_tdictionary_arg(const TypedDictionary &p_dictionary) { +int MyTestMain::test_tdictionary_arg(const TypedDictionary &p_dictionary) { int sum = 0; TypedArray values = p_dictionary.values(); for (int i = 0; i < p_dictionary.size(); i++) { @@ -581,7 +581,7 @@ int Example::test_tdictionary_arg(const TypedDictionary &p_dict return sum; } -TypedDictionary Example::test_tdictionary() const { +TypedDictionary MyTestMain::test_tdictionary() const { TypedDictionary dict; dict[Vector2(1, 2)] = Vector2i(2, 3); @@ -590,60 +590,60 @@ TypedDictionary Example::test_tdictionary() const { } #endif // GODOT_VERSION_MINOR >= 4 -Example *Example::test_node_argument(Example *p_node) const { +MyTestMain *MyTestMain::test_node_argument(MyTestMain *p_node) const { return p_node; } -bool Example::test_object_cast_to_node(Object *p_object) const { +bool MyTestMain::test_object_cast_to_node(Object *p_object) const { return Object::cast_to(p_object) != nullptr; } -bool Example::test_object_cast_to_control(Object *p_object) const { +bool MyTestMain::test_object_cast_to_control(Object *p_object) const { return Object::cast_to(p_object) != nullptr; } -bool Example::test_object_cast_to_example(Object *p_object) const { - return Object::cast_to(p_object) != nullptr; +bool MyTestMain::test_object_cast_to_my_test_main(Object *p_object) const { + return Object::cast_to(p_object) != nullptr; } -Vector2i Example::test_variant_vector2i_conversion(const Variant &p_variant) const { +Vector2i MyTestMain::test_variant_vector2i_conversion(const Variant &p_variant) const { return p_variant; } -int Example::test_variant_int_conversion(const Variant &p_variant) const { +int MyTestMain::test_variant_int_conversion(const Variant &p_variant) const { return p_variant; } -float Example::test_variant_float_conversion(const Variant &p_variant) const { +float MyTestMain::test_variant_float_conversion(const Variant &p_variant) const { return p_variant; } -bool Example::test_object_is_valid(const Variant &p_variant) const { +bool MyTestMain::test_object_is_valid(const Variant &p_variant) const { return static_cast(p_variant.get_validated_object()); } -void Example::test_add_child(Node *p_node) { +void MyTestMain::test_add_child(Node *p_node) { add_child(p_node); } -void Example::test_set_tileset(TileMap *p_tilemap, const Ref &p_tileset) const { +void MyTestMain::test_set_tileset(TileMap *p_tilemap, const Ref &p_tileset) const { p_tilemap->set_tileset(p_tileset); } -bool Example::test_tween_smoke_test() { +bool MyTestMain::test_tween_smoke_test() { Ref tween = create_tween(); return tween.is_valid() && tween->is_class("Tween") && tween->get_reference_count() > 1; } -Variant Example::test_variant_call(Variant p_variant) { +Variant MyTestMain::test_variant_call(Variant p_variant) { return p_variant.call("test", "hello"); } -BitField Example::test_bitfield(BitField flags) { +BitField MyTestMain::test_bitfield(BitField flags) { return flags; } -Variant Example::test_variant_iterator(const Variant &p_input) { +Variant MyTestMain::test_variant_iterator(const Variant &p_input) { Array output; Variant iter; @@ -678,76 +678,76 @@ Variant Example::test_variant_iterator(const Variant &p_input) { return output; } -void Example::test_rpc(int p_value) { +void MyTestMain::test_rpc(int p_value) { last_rpc_arg = p_value; } -void Example::test_send_rpc(int p_value) { +void MyTestMain::test_send_rpc(int p_value) { rpc("test_rpc", p_value); } -int Example::return_last_rpc_arg() { +int MyTestMain::return_last_rpc_arg() { return last_rpc_arg; } -void Example::callable_bind() { +void MyTestMain::callable_bind() { Callable c = Callable(this, "emit_custom_signal").bind("bound", 11); c.call(); } // Properties. -void Example::set_custom_position(const Vector2 &pos) { +void MyTestMain::set_custom_position(const Vector2 &pos) { custom_position = pos; } -Vector2 Example::get_custom_position() const { +Vector2 MyTestMain::get_custom_position() const { return custom_position; } -Vector4 Example::get_v4() const { +Vector4 MyTestMain::get_v4() const { return Vector4(1.2, 3.4, 5.6, 7.8); } -bool Example::test_post_initialize() const { - Ref new_example_ref; - new_example_ref.instantiate(); - return new_example_ref->was_post_initialized(); +bool MyTestMain::test_post_initialize() const { + Ref new_my_test_ref; + new_my_test_ref.instantiate(); + return new_my_test_ref->was_post_initialized(); } // Virtual function override. -bool Example::_has_point(const Vector2 &point) const { +bool MyTestMain::_has_point(const Vector2 &point) const { Label *label = get_node