Reputation: 1671
I have the following code in C want to be test in using google testing framework:
a.h
void getValue(int age, int * value);
a.c
#include <a.h>
void getValue(int age, int * value)
{
value[0] = 0;
value[1] = 1;
}
b.c
#include <a.h>
void formValue()
{
int value[2];
getValue(age, value);
/* the code to handle the value[] array */
/* for() */
}
I want to test the function void formValue()
in file b
, so I created the following mock for void getValue(int age, int * value)
:
// AFileMock.hh
#include
#include "a.h"
class AFileMock {
public:
AFileMock();
~AFileMock();
MOCK_METHOD1(getValue, void(int, int *));
};
then in the test file I want to call the mocked function getValue
and return the value for the void getValue(int age, int * value)
part, but how to return the out coming parameter of value array
when call a mock function?
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <b.h>
#include <AFileMock.h>
using testing::_;
using testing::Return;
using testing::InSequence;
class BTest: public testing::Test {
protected:
AFileMock aFile;
public:
void SetUp() { }
void TearDown() { }
};
TEST_F(BTest, test1)
{
InSequence sequence;
EXPECT_CALL(aFile, getValue(_, _)).
Times(1); // when this mock function is called, how to return the value of the array?
formValue();
}
so in this case, when the mock function is called, how to return the value of array?
Upvotes: 3
Views: 8408
Reputation: 6962
I cannot understand your sample code, a.c
doesn't even compile. But I guess the answer you are looking for is Gmock Actions. A rich set of them is provided.
Upvotes: 2