exception_safety_testing.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/base/internal/exception_safety_testing.h"
00016 
00017 #include "gtest/gtest.h"
00018 #include "absl/meta/type_traits.h"
00019 
00020 namespace testing {
00021 
00022 exceptions_internal::NoThrowTag nothrow_ctor;
00023 
00024 exceptions_internal::StrongGuaranteeTagType strong_guarantee;
00025 
00026 exceptions_internal::ExceptionSafetyTestBuilder<> MakeExceptionSafetyTester() {
00027   return {};
00028 }
00029 
00030 namespace exceptions_internal {
00031 
00032 int countdown = -1;
00033 
00034 ConstructorTracker* ConstructorTracker::current_tracker_instance_ = nullptr;
00035 
00036 void MaybeThrow(absl::string_view msg, bool throw_bad_alloc) {
00037   if (countdown-- == 0) {
00038     if (throw_bad_alloc) throw TestBadAllocException(msg);
00039     throw TestException(msg);
00040   }
00041 }
00042 
00043 testing::AssertionResult FailureMessage(const TestException& e,
00044                                         int countdown) noexcept {
00045   return testing::AssertionFailure() << "Exception thrown from " << e.what();
00046 }
00047 
00048 std::string GetSpecString(TypeSpec spec) {
00049   std::string out;
00050   absl::string_view sep;
00051   const auto append = [&](absl::string_view s) {
00052     absl::StrAppend(&out, sep, s);
00053     sep = " | ";
00054   };
00055   if (static_cast<bool>(TypeSpec::kNoThrowCopy & spec)) {
00056     append("kNoThrowCopy");
00057   }
00058   if (static_cast<bool>(TypeSpec::kNoThrowMove & spec)) {
00059     append("kNoThrowMove");
00060   }
00061   if (static_cast<bool>(TypeSpec::kNoThrowNew & spec)) {
00062     append("kNoThrowNew");
00063   }
00064   return out;
00065 }
00066 
00067 std::string GetSpecString(AllocSpec spec) {
00068   return static_cast<bool>(AllocSpec::kNoThrowAllocate & spec)
00069              ? "kNoThrowAllocate"
00070              : "";
00071 }
00072 
00073 }  // namespace exceptions_internal
00074 
00075 }  // namespace testing


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