【发布时间】:2015-08-25 12:34:37
【问题描述】:
我有以下 C 代码想要使用谷歌测试框架进行测试:
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() */
}
我想在文件b 中测试函数void formValue(),所以我为void getValue(int age, int * value) 创建了以下模拟:
// AFileMock.hh
#包括
#include "a.h"
class AFileMock {
public:
AFileMock();
~AFileMock();
MOCK_METHOD1(getValue, void(int, int *));
};
然后在测试文件中我想调用模拟函数getValue并返回void getValue(int age, int * value)部分的值,但是在调用模拟函数时如何返回value array的输出参数?
#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();
}
那么在这种情况下,当调用mock函数时,如何返回数组的值呢?
【问题讨论】:
-
也许这会有所帮助:code.google.com/p/googlemock/wiki/…
标签: c++ googletest googlemock