Horje
google test assert exception Code Example
google test assert exception
#include <stdexcept>
#include "gtest/gtest.h"

struct foo
{
    int bar(int i) {
        if (i > 100) {
            throw std::out_of_range("Out of range");
        }
        return i;
    }
};

TEST(foo_test,out_of_range)
{
    foo f;
    try {
        f.bar(111);
        FAIL() << "Expected std::out_of_range";
    }
    catch(std::out_of_range const & err) {
        EXPECT_EQ(err.what(),std::string("Out of range"));
    }
    catch(...) {
        FAIL() << "Expected std::out_of_range";
    }
}




Cpp

Related
phi function Code Example phi function Code Example
c++ execute thread and forget Code Example c++ execute thread and forget Code Example
nike Code Example nike Code Example
Chef and Races codechef solution in c++ Code Example Chef and Races codechef solution in c++ Code Example
how to set a variable to infinity in c++ Code Example how to set a variable to infinity in c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8