-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More object unit tests #44387
More object unit tests #44387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -87,6 +87,97 @@ TEST_CASE("[Object] Metadata") { | |||||
meta_list2.size() == 0, | ||||||
"The metadata list should contain 0 items after removing all metadata items."); | ||||||
} | ||||||
|
||||||
TEST_CASE("[Object] IAPI methods") { | ||||||
Object object; | ||||||
bool *rvalid = memnew(bool(false)); | ||||||
|
||||||
object.set(StringName("script"), "script_source", rvalid); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure but I think there's no need to explicitly convert the first argument to
Suggested change
The same applies to other assertions. |
||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"set() should update the passed bool to the expected value."); | ||||||
|
||||||
*rvalid = false; | ||||||
CHECK_MESSAGE( | ||||||
object.get(StringName("script"), rvalid) == "script_source", | ||||||
"get() should return the expected value."); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"get() should update the passed bool to the expected value."); | ||||||
|
||||||
Vector<StringName> p_names; | ||||||
object.set_indexed(p_names, "value", rvalid); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == false, | ||||||
"set_indexed() should update the passed bool to the expected value for empty Vector<StringName>."); | ||||||
|
||||||
*rvalid = true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanity check: should this be reset to
Suggested change
|
||||||
CHECK_MESSAGE( | ||||||
object.get_indexed(p_names, rvalid) == Variant(), | ||||||
"get_indexed() should return the expected value for empty Vector<StringName>."); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == false, | ||||||
"get_indexed() should update the passed bool to the expected value for empty Vector<StringName>."); | ||||||
|
||||||
p_names.push_back(StringName("script")); | ||||||
object.set_indexed(p_names, "indexed_script_source", rvalid); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"set_indexed() should update the passed bool to the expected value for valid Vector<StringName> of size 1."); | ||||||
|
||||||
*rvalid = false; | ||||||
CHECK_MESSAGE( | ||||||
object.get_indexed(p_names, rvalid) == "indexed_script_source", | ||||||
"get_indexed() should return the expected value for valid Vector<StringName> of size 1."); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"get_indexed() should update the passed bool to the expected value for valid Vector<StringName> of size 1."); | ||||||
|
||||||
CHECK_MESSAGE( | ||||||
object.has_method(StringName("free")) == true, | ||||||
"has_method() should return the expected value for StringName('free')"); | ||||||
|
||||||
CHECK_MESSAGE( | ||||||
object.has_method(StringName("_to_string")) == false, | ||||||
"has_method() should return the expected value for non-method"); | ||||||
|
||||||
CHECK_MESSAGE( | ||||||
object.to_string() == "[Object:" + itos(object.get_instance_id()) + "]", | ||||||
"to_string() should return the expected value."); | ||||||
|
||||||
*rvalid = false; | ||||||
CHECK_MESSAGE( | ||||||
object.getvar(StringName("script"), rvalid) == "indexed_script_source", | ||||||
"getvar() should return the expected value."); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"getvar() should update the passed bool to the expected value."); | ||||||
|
||||||
*rvalid = false; | ||||||
object.setvar(StringName("script"), "var_script", rvalid); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == true, | ||||||
"setvar() should update the passed bool to the expected value."); | ||||||
CHECK_MESSAGE( | ||||||
object.getvar(StringName("script"), rvalid) == "var_script", | ||||||
"getvar() should return the expected value."); | ||||||
|
||||||
object.setvar(StringName("non-CoreStringName"), "nonvalid_script", rvalid); | ||||||
CHECK_MESSAGE( | ||||||
*rvalid == false, | ||||||
"setvar() should update the passed bool to the expected value."); | ||||||
|
||||||
memdelete(rvalid); | ||||||
} | ||||||
|
||||||
TEST_CASE("[Object] Script setter and getter") { | ||||||
Object object; | ||||||
|
||||||
object.set_script("script_source"); | ||||||
CHECK_MESSAGE( | ||||||
object.get_script() == "script_source", | ||||||
"get_script() should return the expected value."); | ||||||
} | ||||||
} // namespace TestObject | ||||||
|
||||||
#endif // TEST_OBJECT_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this adds unnecessary complexity, I'd rewrite this to:
and then pass the pointer to methods which use this variable, such as below:
Also, this way you don't have to dereference the pointer (
*valid
) whenever you need to reset thevalid
variable for other assertions.