mirror of
https://github.com/godotengine/godot-cpp.git
synced 2025-12-31 01:48:45 +03:00
Test that internal classes work as expected
This commit is contained in:
@@ -287,6 +287,13 @@ func _ready():
|
||||
assert_equal(library_path, ProjectSettings.globalize_path(library_path))
|
||||
assert_equal(FileAccess.file_exists(library_path), true)
|
||||
|
||||
# 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(internal_class.get_the_answer(), 42)
|
||||
assert_equal(internal_class.get_class(), "ExampleInternal")
|
||||
|
||||
# Test a class with a unicode name.
|
||||
var przykład = ExamplePrzykład.new()
|
||||
assert_equal(przykład.get_the_word(), "słowo to przykład")
|
||||
|
||||
@@ -252,6 +252,8 @@ void Example::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("test_use_engine_singleton"), &Example::test_use_engine_singleton);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("test_get_internal_class"), &Example::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);
|
||||
|
||||
@@ -744,6 +746,12 @@ String Example::test_library_path() {
|
||||
return library_path;
|
||||
}
|
||||
|
||||
Ref<RefCounted> Example::test_get_internal_class() const {
|
||||
Ref<ExampleInternal> it;
|
||||
it.instantiate();
|
||||
return it;
|
||||
}
|
||||
|
||||
int64_t Example::test_get_internal(const Variant &p_input) const {
|
||||
if (p_input.get_type() != Variant::INT) {
|
||||
return -1;
|
||||
@@ -779,3 +787,11 @@ void ExamplePrzykład::_bind_methods() {
|
||||
String ExamplePrzykład::get_the_word() const {
|
||||
return U"słowo to przykład";
|
||||
}
|
||||
|
||||
void ExampleInternal::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_the_answer"), &ExampleInternal::get_the_answer);
|
||||
}
|
||||
|
||||
int ExampleInternal::get_the_answer() const {
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
using namespace godot;
|
||||
|
||||
class ExampleInternal;
|
||||
|
||||
class ExampleRef : public RefCounted {
|
||||
GDCLASS(ExampleRef, RefCounted);
|
||||
|
||||
@@ -203,6 +205,8 @@ public:
|
||||
String test_use_engine_singleton() const;
|
||||
|
||||
static String test_library_path();
|
||||
|
||||
Ref<RefCounted> test_get_internal_class() const;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Example::Constants);
|
||||
@@ -288,3 +292,13 @@ protected:
|
||||
public:
|
||||
String get_the_word() const;
|
||||
};
|
||||
|
||||
class ExampleInternal : public RefCounted {
|
||||
GDCLASS(ExampleInternal, RefCounted);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
int get_the_answer() const;
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
|
||||
GDREGISTER_CLASS(ExampleChild);
|
||||
GDREGISTER_RUNTIME_CLASS(ExampleRuntime);
|
||||
GDREGISTER_CLASS(ExamplePrzykład);
|
||||
GDREGISTER_INTERNAL_CLASS(ExampleInternal);
|
||||
}
|
||||
|
||||
void uninitialize_example_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
Reference in New Issue
Block a user