mirror of
https://github.com/godotengine/godot-cpp.git
synced 2026-01-07 10:10:08 +03:00
Add automated tests that run a GDExtension (rather than just building it)
This commit is contained in:
@@ -13,27 +13,26 @@
|
||||
|
||||
using namespace godot;
|
||||
|
||||
int ExampleRef::instance_count = 0;
|
||||
int ExampleRef::last_id = 0;
|
||||
void ExampleRef::set_id(int p_id) {
|
||||
id = p_id;
|
||||
}
|
||||
|
||||
int ExampleRef::get_id() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
|
||||
}
|
||||
|
||||
ExampleRef::ExampleRef() {
|
||||
id = ++last_id;
|
||||
instance_count++;
|
||||
|
||||
UtilityFunctions::print("ExampleRef ", itos(id), " created, current instance count: ", itos(instance_count));
|
||||
id = 0;
|
||||
}
|
||||
|
||||
ExampleRef::~ExampleRef() {
|
||||
instance_count--;
|
||||
UtilityFunctions::print("ExampleRef ", itos(id), " destroyed, current instance count: ", itos(instance_count));
|
||||
}
|
||||
|
||||
int Example::test_static(int p_a, int p_b) {
|
||||
@@ -41,7 +40,7 @@ int Example::test_static(int p_a, int p_b) {
|
||||
}
|
||||
|
||||
void Example::test_static2() {
|
||||
UtilityFunctions::print(" void static");
|
||||
//UtilityFunctions::print(" void static");
|
||||
}
|
||||
|
||||
int Example::def_args(int p_a, int p_b) {
|
||||
@@ -49,7 +48,7 @@ int Example::def_args(int p_a, int p_b) {
|
||||
}
|
||||
|
||||
void Example::_notification(int p_what) {
|
||||
UtilityFunctions::print("Notification: ", String::num(p_what));
|
||||
//UtilityFunctions::print("Notification: ", String::num(p_what));
|
||||
}
|
||||
|
||||
bool Example::_set(const StringName &p_name, const Variant &p_value) {
|
||||
@@ -112,6 +111,10 @@ void Example::_bind_methods() {
|
||||
// Methods.
|
||||
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);
|
||||
@@ -179,29 +182,43 @@ void Example::_bind_methods() {
|
||||
}
|
||||
|
||||
Example::Example() {
|
||||
UtilityFunctions::print("Constructor.");
|
||||
//UtilityFunctions::print("Constructor.");
|
||||
}
|
||||
|
||||
Example::~Example() {
|
||||
UtilityFunctions::print("Destructor.");
|
||||
//UtilityFunctions::print("Destructor.");
|
||||
}
|
||||
|
||||
// Methods.
|
||||
void Example::simple_func() {
|
||||
UtilityFunctions::print(" Simple func called.");
|
||||
emit_custom_signal("simple_func", 3);
|
||||
}
|
||||
|
||||
void Example::simple_const_func() const {
|
||||
UtilityFunctions::print(" Simple const func called.");
|
||||
((Example *)this)->emit_custom_signal("simple_const_func", 4);
|
||||
}
|
||||
|
||||
int Example::custom_ref_func(Ref<ExampleRef> p_ref) {
|
||||
return p_ref.is_valid() ? p_ref->get_id() : -1;
|
||||
}
|
||||
|
||||
int Example::custom_const_ref_func(const Ref<ExampleRef> &p_ref) {
|
||||
return p_ref.is_valid() ? p_ref->get_id() : -1;
|
||||
}
|
||||
|
||||
String Example::image_ref_func(Ref<Image> p_image) {
|
||||
return p_image.is_valid() ? String("valid") : String("invalid");
|
||||
}
|
||||
|
||||
String Example::image_const_ref_func(const Ref<Image> &p_image) {
|
||||
return p_image.is_valid() ? String("valid") : String("invalid");
|
||||
}
|
||||
|
||||
String Example::return_something(const String &base) {
|
||||
UtilityFunctions::print(" Return something called.");
|
||||
return base;
|
||||
return base + String("42");
|
||||
}
|
||||
|
||||
Viewport *Example::return_something_const() const {
|
||||
UtilityFunctions::print(" Return something const called.");
|
||||
if (is_inside_tree()) {
|
||||
Viewport *result = get_viewport();
|
||||
return result;
|
||||
@@ -221,32 +238,23 @@ ExampleRef *Example::return_extended_ref() const {
|
||||
return memnew(ExampleRef());
|
||||
}
|
||||
|
||||
Example *Example::test_node_argument(Example *p_node) const {
|
||||
UtilityFunctions::print(" Test node argument called with ", p_node ? String::num(p_node->get_instance_id()) : "null");
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Ref<ExampleRef> Example::extended_ref_checks(Ref<ExampleRef> p_ref) const {
|
||||
// This is therefor the prefered way of instancing and returning a refcounted object:
|
||||
Ref<ExampleRef> ref;
|
||||
ref.instantiate();
|
||||
|
||||
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, GDExtensionInt arg_count, GDExtensionCallError &error) {
|
||||
UtilityFunctions::print(" Varargs (Variant return) called with ", String::num((double)arg_count), " arguments");
|
||||
return arg_count;
|
||||
}
|
||||
|
||||
int Example::varargs_func_nv(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) {
|
||||
UtilityFunctions::print(" Varargs (int return) called with ", String::num((double)arg_count), " arguments");
|
||||
return 42;
|
||||
return 42 + arg_count;
|
||||
}
|
||||
|
||||
void Example::varargs_func_void(const Variant **args, GDExtensionInt arg_count, GDExtensionCallError &error) {
|
||||
UtilityFunctions::print(" Varargs (no return) called with ", String::num((double)arg_count), " arguments");
|
||||
emit_custom_signal("varargs_func_void", arg_count + 1);
|
||||
}
|
||||
|
||||
void Example::emit_custom_signal(const String &name, int value) {
|
||||
@@ -285,10 +293,12 @@ int Example::test_vector_ops() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Example::test_tarray_arg(const TypedArray<int64_t> &p_array) {
|
||||
int Example::test_tarray_arg(const TypedArray<int64_t> &p_array) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < p_array.size(); i++) {
|
||||
UtilityFunctions::print(p_array[i]);
|
||||
sum += (int)p_array[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
TypedArray<Vector2> Example::test_tarray() const {
|
||||
@@ -310,8 +320,11 @@ Dictionary Example::test_dictionary() const {
|
||||
return dict;
|
||||
}
|
||||
|
||||
Example *Example::test_node_argument(Example *p_node) const {
|
||||
return p_node;
|
||||
}
|
||||
|
||||
BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) {
|
||||
UtilityFunctions::print(" Got BitField: ", String::num_int64(flags));
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user