zoukankan      html  css  js  c++  java
  • gtest ASSERT_TRUE和EXPECT_TRUE

    调用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);
    }
    

    引用地址

  • 相关阅读:
    POJ2524+并查集
    POJ3697+BFS+hash存边
    POJ1151+线段树+扫描线
    POJ2528+线段树
    ubuntu 和 win7 远程登陆 + vnc登陆
    POJ3690+位运算
    POJ3283+字典树
    POJ3282+模拟
    POJ2349+prim
    2016.6.13
  • 原文地址:https://www.cnblogs.com/catmelo/p/7125648.html
Copyright © 2011-2022 走看看