abseil-cpp/absl/base/internal/exception_safety_testing.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/base/internal/exception_safety_testing.h"
16 
17 #ifdef ABSL_HAVE_EXCEPTIONS
18 
19 #include "gtest/gtest.h"
20 #include "absl/meta/type_traits.h"
21 
22 namespace testing {
23 
24 exceptions_internal::NoThrowTag nothrow_ctor;
25 
26 exceptions_internal::StrongGuaranteeTagType strong_guarantee;
27 
28 exceptions_internal::ExceptionSafetyTestBuilder<> MakeExceptionSafetyTester() {
29  return {};
30 }
31 
32 namespace exceptions_internal {
33 
34 int countdown = -1;
35 
36 ConstructorTracker* ConstructorTracker::current_tracker_instance_ = nullptr;
37 
38 void MaybeThrow(absl::string_view msg, bool throw_bad_alloc) {
39  if (countdown-- == 0) {
40  if (throw_bad_alloc) throw TestBadAllocException(msg);
41  throw TestException(msg);
42  }
43 }
44 
45 testing::AssertionResult FailureMessage(const TestException& e,
46  int countdown) noexcept {
47  return testing::AssertionFailure() << "Exception thrown from " << e.what();
48 }
49 
50 std::string GetSpecString(TypeSpec spec) {
53  const auto append = [&](absl::string_view s) {
54  absl::StrAppend(&out, sep, s);
55  sep = " | ";
56  };
57  if (static_cast<bool>(TypeSpec::kNoThrowCopy & spec)) {
58  append("kNoThrowCopy");
59  }
60  if (static_cast<bool>(TypeSpec::kNoThrowMove & spec)) {
61  append("kNoThrowMove");
62  }
63  if (static_cast<bool>(TypeSpec::kNoThrowNew & spec)) {
64  append("kNoThrowNew");
65  }
66  return out;
67 }
68 
69 std::string GetSpecString(AllocSpec spec) {
70  return static_cast<bool>(AllocSpec::kNoThrowAllocate & spec)
71  ? "kNoThrowAllocate"
72  : "";
73 }
74 
75 } // namespace exceptions_internal
76 
77 } // namespace testing
78 
79 #endif // ABSL_HAVE_EXCEPTIONS
testing
Definition: aws_request_signer_test.cc:25
testing::AssertionFailure
AssertionResult AssertionFailure()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1028
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
absl::StrAppend
void StrAppend(std::string *dest, const AlphaNum &a)
Definition: abseil-cpp/absl/strings/str_cat.cc:193
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
absl::FormatConversionChar::s
@ s
run_interop_tests.spec
def spec
Definition: run_interop_tests.py:1394
absl::FormatConversionChar::e
@ e
text_format_test_wrapper.sep
sep
Definition: text_format_test_wrapper.py:34
testing::AssertionResult
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:18855
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:20