Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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";
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ pass ofstream as argument 
Cpp :: stoi in c++ 
Cpp :: c++ add input in 
Cpp :: call function from separate bash script 
Cpp :: arduino falling edge 
Cpp :: C++ Quotient and Remainder 
Cpp :: Abstract factory C++ code 
Cpp :: count number of char in a string c++ 
Cpp :: max heap insertion c++ 
Cpp :: pow without math.h 
Cpp :: How to pass a multidimensional array to a function in C and C++ 
Cpp :: time complexity of sorting algorithms 
Cpp :: how to use power in c++ 
Cpp :: sum of n natural numbers 
Cpp :: if not c++ 
Cpp :: valid parentheses in cpp 
Cpp :: assign value to a pointer 
Cpp :: even and odd numbers 1 to 100 
Cpp :: pause the console c++ 
Cpp :: create a copy of a vector c++ 
Cpp :: online converter c++ to c 
Cpp :: error C2011 
Cpp :: faster solutions 
Cpp :: c++ online 
Cpp :: how to pronounce beaucoup 
Cpp :: c++ to mips converter online 
Cpp :: string in int in cpp 
Cpp :: c++ template function in class 
Cpp :: ue4 c++ enum variable declaration 
Cpp :: contains in c++ map 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =