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 :: age in days in c++ 
Cpp :: volumeof a sphere 
Cpp :: add input in c++ 
Cpp :: how to increase array memory in c++ 
Cpp :: c++ program to convert fahrenheit to celsius 
Cpp :: C++ if...else...else if statement 
Cpp :: modular exponentiation algorithm c++ 
Cpp :: Shuffle String leetcode solution in c++ 
Cpp :: assignment operator with pointers c++ 
Cpp :: shortest path in unweighted graph bfs 
Cpp :: unordered_map c++ 
Cpp :: time complexity of best sort algorithm 
Cpp :: split string in c++ 
Cpp :: c++ pointers and arrays 
Cpp :: priority queue in cpp 
Cpp :: valid parentheses in c++ 
Cpp :: A Program to check if strings are rotations of each other or not 
Cpp :: c++ function overloading 
Cpp :: c++ custom printf 
Cpp :: double plus overload 
Cpp :: fname from FString 
Cpp :: gtest assert not equal 
Cpp :: unambiguous 
Cpp :: no of balanced substrings 
Cpp :: strcmp in c++ header file 
Cpp :: setFontSize QT 
Cpp :: opengl draw cresent moon c++ 
Cpp :: sort vector in descending order c++ 
Cpp :: sjfoajf;klsjflasdkfjk;lasjfjajkf;dslafjdjalkkkjakkkkkkkkkkkkkkkkfaWZdfbhjkkkk gauds 
Cpp :: c++ click event 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =