about summary refs log tree commit diff
path: root/absl/base/exception_safety_testing_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/base/exception_safety_testing_test.cc')
-rw-r--r--absl/base/exception_safety_testing_test.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/absl/base/exception_safety_testing_test.cc b/absl/base/exception_safety_testing_test.cc
index 1fc03861784e..5477b40a5bed 100644
--- a/absl/base/exception_safety_testing_test.cc
+++ b/absl/base/exception_safety_testing_test.cc
@@ -63,7 +63,7 @@ TEST_F(ThrowingValueTest, Throws) {
 // the countdown doesn't hit 0, and doesn't modify the state of the
 // ThrowingValue if it throws
 template <typename F>
-void TestOp(F&& f) {
+void TestOp(const F& f) {
   UnsetCountdown();
   ExpectNoThrow(f);
 
@@ -153,11 +153,21 @@ TEST_F(ThrowingValueTest, ThrowingStreamOps) {
   TestOp([&]() { std::cout << bomb; });
 }
 
+template <typename F>
+void TestAllocatingOp(const F& f) {
+  UnsetCountdown();
+  ExpectNoThrow(f);
+
+  SetCountdown();
+  EXPECT_THROW(f(), exceptions_internal::TestBadAllocException);
+  UnsetCountdown();
+}
+
 TEST_F(ThrowingValueTest, ThrowingAllocatingOps) {
   // make_unique calls unqualified operator new, so these exercise the
   // ThrowingValue overloads.
-  TestOp([]() { return absl::make_unique<ThrowingValue<>>(1); });
-  TestOp([]() { return absl::make_unique<ThrowingValue<>[]>(2); });
+  TestAllocatingOp([]() { return absl::make_unique<ThrowingValue<>>(1); });
+  TestAllocatingOp([]() { return absl::make_unique<ThrowingValue<>[]>(2); });
 }
 
 TEST_F(ThrowingValueTest, NonThrowingMoveCtor) {
@@ -399,7 +409,8 @@ struct CallOperator {
 };
 
 struct NonNegative {
-  friend testing::AssertionResult AbslCheckInvariants(NonNegative* g) {
+  friend testing::AssertionResult AbslCheckInvariants(
+      NonNegative* g, absl::InternalAbslNamespaceFinder) {
     if (g->i >= 0) return testing::AssertionSuccess();
     return testing::AssertionFailure()
            << "i should be non-negative but is " << g->i;
@@ -503,7 +514,8 @@ struct HasReset : public NonNegative {
 
   void reset() { i = 0; }
 
-  friend bool AbslCheckInvariants(HasReset* h) {
+  friend bool AbslCheckInvariants(HasReset* h,
+                                  absl::InternalAbslNamespaceFinder) {
     h->reset();
     return h->i == 0;
   }
@@ -591,7 +603,8 @@ struct ExhaustivenessTester {
     return true;
   }
 
-  friend testing::AssertionResult AbslCheckInvariants(ExhaustivenessTester*) {
+  friend testing::AssertionResult AbslCheckInvariants(
+      ExhaustivenessTester*, absl::InternalAbslNamespaceFinder) {
     return testing::AssertionSuccess();
   }