gtest ASSERT_TRUE和EXPECT_TRUE
2024-08-26 02:49:17
调用ASSERT_TRUE的函数,返回值类型定义必须是void,如果想返回别的类型,就用EXPECT_TRUE:
void abc::fun()
{
ASSERT_TRUE(fun1());
}
bool abc::fun()
{
bool result = fun1();
EXPECT_TRUE(result );
return result ;
}
ASSERT_TRUE is a macro. When expanded it will contain a branch like:
if (fun1() == false) {
return;
}
This is how ASSERT_TRUE does a hard stop on failure, but it also means that your method bool abc::fun() now has a void return exit path, in conflict with its signature.
Possible fixes include don't use hard stop asserts:
bool abc::fun(){
bool result = fun1();
EXPECT_TRUE(result); //No return in expansion
//No hard stop!
return result;
}
or change your methods return type if not needed:
void abc::fun(){
ASSERT_TRUE(fun1()); //Hard stop on failure
}
or return by reference:
void abc::fun(bool &outResult){
outResult = fun1(); //return result by reference
ASSERT_TRUE(result);
}
最新文章
- 19.在HTTP 1.0中,状态码401的含义是(?);如果返回“找不到文件”的提示,则可用 header 函数,其语句为(?)写出http常见的状态码和含义,至少5个.[完善题目]
- openlayers 注册事件例子
- 好的博客mark
- 单例模式(Winform窗体的实现)
- 针对BootStrap中tabs控件的美化和完善
- 汉字编码:GB2312, GBK, GB18030, Big5
- 关于”机器学习方法“,&;quot;深度学习方法&;quot;系列
- auDemo
- shell-逐行读取文件
- 获取Django项目的全部url
- bzoj 2303: [Apio2011]方格染色
- 利用FPN构建Faster R-CNN检测
- 网上看到一份详细sql游标说明 《转载 https://www.cnblogs.com/xiongzaiqiren/p/sql-cursor.html》
- 《Java大学教程》—第14章 抽象、继承和接口
- Python:Day53 Template基础
- 生产环境Linux常用命令【随时更新】
- Cartographer源码阅读(8):imu_tracker
- mysql日期操作
- Android Retrofit2.1.0设置编码格式GBK
- Codeforces 1077 F2 - Pictures with Kittens (hard version)
热门文章
- 定义Portal显示规则
- samba 奇怪问题
- memory management in oracle 11G R2
- 中间件解析FDMEMTABLE.delta生成SQL的方法
- gradle: 修改gradle-xx-bin.zip下载地址
- 还原对于server失败 备份集中的数据库备份与现有数据库不同
- C++中stringstream ostringstream istringstream使用方式
- Modular_exponentiation模幂运算
- 第一篇 Windows 8 开发Windows Metro style app环境配置
- Quartz.net使用入门(三)