1 | initial version |
Yes, it is possible to check all the components of an array pointer that is passed to a mocked function using Googlemock for C++. A common way to do this is to use the ElementsAreArray()
matcher, which allows the user to specify the expected array elements as a standard C++ array or a pointer followed by the number of elements.
Here's an example of how to use it:
// Suppose we have a mock function that takes an array of integers
MOCK_METHOD(void, myMockFunc, (int* arr, int arrSize));
// We can use EXPECT_CALL to set up the expectation
int expectedArr[] = {1, 2, 3};
EXPECT_CALL(mockObj, myMockFunc(ElementsAreArray(expectedArr)));
// Now we can call the function with an array and the expectation will be checked
int actualArr[] = {1, 2, 3};
mockObj.myMockFunc(actualArr, 3);
In this example, the ElementsAreArray()
matcher ensures that the actualArr
passed to myMockFunc()
contains the same elements as expectedArr
. If the expectation is not met, the test will fail.