proxygen
UncaughtExceptionsTest.cpp File Reference
#include <folly/lang/UncaughtExceptions.h>
#include <folly/Conv.h>
#include <folly/portability/GTest.h>
#include <glog/logging.h>

Go to the source code of this file.

Classes

class  Validator
 
struct  ThrowInDestructor< N, I >
 
struct  ThrowInDestructor< N, 0 >
 
struct  ThrowingConstructor
 
struct  InheritsThrowingConstructor
 

Functions

 TEST (UncaughtExceptions, no_exception)
 
 TEST (UncaughtExceptions, no_uncaught_exception)
 
 TEST (UncaughtExceptions, one_uncaught_exception)
 
 TEST (UncaughtExceptions, catch_rethrow)
 
void throwingFunction ()
 
 TEST (UncaughtExceptions, one_uncaught_exception_in_function)
 
 TEST (UncaughtExceptions, two_uncaught_exceptions)
 
 TEST (UncaughtExceptions, ten_uncaught_exceptions)
 
 TEST (UncaughtExceptions, one_exception_in_ctor_initializer_expression)
 

Function Documentation

TEST ( UncaughtExceptions  ,
no_exception   
)

Definition at line 49 of file UncaughtExceptionsTest.cpp.

49  {
50  Validator validator(0, "no_exception");
51 }
TEST ( UncaughtExceptions  ,
no_uncaught_exception   
)

Definition at line 53 of file UncaughtExceptionsTest.cpp.

References Validator::validate().

53  {
54  Validator validator(0, "no_uncaught_exception");
55  try {
56  throw std::runtime_error("exception");
57  } catch (const std::runtime_error& e) {
58  validator.validate();
59  }
60 }
TEST ( UncaughtExceptions  ,
one_uncaught_exception   
)

Definition at line 62 of file UncaughtExceptionsTest.cpp.

62  {
63  try {
64  Validator validator(1, "one_uncaught_exception");
65  throw std::runtime_error("exception");
66  } catch (const std::runtime_error& e) {
67  }
68 }
TEST ( UncaughtExceptions  ,
catch_rethrow   
)

Definition at line 70 of file UncaughtExceptionsTest.cpp.

References EXPECT_EQ, and folly::uncaught_exceptions().

70  {
71  try {
72  Validator validatorOuter(1, "catch_rethrow_outer");
73  try {
74  Validator validatorInner(1, "catch_rethrow_inner");
75  throw std::runtime_error("exception");
76  } catch (const std::runtime_error& e) {
78  Validator validatorRethrow(1, "catch_rethrow");
79  throw;
80  }
81  } catch (const std::runtime_error& e) {
83  }
84 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int uncaught_exceptions() noexcept
TEST ( UncaughtExceptions  ,
one_uncaught_exception_in_function   
)

Definition at line 91 of file UncaughtExceptionsTest.cpp.

References EXPECT_THROW, and throwingFunction().

91  {
92  EXPECT_THROW({ throwingFunction(); }, std::runtime_error);
93 }
void throwingFunction()
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
TEST ( UncaughtExceptions  ,
two_uncaught_exceptions   
)

Definition at line 134 of file UncaughtExceptionsTest.cpp.

134  {
135  ThrowInDestructor<2> twoUncaughtExceptions;
136 }
TEST ( UncaughtExceptions  ,
ten_uncaught_exceptions   
)

Definition at line 138 of file UncaughtExceptionsTest.cpp.

138  {
139  ThrowInDestructor<10> twoUncaughtExceptions;
140 }
TEST ( UncaughtExceptions  ,
one_exception_in_ctor_initializer_expression   
)

Definition at line 161 of file UncaughtExceptionsTest.cpp.

References EXPECT_THROW.

161  {
162  EXPECT_THROW(
163  { InheritsThrowingConstructor inheritsThrowingConstructor; },
164  std::runtime_error);
165 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
void throwingFunction ( )

Definition at line 86 of file UncaughtExceptionsTest.cpp.

Referenced by TEST().

86  {
87  Validator validator(1, "one_uncaught_exception_in_function");
88  throw std::runtime_error("exception");
89 }