GMOCK参数验证
GMOCK Argument Verification
我有一个类,其成员数组类型为int
// Class Defenition
class Foo {
int array[5];
// ... Other Memebers
}
拥有另一个具有成员函数的类,该函数具有Foo*类型的参数
class SerialTXInterface {
public:
virtual bool print_foo(Foo* strPtr) = 0;
// ... Other Members
};
上述方法的模型:
MOCK_METHOD1(print_str_s, bool(Array_s<char>* strPtr));
串行TX接口
SerialTXInterface* STX = &SerialTXObject;
Foo对象
Foo FooObj;
函数调用
STX.print_foo(&FooOjb)
如何验证Foo成员数组[5]=={1,2,3,4,5}
这对我有效(如果我将Foo::array
公开)
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;
class Foo {
public:
int array[5];
// ... Other Memebers
};
class SerialTXInterface {
public:
virtual bool print_foo(Foo* strPtr) = 0;
// ... Other Members
};
class SerialTXMock {
public:
MOCK_METHOD1(print_foo, bool(Foo* strPtr));
};
TEST(STXUser, Sends12345)
{
SerialTXMock STXM;
EXPECT_CALL(STXM, print_foo(Pointee(Field(&Foo::array,ElementsAre(1,2,3,4, 5)))));
Foo testfoo = {{1,2,3,4,5}};
STXM.print_foo(&testfoo);
}
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- boost::p rogram_options 验证每个参数而不是每个参数类型?
- GoogleMock:如何验证输入参数的调用次数?
- 对象验证的模板参数
- 用于验证请求的哈希参数
- 使用constexpr验证构造函数中的文字参数
- GMOCK参数验证
- 随机参数验证
- 处理命令行参数解析/验证的代码段/lib
- CRT参数验证使多线程调试程序崩溃
- 如何验证传递给模拟函数的参数的派生类型
- std::function:严格的编译时参数验证
- 在编译时在c/c++预处理宏中验证参数为ARRAY类型
- 使用"断言"验证参数数
- 正在验证变量参数是否为预期类型