Horje
google test assert throw Code Example
google test assert throw
#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
Minimizing the dot product codechef in c++ Code Example Minimizing the dot product codechef in c++ Code Example
how to split string into words c++ Code Example how to split string into words c++ Code Example
Processing a string- CodeChef Solution in CPP Code Example Processing a string- CodeChef Solution in CPP Code Example
C++ Volume of a Sphere Code Example C++ Volume of a Sphere Code Example
how to print a word in c++ Code Example how to print a word in c++ Code Example

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