Skip to content

Commit 61998b1

Browse files
[Tests] Ensure all default method arguments can be encoded
Checks that all arguments of bound methods can be encoded in extensions, checking non-empty or non-null cases for containers and objects
1 parent 96be44c commit 61998b1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/core/object/test_class_db.h

+40
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,38 @@ bool arg_default_value_is_assignable_to_type(const Context &p_context, const Var
289289
return false;
290290
}
291291

292+
bool arg_default_value_is_valid_data(const Variant &p_val, String *r_err_msg = nullptr) {
293+
switch (p_val.get_type()) {
294+
case Variant::RID:
295+
case Variant::ARRAY:
296+
case Variant::DICTIONARY:
297+
case Variant::PACKED_BYTE_ARRAY:
298+
case Variant::PACKED_INT32_ARRAY:
299+
case Variant::PACKED_INT64_ARRAY:
300+
case Variant::PACKED_FLOAT32_ARRAY:
301+
case Variant::PACKED_FLOAT64_ARRAY:
302+
case Variant::PACKED_STRING_ARRAY:
303+
case Variant::PACKED_VECTOR2_ARRAY:
304+
case Variant::PACKED_VECTOR3_ARRAY:
305+
case Variant::PACKED_COLOR_ARRAY:
306+
case Variant::PACKED_VECTOR4_ARRAY:
307+
case Variant::CALLABLE:
308+
case Variant::SIGNAL:
309+
case Variant::OBJECT:
310+
if (p_val.is_zero()) {
311+
return true;
312+
}
313+
if (r_err_msg) {
314+
*r_err_msg = "Must be zero.";
315+
}
316+
break;
317+
default:
318+
return true;
319+
}
320+
321+
return false;
322+
}
323+
292324
void validate_property(const Context &p_context, const ExposedClass &p_class, const PropertyData &p_prop) {
293325
const MethodData *setter = p_class.find_method_by_name(p_prop.setter);
294326

@@ -411,6 +443,14 @@ void validate_argument(const Context &p_context, const ExposedClass &p_class, co
411443
}
412444

413445
TEST_COND(!arg_defval_assignable_to_type, err_msg);
446+
447+
bool arg_defval_valid_data = arg_default_value_is_valid_data(p_arg.defval, &type_error_msg);
448+
449+
if (!type_error_msg.is_empty()) {
450+
err_msg += " " + type_error_msg;
451+
}
452+
453+
TEST_COND(!arg_defval_valid_data, err_msg);
414454
}
415455
}
416456

0 commit comments

Comments
 (0)