Skip to content
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

Closed
wants to merge 2 commits into from
Closed

More object unit tests #44387

wants to merge 2 commits into from

Conversation

rmarco3e8
Copy link

Hello, this is my first pull request so any suggested changes or constructive criticism will be much-appreciated. I tried building off of the existing unit tests for the object class.

I added two test cases. One is a brief test of the setter and getter methods of the script interface of the Object class. The second runs through some tests of a number of methods including setters and getters in the IAPI interface of the Object class. One missing case regarding the get_indexed() and set_indexed() methods is for Vector arguments of size greater than 1. I had some trouble getting the methods to update r_valid to true in this case.


TEST_CASE("[Object] IAPI methods") {
Object object;
bool *rvalid = memnew(bool(false));
Copy link
Contributor

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:

Suggested change
bool *rvalid = memnew(bool(false));
bool valid = false;

and then pass the pointer to methods which use this variable, such as below:

object.get_indexed(p_names, &valid);

Also, this way you don't have to dereference the pointer (*valid) whenever you need to reset the valid variable for other assertions.

Object object;
bool *rvalid = memnew(bool(false));

object.set(StringName("script"), "script_source", rvalid);
Copy link
Contributor

Choose a reason for hiding this comment

The 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 StringName:

Suggested change
object.set(StringName("script"), "script_source", rvalid);
object.set("script", "script_source", rvalid);

The same applies to other assertions.

*rvalid == false,
"set_indexed() should update the passed bool to the expected value for empty Vector<StringName>.");

*rvalid = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: should this be reset to false (at least for consistency)?

Suggested change
*rvalid = true;
*rvalid = false;

@akien-mga
Copy link
Member

Sorry for the late review. This was at least partially superseded by #45411. If there are some parts tested here which are not covered in the latest version they might be worth sending as a new PR based on the latest master branch (note that the file moved to tests/core/object/test_object.h).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants