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 
16 
17 #include "gtest/gtest.h"
18 #include "absl/meta/type_traits.h"
19 
20 namespace testing {
21 
23 
25 
27  return {};
28 }
29 
30 namespace exceptions_internal {
31 
32 int countdown = -1;
33 
35 
36 void MaybeThrow(absl::string_view msg, bool throw_bad_alloc) {
37  if (countdown-- == 0) {
38  if (throw_bad_alloc) throw TestBadAllocException(msg);
39  throw TestException(msg);
40  }
41 }
42 
43 testing::AssertionResult FailureMessage(const TestException& e,
44  int countdown) noexcept {
45  return testing::AssertionFailure() << "Exception thrown from " << e.what();
46 }
47 
48 std::string GetSpecString(TypeSpec spec) {
49  std::string out;
51  const auto append = [&](absl::string_view s) {
52  absl::StrAppend(&out, sep, s);
53  sep = " | ";
54  };
55  if (static_cast<bool>(TypeSpec::kNoThrowCopy & spec)) {
56  append("kNoThrowCopy");
57  }
58  if (static_cast<bool>(TypeSpec::kNoThrowMove & spec)) {
59  append("kNoThrowMove");
60  }
61  if (static_cast<bool>(TypeSpec::kNoThrowNew & spec)) {
62  append("kNoThrowNew");
63  }
64  return out;
65 }
66 
67 std::string GetSpecString(AllocSpec spec) {
68  return static_cast<bool>(AllocSpec::kNoThrowAllocate & spec)
69  ? "kNoThrowAllocate"
70  : "";
71 }
72 
73 } // namespace exceptions_internal
74 
75 } // namespace testing
std::string * out
Definition: parser_test.cc:293
exceptions_internal::StrongGuaranteeTagType strong_guarantee
void StrAppend(std::string *dest, const AlphaNum &a)
Definition: str_cat.cc:193
testing::AssertionResult FailureMessage(const TestException &e, int countdown) noexcept
exceptions_internal::ExceptionSafetyTestBuilder MakeExceptionSafetyTester()
const char * msg
Definition: mutex.cc:254
exceptions_internal::NoThrowTag nothrow_ctor
std::string GetSpecString(TypeSpec spec)
void MaybeThrow(absl::string_view msg, bool throw_bad_alloc)


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:19:56