Suppose I have a class Alpha that has a member Beta. (specifically, a pointer to Beta is injected at construction); Beta is some object that will be mocked out later. But we care about what, precisely, Alpha calls when it calls a function from beta.
class Gamma{
private:
char array[15];
public:
char* getArray() { return &array[0]; }
}
class Alpha{
private:
Beta* m_beta;
public:
Alpha(Beta* external) : m_beta(external) {}
DoStuff(const Gamma& thing){
// ... maybe do some stuff with Gamma;
Beta->Function(thing.getArray(), 15);
}
};
class Beta{
public:
void Function(const char* array, int sizeOfArray);
};
class MockBeta : public Beta{
MOCK_METHOD2(Function, void(const char*, int));
}
using ::testing::_;
Test(AlphaTest, DoStuffTest){
char expectedArray[15] = {/*whatever*/};
char actualArray[15];
// char* arrayPtr = nullptr;
MockBeta mock_external;
Alpha testObject(&mock_external);
EXPECT_CALL(mock_external, Function(_,_))
.WillOnce(SaveArg<0>(&(&actualArray[0]));
// .WillOnce(SaveArg<0>(&arrayPtr));
}
This example complains on compile: cannot take the address of an rvalue of type 'char *' (on the line: .WillOnce(SaveArg<0>(&(&actualArray[0])); )
I've tried a variety of approaches. - A custom Action with parameter: ACTION_P(SaveToPtr, ptr) { ptr = arg0; } doesn't work because ptr is a const value for the custom actions.
- Instead of an array, I could try with just a general char*. But then it gives a compiler error that it's incomatible with type 'const char *const'
And probably other stuff.
Any ideas?