Ask Your Question
4

What is the method to read the contents of an array pointer that has been passed to a Googlemock mocked method?

asked 2022-01-02 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-02 10:00:00 +0000

scrum gravatar image

To read the contents of an array pointer that has been passed to a Googlemock mocked method, you can use the ElementsAreArray() matcher provided by Googlemock.

Here's an example:

int arr[3] = {1, 2, 3};
EXPECT_CALL(mockedObject, mockedMethod(ElementsAreArray(arr, 3)));

// Inside the mocked method:
void mockedMethod(int* arr, int length) {
    // Use the passed array pointer and length here
}

In this example, the ElementsAreArray() matcher checks that the passed array is identical to the arr array with length 3. Inside the mocked method, you can use the arr pointer and length to read the contents of the passed array.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-02 11:00:00 +0000

Seen: 1 times

Last updated: Feb 02 '22